From 8a686db6bd0004488028b81c42c09511b0388377 Mon Sep 17 00:00:00 2001 From: SG Date: Thu, 25 May 2023 16:18:30 +0300 Subject: [PATCH 1/2] Storage, common_rename: check that old path is exists --- .../services/storage/storage_external_api.c | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/applications/services/storage/storage_external_api.c b/applications/services/storage/storage_external_api.c index 549397c87de..e1b6587cac7 100644 --- a/applications/services/storage/storage_external_api.c +++ b/applications/services/storage/storage_external_api.c @@ -424,19 +424,25 @@ FS_Error storage_common_remove(Storage* storage, const char* path) { FS_Error storage_common_rename(Storage* storage, const char* old_path, const char* new_path) { FS_Error error; - if(storage_file_exists(storage, new_path)) { - error = storage_common_remove(storage, new_path); + do { + if(!storage_common_exists(storage, old_path)) { + error = FSE_NOT_EXIST; + break; + } + + if(storage_file_exists(storage, new_path)) { + storage_common_remove(storage, new_path); + } + + error = storage_common_copy(storage, old_path, new_path); if(error != FSE_OK) { - return error; + break; } - } - error = storage_common_copy(storage, old_path, new_path); - if(error == FSE_OK) { if(!storage_simply_remove_recursive(storage, old_path)) { error = FSE_INTERNAL; } - } + } while(false); return error; } From 5e42b20931b97abfc619cb02490e06258f79367c Mon Sep 17 00:00:00 2001 From: SG Date: Thu, 25 May 2023 16:38:02 +0300 Subject: [PATCH 2/2] Storage, common_rename: return correct status --- applications/services/storage/storage_external_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/services/storage/storage_external_api.c b/applications/services/storage/storage_external_api.c index e1b6587cac7..5fcaa59216b 100644 --- a/applications/services/storage/storage_external_api.c +++ b/applications/services/storage/storage_external_api.c @@ -426,7 +426,7 @@ FS_Error storage_common_rename(Storage* storage, const char* old_path, const cha do { if(!storage_common_exists(storage, old_path)) { - error = FSE_NOT_EXIST; + error = FSE_INVALID_NAME; break; }