mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-28 03:59:58 -07:00
Merge and improve new storage rename/move
This commit is contained in:
@@ -391,12 +391,27 @@ static FS_Error storage_process_common_remove(Storage* app, FuriString* path) {
|
||||
}
|
||||
|
||||
static FS_Error storage_process_common_rename(Storage* app, FuriString* old, FuriString* new) {
|
||||
StorageData* storage;
|
||||
FS_Error ret = storage_get_data(app, old, &storage);
|
||||
FS_Error ret = FSE_OK;
|
||||
|
||||
do {
|
||||
const StorageType storage_type_old = storage_get_type_by_path(old);
|
||||
const StorageType storage_type_new = storage_get_type_by_path(new);
|
||||
|
||||
// Different filesystems, return to caller to do copy + remove
|
||||
if(storage_type_old != storage_type_new) {
|
||||
ret = FSE_NOT_IMPLEMENTED;
|
||||
break;
|
||||
}
|
||||
|
||||
// Same filesystem, use fast rename
|
||||
StorageData* storage;
|
||||
ret = storage_get_data(app, old, &storage);
|
||||
|
||||
if(ret != FSE_OK) break;
|
||||
|
||||
if(ret == FSE_OK) {
|
||||
if(storage_path_already_open(old, storage)) {
|
||||
return FSE_ALREADY_OPEN;
|
||||
ret = FSE_ALREADY_OPEN;
|
||||
break;
|
||||
}
|
||||
|
||||
storage_data_timestamp(storage);
|
||||
@@ -404,7 +419,7 @@ static FS_Error storage_process_common_rename(Storage* app, FuriString* old, Fur
|
||||
storage,
|
||||
common.rename(
|
||||
storage, cstr_path_without_vfs_prefix(old), cstr_path_without_vfs_prefix(new)));
|
||||
}
|
||||
} while(false);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -605,7 +620,6 @@ void storage_process_alias(
|
||||
|
||||
void storage_process_message_internal(Storage* app, StorageMessage* message) {
|
||||
FuriString* path = NULL;
|
||||
FuriString* opath = NULL;
|
||||
|
||||
switch(message->command) {
|
||||
// File operations
|
||||
@@ -710,21 +724,16 @@ void storage_process_message_internal(Storage* app, StorageMessage* message) {
|
||||
storage_process_alias(app, path, message->data->path.thread_id, false);
|
||||
message->return_data->error_value = storage_process_common_remove(app, path);
|
||||
break;
|
||||
case StorageCommandCommonRename:
|
||||
opath = furi_string_alloc_set(message->data->rename.old);
|
||||
storage_process_alias(app, opath, message->data->rename.thread_id, false);
|
||||
path = furi_string_alloc_set(message->data->rename.new);
|
||||
storage_process_alias(app, path, message->data->rename.thread_id, false);
|
||||
// Paths are resolved, no aliases
|
||||
if(strncmp(
|
||||
furi_string_get_cstr(opath), furi_string_get_cstr(path), STORAGE_PATH_PREFIX_LEN)) {
|
||||
// Different filesystems, return to caller
|
||||
message->return_data->error_value = FSE_NOT_IMPLEMENTED;
|
||||
break;
|
||||
}
|
||||
// Same filesystem, use rename
|
||||
message->return_data->error_value = storage_process_common_rename(app, opath, path);
|
||||
case StorageCommandCommonRename: {
|
||||
FuriString* old_path = furi_string_alloc_set(message->data->rename.old);
|
||||
FuriString* new_path = furi_string_alloc_set(message->data->rename.new);
|
||||
storage_process_alias(app, old_path, message->data->cequivpath.thread_id, false);
|
||||
storage_process_alias(app, new_path, message->data->cequivpath.thread_id, false);
|
||||
message->return_data->error_value = storage_process_common_rename(app, old_path, new_path);
|
||||
furi_string_free(old_path);
|
||||
furi_string_free(new_path);
|
||||
break;
|
||||
}
|
||||
case StorageCommandCommonMkDir:
|
||||
path = furi_string_alloc_set(message->data->path.path);
|
||||
storage_process_alias(app, path, message->data->path.thread_id, true);
|
||||
@@ -780,9 +789,6 @@ void storage_process_message_internal(Storage* app, StorageMessage* message) {
|
||||
if(path != NULL) { //-V547
|
||||
furi_string_free(path);
|
||||
}
|
||||
if(opath != NULL) { //-V547
|
||||
furi_string_free(opath);
|
||||
}
|
||||
|
||||
api_lock_unlock(message->lock);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user