@@ -225,22 +225,7 @@ STATIC mp_obj_t fat_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t path_
225
225
const char * old_path = mp_obj_str_get_str (path_in );
226
226
const char * new_path = mp_obj_str_get_str (path_out );
227
227
228
- // Check to see if we're moving a directory into itself. This occurs when we're moving a
229
- // directory where the old path is a prefix of the new and the next character is a "/" and thus
230
- // preserves the original directory name.
231
- FILINFO fno ;
232
- FRESULT res = f_stat (& self -> fatfs , old_path , & fno );
233
- if (res != FR_OK ) {
234
- mp_raise_OSError_fresult (res );
235
- }
236
- if ((fno .fattrib & AM_DIR ) != 0 &&
237
- strlen (new_path ) > strlen (old_path ) &&
238
- new_path [strlen (old_path )] == '/' &&
239
- strncmp (old_path , new_path , strlen (old_path )) == 0 ) {
240
- mp_raise_OSError (MP_EINVAL );
241
- }
242
-
243
- res = f_rename (& self -> fatfs , old_path , new_path );
228
+ FRESULT res = f_rename (& self -> fatfs , old_path , new_path );
244
229
if (res == FR_EXIST ) {
245
230
// if new_path exists then try removing it (but only if it's a file)
246
231
fat_vfs_remove_internal (vfs_in , path_out , 0 ); // 0 == file attribute
@@ -249,6 +234,8 @@ STATIC mp_obj_t fat_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t path_
249
234
}
250
235
if (res == FR_OK ) {
251
236
return mp_const_none ;
237
+ } else if (res == FR_NO_PATH ) {
238
+ mp_raise_OSError (MP_EINVAL );
252
239
} else {
253
240
mp_raise_OSError_fresult (res );
254
241
}
0 commit comments