mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 23:08:36 -07:00
Storage fast migrate (use rename recursively)
This commit is contained in:
@@ -593,8 +593,10 @@ FS_Error storage_common_copy(Storage* storage, const char* old_path, const char*
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static FS_Error _storage_common_merge(Storage*, const char*, const char*, bool);
|
||||||
|
|
||||||
static FS_Error
|
static FS_Error
|
||||||
storage_merge_recursive(Storage* storage, const char* old_path, const char* new_path) {
|
storage_merge_recursive(Storage* storage, const char* old_path, const char* new_path, bool copy) {
|
||||||
FS_Error error = FSE_OK;
|
FS_Error error = FSE_OK;
|
||||||
DirWalk* dir_walk = dir_walk_alloc(storage);
|
DirWalk* dir_walk = dir_walk_alloc(storage);
|
||||||
FuriString *path, *file_basename, *tmp_new_path;
|
FuriString *path, *file_basename, *tmp_new_path;
|
||||||
@@ -636,8 +638,8 @@ static FS_Error
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
error = storage_common_merge(
|
error = _storage_common_merge(
|
||||||
storage, furi_string_get_cstr(path), furi_string_get_cstr(tmp_new_path));
|
storage, furi_string_get_cstr(path), furi_string_get_cstr(tmp_new_path), copy);
|
||||||
|
|
||||||
if(error != FSE_OK) {
|
if(error != FSE_OK) {
|
||||||
break;
|
break;
|
||||||
@@ -654,7 +656,7 @@ static FS_Error
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
FS_Error storage_common_merge(Storage* storage, const char* old_path, const char* new_path) {
|
static FS_Error _storage_common_merge(Storage* storage, const char* old_path, const char* new_path, bool copy) {
|
||||||
FS_Error error;
|
FS_Error error;
|
||||||
const char* new_path_tmp = NULL;
|
const char* new_path_tmp = NULL;
|
||||||
FuriString* new_path_next = NULL;
|
FuriString* new_path_next = NULL;
|
||||||
@@ -665,7 +667,12 @@ FS_Error storage_common_merge(Storage* storage, const char* old_path, const char
|
|||||||
|
|
||||||
if(error == FSE_OK) {
|
if(error == FSE_OK) {
|
||||||
if(file_info_is_dir(&fileinfo)) {
|
if(file_info_is_dir(&fileinfo)) {
|
||||||
error = storage_merge_recursive(storage, old_path, new_path);
|
if(!copy) {
|
||||||
|
error = storage_common_rename(storage, old_path, new_path);
|
||||||
|
}
|
||||||
|
if(copy || error != FSE_OK) {
|
||||||
|
error = storage_merge_recursive(storage, old_path, new_path, copy);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
error = storage_common_stat(storage, new_path, &fileinfo);
|
error = storage_common_stat(storage, new_path, &fileinfo);
|
||||||
if(error == FSE_OK) {
|
if(error == FSE_OK) {
|
||||||
@@ -699,22 +706,26 @@ FS_Error storage_common_merge(Storage* storage, const char* old_path, const char
|
|||||||
} else {
|
} else {
|
||||||
new_path_tmp = new_path;
|
new_path_tmp = new_path;
|
||||||
}
|
}
|
||||||
Stream* stream_from = file_stream_alloc(storage);
|
if(copy) {
|
||||||
Stream* stream_to = file_stream_alloc(storage);
|
Stream* stream_from = file_stream_alloc(storage);
|
||||||
|
Stream* stream_to = file_stream_alloc(storage);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if(!file_stream_open(stream_from, old_path, FSAM_READ, FSOM_OPEN_EXISTING)) break;
|
if(!file_stream_open(stream_from, old_path, FSAM_READ, FSOM_OPEN_EXISTING)) break;
|
||||||
if(!file_stream_open(stream_to, new_path_tmp, FSAM_WRITE, FSOM_CREATE_NEW)) break;
|
if(!file_stream_open(stream_to, new_path_tmp, FSAM_WRITE, FSOM_CREATE_NEW)) break;
|
||||||
stream_copy_full(stream_from, stream_to);
|
stream_copy_full(stream_from, stream_to);
|
||||||
} while(false);
|
} while(false);
|
||||||
|
|
||||||
error = file_stream_get_error(stream_from);
|
error = file_stream_get_error(stream_from);
|
||||||
if(error == FSE_OK) {
|
if(error == FSE_OK) {
|
||||||
error = file_stream_get_error(stream_to);
|
error = file_stream_get_error(stream_to);
|
||||||
|
}
|
||||||
|
|
||||||
|
stream_free(stream_from);
|
||||||
|
stream_free(stream_to);
|
||||||
|
} else {
|
||||||
|
error = storage_common_rename(storage, old_path, new_path_tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
stream_free(stream_from);
|
|
||||||
stream_free(stream_to);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -723,6 +734,10 @@ FS_Error storage_common_merge(Storage* storage, const char* old_path, const char
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FS_Error storage_common_merge(Storage* storage, const char* old_path, const char* new_path) {
|
||||||
|
return _storage_common_merge(storage, old_path, new_path, true);
|
||||||
|
}
|
||||||
|
|
||||||
FS_Error storage_common_mkdir(Storage* storage, const char* path) {
|
FS_Error storage_common_mkdir(Storage* storage, const char* path) {
|
||||||
S_API_PROLOGUE;
|
S_API_PROLOGUE;
|
||||||
SAData data = {
|
SAData data = {
|
||||||
@@ -774,14 +789,10 @@ FS_Error storage_common_migrate(Storage* storage, const char* source, const char
|
|||||||
return FSE_OK;
|
return FSE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
FS_Error error = storage_common_rename(storage, source, dest);
|
FS_Error error = _storage_common_merge(storage, source, dest, false);
|
||||||
|
|
||||||
if(error != FSE_OK) {
|
if(error == FSE_OK) {
|
||||||
error = storage_common_merge(storage, source, dest);
|
storage_simply_remove_recursive(storage, source);
|
||||||
|
|
||||||
if(error == FSE_OK) {
|
|
||||||
storage_simply_remove_recursive(storage, source);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
|
|||||||
Reference in New Issue
Block a user