OFW be like rEnAmE = cOpY + dElEtE, bro stfu :/

This commit is contained in:
Willy-JL
2023-05-15 01:31:02 +01:00
parent c5bf0763a5
commit c6eff58890
6 changed files with 84 additions and 7 deletions
@@ -369,6 +369,39 @@ static FS_Error storage_process_common_remove(Storage* app, FuriString* path) {
return ret;
}
static FS_Error storage_process_common_rename(Storage* app, FuriString* old, FuriString* new) {
FS_Error ret;
// Paths are already resolved, no aliases
if(strncmp(furi_string_get_cstr(old), furi_string_get_cstr(new), STORAGE_PATH_PREFIX_LEN)) {
// Different filesystems, use copy + remove
ret = storage_common_copy(app, furi_string_get_cstr(old), furi_string_get_cstr(new));
if(ret == FSE_OK) {
if(!storage_simply_remove_recursive(app, furi_string_get_cstr(old))) {
ret = FSE_INTERNAL;
}
}
} else {
// Same filesystem, use rename
StorageData* storage;
ret = storage_get_data(app, old, &storage);
do {
if(storage_path_already_open(old, storage)) {
ret = FSE_ALREADY_OPEN;
break;
}
storage_data_timestamp(storage);
FS_CALL(
storage,
common.rename(
storage, cstr_path_without_vfs_prefix(old), cstr_path_without_vfs_prefix(new)));
} while(false);
}
return ret;
}
static FS_Error storage_process_common_mkdir(Storage* app, FuriString* path) {
StorageData* storage;
FS_Error ret = storage_get_data(app, path, &storage);
@@ -514,6 +547,7 @@ void storage_process_alias(
void storage_process_message_internal(Storage* app, StorageMessage* message) {
FuriString* path = NULL;
FuriString* opath = NULL;
switch(message->command) {
// File operations
@@ -614,6 +648,13 @@ 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);
message->return_data->error_value = storage_process_common_rename(app, opath, path);
break;
case StorageCommandCommonMkDir:
path = furi_string_alloc_set(message->data->path.path);
storage_process_alias(app, path, message->data->path.thread_id, true);
@@ -649,6 +690,9 @@ 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);
}