Skip to content

Commit 88f0b63

Browse files
authored
Storage, common_rename: check that old path is exists (#2698)
* Storage, common_rename: check that old path is exists * Storage, common_rename: return correct status
1 parent 3217f28 commit 88f0b63

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

applications/services/storage/storage_external_api.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -424,19 +424,25 @@ FS_Error storage_common_remove(Storage* storage, const char* path) {
424424
FS_Error storage_common_rename(Storage* storage, const char* old_path, const char* new_path) {
425425
FS_Error error;
426426

427-
if(storage_file_exists(storage, new_path)) {
428-
error = storage_common_remove(storage, new_path);
427+
do {
428+
if(!storage_common_exists(storage, old_path)) {
429+
error = FSE_INVALID_NAME;
430+
break;
431+
}
432+
433+
if(storage_file_exists(storage, new_path)) {
434+
storage_common_remove(storage, new_path);
435+
}
436+
437+
error = storage_common_copy(storage, old_path, new_path);
429438
if(error != FSE_OK) {
430-
return error;
439+
break;
431440
}
432-
}
433441

434-
error = storage_common_copy(storage, old_path, new_path);
435-
if(error == FSE_OK) {
436442
if(!storage_simply_remove_recursive(storage, old_path)) {
437443
error = FSE_INTERNAL;
438444
}
439-
}
445+
} while(false);
440446

441447
return error;
442448
}

0 commit comments

Comments
 (0)