-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compile-time APP_DATA_PATH() and APP_ASSETS_PATH() #3435
base: dev
Are you sure you want to change the base?
Changes from 14 commits
3ba778f
890dab3
b7ad7e0
fa3f0b8
05cd847
6f2649a
6a41af6
70e0ee0
6690f80
0162b3b
a717691
16e800c
70a10d5
b2ce587
e7164e2
3fb5f9e
887cd4b
df9a4f8
9ab373d
9388cd7
9d9b029
c4bacfd
0157f36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -520,45 +520,26 @@ static FS_Error storage_process_sd_status(Storage* app) { | |
|
||
/******************** Aliases processing *******************/ | ||
|
||
void storage_process_alias( | ||
Storage* app, | ||
FuriString* path, | ||
FuriThreadId thread_id, | ||
bool create_folders) { | ||
if(furi_string_start_with(path, STORAGE_APP_DATA_PATH_PREFIX)) { | ||
FuriString* apps_data_path_with_appsid = furi_string_alloc_set(APPS_DATA_PATH "/"); | ||
furi_string_cat(apps_data_path_with_appsid, furi_thread_get_appid(thread_id)); | ||
|
||
// "/data" -> "/ext/apps_data/appsid" | ||
furi_string_replace_at( | ||
path, | ||
0, | ||
strlen(STORAGE_APP_DATA_PATH_PREFIX), | ||
furi_string_get_cstr(apps_data_path_with_appsid)); | ||
void storage_process_alias(Storage* app, FuriString* path, bool create_folders) { | ||
if(furi_string_start_with(path, STORAGE_APPS_DATA_STEM "/")) { | ||
FuriString* apps_data_appid = furi_string_alloc_set(path); | ||
// Only create "/ext/apps_data/appid", not any subdir | ||
// "/ext/apps_data/appid/whatever" -> "/ext/apps_data/appid" | ||
size_t slash = | ||
furi_string_search_char(apps_data_appid, '/', strlen(STORAGE_APPS_DATA_STEM "/")); | ||
if(slash != FURI_STRING_FAILURE) { | ||
furi_string_left(apps_data_appid, slash); | ||
} | ||
|
||
// Create app data folder if not exists | ||
if(create_folders && | ||
storage_process_common_stat(app, apps_data_path_with_appsid, NULL) != FSE_OK) { | ||
furi_string_set(apps_data_path_with_appsid, APPS_DATA_PATH); | ||
storage_process_common_mkdir(app, apps_data_path_with_appsid); | ||
furi_string_cat(apps_data_path_with_appsid, "/"); | ||
furi_string_cat(apps_data_path_with_appsid, furi_thread_get_appid(thread_id)); | ||
storage_process_common_mkdir(app, apps_data_path_with_appsid); | ||
if(create_folders && storage_process_common_stat(app, apps_data_appid, NULL) != FSE_OK) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code incorrectly handles paths like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems like its still the error i mentioned above, setting up the CI unit tests, not running them. code that causes the issue is not in flipper code, but python helper is failing when creating a folder that already exists. i had tried in 887cd4b to make it ignore an "already exists" error but seems like this fix had some syntax issue. i will fix this, but maybe could consider making it so checking for dir exist in "/ext/apps_data/*" will say that dir already exists? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think maintaining compatibility and existing behaviour from API is quite important - looking forward to hearing @DrZlo13's opinion on these changes. |
||
FuriString* apps_data = furi_string_alloc_set(STORAGE_APPS_DATA_STEM); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we're checking existence of one path, but creating a different one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it first makes /ext/apps_data here, then 2 lines below it makes /ext/apps_data/appid. it is just ensuring that apps_data exists, previous implementation did this too |
||
storage_process_common_mkdir(app, apps_data); | ||
furi_string_free(apps_data); | ||
storage_process_common_mkdir(app, apps_data_appid); | ||
} | ||
|
||
furi_string_free(apps_data_path_with_appsid); | ||
} else if(furi_string_start_with(path, STORAGE_APP_ASSETS_PATH_PREFIX)) { | ||
FuriString* apps_assets_path_with_appsid = furi_string_alloc_set(APPS_ASSETS_PATH "/"); | ||
furi_string_cat(apps_assets_path_with_appsid, furi_thread_get_appid(thread_id)); | ||
|
||
// "/assets" -> "/ext/apps_assets/appsid" | ||
furi_string_replace_at( | ||
path, | ||
0, | ||
strlen(STORAGE_APP_ASSETS_PATH_PREFIX), | ||
furi_string_get_cstr(apps_assets_path_with_appsid)); | ||
|
||
furi_string_free(apps_assets_path_with_appsid); | ||
furi_string_free(apps_data_appid); | ||
} | ||
} | ||
|
||
|
@@ -571,7 +552,7 @@ void storage_process_message_internal(Storage* app, StorageMessage* message) { | |
// File operations | ||
case StorageCommandFileOpen: | ||
path = furi_string_alloc_set(message->data->fopen.path); | ||
storage_process_alias(app, path, message->data->fopen.thread_id, true); | ||
storage_process_alias(app, path, true); | ||
message->return_data->bool_value = storage_process_file_open( | ||
app, | ||
message->data->fopen.file, | ||
|
@@ -627,7 +608,7 @@ void storage_process_message_internal(Storage* app, StorageMessage* message) { | |
// Dir operations | ||
case StorageCommandDirOpen: | ||
path = furi_string_alloc_set(message->data->dopen.path); | ||
storage_process_alias(app, path, message->data->dopen.thread_id, true); | ||
storage_process_alias(app, path, true); | ||
message->return_data->bool_value = | ||
storage_process_dir_open(app, message->data->dopen.file, path); | ||
break; | ||
|
@@ -651,44 +632,43 @@ void storage_process_message_internal(Storage* app, StorageMessage* message) { | |
// Common operations | ||
case StorageCommandCommonTimestamp: | ||
path = furi_string_alloc_set(message->data->ctimestamp.path); | ||
storage_process_alias(app, path, message->data->ctimestamp.thread_id, false); | ||
storage_process_alias(app, path, false); | ||
message->return_data->error_value = | ||
storage_process_common_timestamp(app, path, message->data->ctimestamp.timestamp); | ||
break; | ||
case StorageCommandCommonStat: | ||
path = furi_string_alloc_set(message->data->cstat.path); | ||
storage_process_alias(app, path, message->data->cstat.thread_id, false); | ||
storage_process_alias(app, path, false); | ||
message->return_data->error_value = | ||
storage_process_common_stat(app, path, message->data->cstat.fileinfo); | ||
break; | ||
case StorageCommandCommonRemove: | ||
path = furi_string_alloc_set(message->data->path.path); | ||
storage_process_alias(app, path, message->data->path.thread_id, false); | ||
storage_process_alias(app, path, false); | ||
message->return_data->error_value = storage_process_common_remove(app, path); | ||
break; | ||
case StorageCommandCommonMkDir: | ||
path = furi_string_alloc_set(message->data->path.path); | ||
storage_process_alias(app, path, message->data->path.thread_id, true); | ||
storage_process_alias(app, path, true); | ||
message->return_data->error_value = storage_process_common_mkdir(app, path); | ||
break; | ||
case StorageCommandCommonFSInfo: | ||
path = furi_string_alloc_set(message->data->cfsinfo.fs_path); | ||
storage_process_alias(app, path, message->data->cfsinfo.thread_id, false); | ||
storage_process_alias(app, path, false); | ||
message->return_data->error_value = storage_process_common_fs_info( | ||
app, path, message->data->cfsinfo.total_space, message->data->cfsinfo.free_space); | ||
break; | ||
case StorageCommandCommonResolvePath: | ||
storage_process_alias( | ||
app, message->data->cresolvepath.path, message->data->cresolvepath.thread_id, true); | ||
storage_process_alias(app, message->data->cresolvepath.path, true); | ||
break; | ||
|
||
case StorageCommandCommonEquivalentPath: { | ||
FuriString* path1 = furi_string_alloc_set(message->data->cequivpath.path1); | ||
FuriString* path2 = furi_string_alloc_set(message->data->cequivpath.path2); | ||
storage_path_trim_trailing_slashes(path1); | ||
storage_path_trim_trailing_slashes(path2); | ||
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, path1, false); | ||
storage_process_alias(app, path2, false); | ||
if(message->data->cequivpath.truncate) { | ||
furi_string_left(path2, furi_string_size(path1)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved from storage_i.h "APPS_DATA_PATH" and "APPS_ASSETS_PATH" to here to avoid duplicated definition with "apps_data" explicitly in string. not sure if its fine to be exposed to public api, if it gives wrong idea