diff --git a/applications/services/storage/storage.h b/applications/services/storage/storage.h index 78dae7a2c..1ee4ab820 100644 --- a/applications/services/storage/storage.h +++ b/applications/services/storage/storage.h @@ -236,6 +236,14 @@ 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); +/** Moves file/directory, file/directory must not be open, will overwrite existing destination + * @param app pointer to the api + * @param old_path old path + * @param new_path new path + * @return FS_Error operation result + */ +FS_Error storage_common_move(Storage* storage, const char* old_path, const char* new_path); + /** Copy file, file must not be open * @param app pointer to the api * @param old_path old path diff --git a/applications/services/storage/storage_external_api.c b/applications/services/storage/storage_external_api.c index 49432c547..0b4587926 100644 --- a/applications/services/storage/storage_external_api.c +++ b/applications/services/storage/storage_external_api.c @@ -449,6 +449,35 @@ FS_Error storage_common_rename(Storage* storage, const char* old_path, const cha return S_RETURN_ERROR; } +FS_Error storage_common_move(Storage* storage, const char* old_path, const char* new_path) { + if(!storage_common_exists(storage, old_path)) { + return FSE_NOT_EXIST; + } + + if(storage_is_subdir(new_path, old_path)) { + return FSE_INVALID_NAME; + } + + if(storage_common_exists(storage, new_path)) { + FS_Error error = storage_common_remove(storage, new_path); + if(error != FSE_OK) { + return error; + } + } + + S_API_PROLOGUE; + SAData data = { + .rename = { + .old = old_path, + .new = new_path, + .thread_id = furi_thread_get_current_id(), + }}; + + S_API_MESSAGE(StorageCommandCommonRename); + S_API_EPILOGUE; + return S_RETURN_ERROR; +} + static FS_Error storage_copy_recursive(Storage* storage, const char* old_path, const char* new_path) { if(storage_is_subdir(new_path, old_path)) {