mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 18:08:35 -07:00
Fix brick on rename across filesystems
This commit is contained in:
@@ -446,7 +446,18 @@ FS_Error storage_common_rename(Storage* storage, const char* old_path, const cha
|
|||||||
|
|
||||||
S_API_MESSAGE(StorageCommandCommonRename);
|
S_API_MESSAGE(StorageCommandCommonRename);
|
||||||
S_API_EPILOGUE;
|
S_API_EPILOGUE;
|
||||||
return S_RETURN_ERROR;
|
FS_Error ret = S_RETURN_ERROR;
|
||||||
|
|
||||||
|
if(ret == FSE_NOT_IMPLEMENTED) {
|
||||||
|
// Different filesystems, use copy + remove
|
||||||
|
ret = storage_common_copy(storage, old_path, new_path);
|
||||||
|
if(ret == FSE_OK) {
|
||||||
|
if(!storage_simply_remove_recursive(storage, old_path)) {
|
||||||
|
ret = FSE_INTERNAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
FS_Error storage_common_move(Storage* storage, const char* old_path, const char* new_path) {
|
FS_Error storage_common_move(Storage* storage, const char* old_path, const char* new_path) {
|
||||||
@@ -458,7 +469,7 @@ FS_Error storage_common_move(Storage* storage, const char* old_path, const char*
|
|||||||
return FSE_INVALID_NAME;
|
return FSE_INVALID_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(storage_common_exists(storage, new_path)) {
|
if(storage_file_exists(storage, new_path)) {
|
||||||
FS_Error error = storage_common_remove(storage, new_path);
|
FS_Error error = storage_common_remove(storage, new_path);
|
||||||
if(error != FSE_OK) {
|
if(error != FSE_OK) {
|
||||||
return error;
|
return error;
|
||||||
@@ -475,7 +486,16 @@ FS_Error storage_common_move(Storage* storage, const char* old_path, const char*
|
|||||||
|
|
||||||
S_API_MESSAGE(StorageCommandCommonRename);
|
S_API_MESSAGE(StorageCommandCommonRename);
|
||||||
S_API_EPILOGUE;
|
S_API_EPILOGUE;
|
||||||
return S_RETURN_ERROR;
|
FS_Error ret = S_RETURN_ERROR;
|
||||||
|
|
||||||
|
if(ret == FSE_NOT_IMPLEMENTED) {
|
||||||
|
// Different filesystems, use copy + remove
|
||||||
|
ret = storage_common_copy(storage, old_path, new_path);
|
||||||
|
if(ret == FSE_OK) {
|
||||||
|
ret = storage_simply_remove_recursive(storage, old_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FS_Error
|
static FS_Error
|
||||||
|
|||||||
@@ -356,47 +356,32 @@ static FS_Error storage_process_common_remove(Storage* app, FuriString* path) {
|
|||||||
StorageData* storage;
|
StorageData* storage;
|
||||||
FS_Error ret = storage_get_data(app, path, &storage);
|
FS_Error ret = storage_get_data(app, path, &storage);
|
||||||
|
|
||||||
do {
|
if(ret == FSE_OK) {
|
||||||
if(storage_path_already_open(path, storage)) {
|
if(storage_path_already_open(path, storage)) {
|
||||||
ret = FSE_ALREADY_OPEN;
|
return FSE_ALREADY_OPEN;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
storage_data_timestamp(storage);
|
storage_data_timestamp(storage);
|
||||||
FS_CALL(storage, common.remove(storage, cstr_path_without_vfs_prefix(path)));
|
FS_CALL(storage, common.remove(storage, cstr_path_without_vfs_prefix(path)));
|
||||||
} while(false);
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FS_Error storage_process_common_rename(Storage* app, FuriString* old, FuriString* new) {
|
static FS_Error storage_process_common_rename(Storage* app, FuriString* old, FuriString* new) {
|
||||||
FS_Error ret;
|
StorageData* storage;
|
||||||
// Paths are already resolved, no aliases
|
FS_Error ret = storage_get_data(app, old, &storage);
|
||||||
if(strncmp(furi_string_get_cstr(old), furi_string_get_cstr(new), STORAGE_PATH_PREFIX_LEN)) {
|
|
||||||
// Different filesystems, use copy + remove
|
if(ret == FSE_OK) {
|
||||||
ret = storage_common_copy(app, furi_string_get_cstr(old), furi_string_get_cstr(new));
|
if(storage_path_already_open(old, storage)) {
|
||||||
if(ret == FSE_OK) {
|
return FSE_ALREADY_OPEN;
|
||||||
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 {
|
storage_data_timestamp(storage);
|
||||||
if(storage_path_already_open(old, storage)) {
|
FS_CALL(
|
||||||
ret = FSE_ALREADY_OPEN;
|
storage,
|
||||||
break;
|
common.rename(
|
||||||
}
|
storage, cstr_path_without_vfs_prefix(old), cstr_path_without_vfs_prefix(new)));
|
||||||
|
|
||||||
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;
|
return ret;
|
||||||
@@ -653,6 +638,14 @@ void storage_process_message_internal(Storage* app, StorageMessage* message) {
|
|||||||
storage_process_alias(app, opath, message->data->rename.thread_id, false);
|
storage_process_alias(app, opath, message->data->rename.thread_id, false);
|
||||||
path = furi_string_alloc_set(message->data->rename.new);
|
path = furi_string_alloc_set(message->data->rename.new);
|
||||||
storage_process_alias(app, path, message->data->rename.thread_id, false);
|
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);
|
message->return_data->error_value = storage_process_common_rename(app, opath, path);
|
||||||
break;
|
break;
|
||||||
case StorageCommandCommonMkDir:
|
case StorageCommandCommonMkDir:
|
||||||
|
|||||||
Reference in New Issue
Block a user