Add an actual move function (OFW, rename != move)

This commit is contained in:
Willy-JL
2023-05-26 22:06:14 +01:00
parent 20dd1ba9da
commit fa89ef848c
2 changed files with 37 additions and 0 deletions

View File

@@ -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

View File

@@ -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)) {