@@ -457,14 +457,19 @@ static bool __attribute__((noinline)) run_code_py(safe_mode_t safe_mode, bool *s
457457 usb_setup_with_vm ();
458458 #endif
459459
460+ // Always return to root before trying to run files.
461+ common_hal_os_chdir ("/" );
460462 // Check if a different run file has been allocated
461463 if (next_code_configuration != NULL ) {
462464 next_code_configuration -> options &= ~SUPERVISOR_NEXT_CODE_OPT_NEWLY_SET ;
463465 next_code_options = next_code_configuration -> options ;
464466 if (next_code_configuration -> filename [0 ] != '\0' ) {
467+ if (next_code_configuration -> working_directory != NULL ) {
468+ common_hal_os_chdir (next_code_configuration -> working_directory );
469+ }
465470 // This is where the user's python code is actually executed:
466471 const char * const filenames [] = { next_code_configuration -> filename };
467- found_main = maybe_run_list (filenames , MP_ARRAY_SIZE ( filenames ) );
472+ found_main = maybe_run_list (filenames , 1 );
468473 if (!found_main ) {
469474 serial_write (next_code_configuration -> filename );
470475 serial_write_compressed (MP_ERROR_TEXT (" not found.\n" ));
@@ -1105,9 +1110,6 @@ int __attribute__((used)) main(void) {
11051110 }
11061111 simulate_reset = false;
11071112
1108- // Always return to root before trying to run files.
1109- common_hal_os_chdir ("/" );
1110-
11111113 if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL ) {
11121114 // If code.py did a fake deep sleep, pretend that we
11131115 // are running code.py for the first time after a hard
0 commit comments