Skip to content

Reset cwd before looking for files to run#8296

Merged
dhalbert merged 1 commit into
adafruit:mainfrom
pypewpew:reset-cwd
Aug 18, 2023
Merged

Reset cwd before looking for files to run#8296
dhalbert merged 1 commit into
adafruit:mainfrom
pypewpew:reset-cwd

Conversation

@deshipu
Copy link
Copy Markdown

@deshipu deshipu commented Aug 18, 2023

Make sure we only look for the files in the root directory.

Fixes #8295

Make sure we only look for the files in the root directory.
Copy link
Copy Markdown
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't reset the current directory until code.py is run, after. The current directory should probably be reset for boot.py, safemode.py, and code.py. So I think it should be reset in start_mp(). Or should it not be reset between boot.py and code.py? That's something to ponder, about whether to make boot.py be able to change the current directory in a sticky way.

Also, if the filesystem is not working, I think chdir() may throw an error. Maybe better to check with filesystem_present() before claling it.

@deshipu
Copy link
Copy Markdown
Author

deshipu commented Aug 18, 2023

There is no way to change the directory before boot.py runs, so I don't think there is a need to reset it there. Also, start_mp only runs once at the beginning, but the nature of the problem comes from cwd persisting across reloads, not from the initial conditions.

I don't see the maybe_run_list function checking for the filesystem, so I assumed that by this point it has already been checked? I don't really have a way of testing this without a filesystem.

@dhalbert
Copy link
Copy Markdown
Collaborator

Good point about boot.py, I wasn't thinking too clearly.

To fake not having a filesystem, temporarily add a return false; just before // try to mount the flash in filesystem_init() in supervisor/shared/filesystem.c.

@deshipu
Copy link
Copy Markdown
Author

deshipu commented Aug 18, 2023

When I do that, I get:

Auto-reload is off.
Running in safe mode! Not running saved code.

You are in safe mode because:
CIRCUITPY drive could not be found or created.

Press any key to enter the REPL. Use CTRL-D to reload.

No crash.

@dhalbert
Copy link
Copy Markdown
Collaborator

So it never gets to running the code.py that's good.

Copy link
Copy Markdown
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concerns (some incorrect) all accounted for. Thanks!

@deshipu
Copy link
Copy Markdown
Author

deshipu commented Aug 18, 2023

There is still the case when someone uses chdir in boot.py and the board goes into safe mode and runs the wrong safemode.py, but I think that's a self-inflicted wound?

@dhalbert
Copy link
Copy Markdown
Collaborator

ja pygamer is overflowing, but we don't need to fix that here.

@dhalbert dhalbert merged commit babd2de into adafruit:main Aug 18, 2023
@dhalbert
Copy link
Copy Markdown
Collaborator

There is still the case when someone uses chdir in boot.py and the board goes into safe mode and runs the wrong safemode.py, but I think that's a self-inflicted wound?

safemode.py is run after a hard reset, so I think that cannot happen?

@deshipu
Copy link
Copy Markdown
Author

deshipu commented Aug 18, 2023

Excellent.

@deshipu deshipu deleted the reset-cwd branch August 18, 2023 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Current working directory survives reload

2 participants