mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 20:18:35 -07:00
Fix copy/paste and rename behaviors
Same beginning of name != same file/folder Must check with a / suffixed And never hold a pointer to furi string cstr
This commit is contained in:
@@ -135,11 +135,9 @@ FS_Error archive_copy_rename_file_or_dir(
|
|||||||
bool copy,
|
bool copy,
|
||||||
bool find_name) {
|
bool find_name) {
|
||||||
furi_assert(context);
|
furi_assert(context);
|
||||||
const char* dst_cstr = furi_string_get_cstr(dst_path);
|
FURI_LOG_I(
|
||||||
|
TAG, "%s from %s to %s", copy ? "Copy" : "Move", src_path, furi_string_get_cstr(dst_path));
|
||||||
|
|
||||||
FURI_LOG_I(TAG, "%s from %s to %s", copy ? "Copy" : "Move", src_path, dst_cstr);
|
|
||||||
|
|
||||||
UNUSED(context);
|
|
||||||
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
Storage* fs_api = furi_record_open(RECORD_STORAGE);
|
||||||
|
|
||||||
FileInfo fileinfo;
|
FileInfo fileinfo;
|
||||||
@@ -147,17 +145,17 @@ FS_Error archive_copy_rename_file_or_dir(
|
|||||||
|
|
||||||
FS_Error error = FSE_OK;
|
FS_Error error = FSE_OK;
|
||||||
|
|
||||||
if(!path_contains_only_ascii(dst_cstr)) {
|
if(!path_contains_only_ascii(furi_string_get_cstr(dst_path))) {
|
||||||
error = FSE_INVALID_NAME;
|
error = FSE_INVALID_NAME;
|
||||||
} else if(!copy && !strcmp(src_path, dst_cstr)) {
|
} else if(!copy && !strcmp(src_path, furi_string_get_cstr(dst_path))) {
|
||||||
error = FSE_EXIST;
|
error = FSE_EXIST;
|
||||||
} else {
|
} else {
|
||||||
if(find_name && storage_common_exists(fs_api, dst_cstr)) {
|
if(find_name && storage_common_exists(fs_api, furi_string_get_cstr(dst_path))) {
|
||||||
FuriString* dir_path = furi_string_alloc();
|
FuriString* dir_path = furi_string_alloc();
|
||||||
FuriString* filename = furi_string_alloc();
|
FuriString* filename = furi_string_alloc();
|
||||||
FuriString* file_ext = furi_string_alloc();
|
FuriString* file_ext = furi_string_alloc();
|
||||||
|
|
||||||
path_extract_dirname(dst_cstr, dir_path);
|
path_extract_dirname(furi_string_get_cstr(dst_path), dir_path);
|
||||||
path_extract_filename(dst_path, filename, true);
|
path_extract_filename(dst_path, filename, true);
|
||||||
path_extract_ext_str(dst_path, file_ext);
|
path_extract_ext_str(dst_path, file_ext);
|
||||||
|
|
||||||
@@ -168,7 +166,8 @@ FS_Error archive_copy_rename_file_or_dir(
|
|||||||
furi_string_get_cstr(file_ext),
|
furi_string_get_cstr(file_ext),
|
||||||
dst_path,
|
dst_path,
|
||||||
255);
|
255);
|
||||||
furi_string_cat_printf(dir_path, "/%s%s", dst_cstr, furi_string_get_cstr(file_ext));
|
furi_string_cat_printf(
|
||||||
|
dir_path, "/%s%s", furi_string_get_cstr(dst_path), furi_string_get_cstr(file_ext));
|
||||||
furi_string_set(dst_path, dir_path);
|
furi_string_set(dst_path, dir_path);
|
||||||
|
|
||||||
furi_string_free(dir_path);
|
furi_string_free(dir_path);
|
||||||
@@ -177,24 +176,31 @@ FS_Error archive_copy_rename_file_or_dir(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(copy) {
|
if(copy) {
|
||||||
error = storage_common_copy(fs_api, src_path, dst_cstr);
|
error = storage_common_copy(fs_api, src_path, furi_string_get_cstr(dst_path));
|
||||||
} else {
|
} else {
|
||||||
error = storage_common_rename(fs_api, src_path, dst_cstr);
|
error = storage_common_rename(fs_api, src_path, furi_string_get_cstr(dst_path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
furi_record_close(RECORD_STORAGE);
|
furi_record_close(RECORD_STORAGE);
|
||||||
|
|
||||||
if(!copy && archive_is_favorite("%s", src_path)) {
|
if(!copy && archive_is_favorite("%s", src_path)) {
|
||||||
archive_favorites_rename(src_path, dst_cstr);
|
archive_favorites_rename(src_path, furi_string_get_cstr(dst_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(error == FSE_OK) {
|
if(error == FSE_OK) {
|
||||||
FURI_LOG_I(TAG, "%s from %s to %s is DONE", copy ? "Copy" : "Move", src_path, dst_cstr);
|
FURI_LOG_I(
|
||||||
|
TAG,
|
||||||
|
"%s from %s to %s is DONE",
|
||||||
|
copy ? "Copy" : "Move",
|
||||||
|
src_path,
|
||||||
|
furi_string_get_cstr(dst_path));
|
||||||
} else {
|
} else {
|
||||||
FURI_LOG_E(
|
FURI_LOG_E(
|
||||||
TAG,
|
TAG,
|
||||||
"%s failed: %s, Code: %d",
|
"%s from %s to %s failed: %s, Code: %d",
|
||||||
copy ? "Copy" : "Move",
|
copy ? "Copy" : "Move",
|
||||||
|
src_path,
|
||||||
|
furi_string_get_cstr(dst_path),
|
||||||
filesystem_api_error_get_desc(error),
|
filesystem_api_error_get_desc(error),
|
||||||
error);
|
error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -757,6 +757,10 @@ void storage_process_message_internal(Storage* app, StorageMessage* message) {
|
|||||||
storage_path_trim_trailing_slashes(path2);
|
storage_path_trim_trailing_slashes(path2);
|
||||||
storage_process_alias(app, path1, message->data->cequivpath.thread_id, false);
|
storage_process_alias(app, path1, message->data->cequivpath.thread_id, false);
|
||||||
storage_process_alias(app, path2, message->data->cequivpath.thread_id, false);
|
storage_process_alias(app, path2, message->data->cequivpath.thread_id, false);
|
||||||
|
// Comparison is done on path name, same beginning of name != same file/folder
|
||||||
|
// Check with a / suffixed to ensure same file/folder name
|
||||||
|
furi_string_cat(path1, "/");
|
||||||
|
furi_string_cat(path2, "/");
|
||||||
if(message->data->cequivpath.truncate) {
|
if(message->data->cequivpath.truncate) {
|
||||||
furi_string_left(path2, furi_string_size(path1));
|
furi_string_left(path2, furi_string_size(path1));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user