M*LIB: non-inlined strings, FuriString primitive (#1795)
* Quicksave 1 * Header stage complete * Source stage complete * Lint & merge fixes * Includes * Documentation step 1 * FBT: output free size considering BT STACK * Documentation step 2 * py lint * Fix music player plugin * unit test stage 1: string allocator, mem, getters, setters, appends, compare, search. * unit test: string equality * unit test: string replace * unit test: string start_with, end_with * unit test: string trim * unit test: utf-8 * Rename * Revert fw_size changes * Simplify CLI backspace handling * Simplify CLI character insert * Merge fixes * Furi: correct filenaming and spelling * Bt: remove furi string include Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <m-string.h>
|
||||
#include "filesystem_api_defines.h"
|
||||
#include "storage_sd_api.h"
|
||||
|
||||
@@ -292,7 +291,7 @@ FS_Error storage_sd_status(Storage* api);
|
||||
|
||||
/******************* Internal LFS Functions *******************/
|
||||
|
||||
typedef void (*Storage_name_converter)(string_t);
|
||||
typedef void (*Storage_name_converter)(FuriString*);
|
||||
|
||||
/** Backs up internal storage to a tar archive
|
||||
* @param api pointer to the api
|
||||
@@ -350,7 +349,7 @@ void storage_get_next_filename(
|
||||
const char* dirname,
|
||||
const char* filename,
|
||||
const char* fileextension,
|
||||
string_t nextfilename,
|
||||
FuriString* nextfilename,
|
||||
uint8_t max_len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@@ -38,11 +38,11 @@ static void storage_cli_print_error(FS_Error error) {
|
||||
printf("Storage error: %s\r\n", storage_error_get_desc(error));
|
||||
}
|
||||
|
||||
static void storage_cli_info(Cli* cli, string_t path) {
|
||||
static void storage_cli_info(Cli* cli, FuriString* path) {
|
||||
UNUSED(cli);
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
if(string_cmp_str(path, STORAGE_INT_PATH_PREFIX) == 0) {
|
||||
if(furi_string_cmp_str(path, STORAGE_INT_PATH_PREFIX) == 0) {
|
||||
uint64_t total_space;
|
||||
uint64_t free_space;
|
||||
FS_Error error =
|
||||
@@ -57,7 +57,7 @@ static void storage_cli_info(Cli* cli, string_t path) {
|
||||
(uint32_t)(total_space / 1024),
|
||||
(uint32_t)(free_space / 1024));
|
||||
}
|
||||
} else if(string_cmp_str(path, STORAGE_EXT_PATH_PREFIX) == 0) {
|
||||
} else if(furi_string_cmp_str(path, STORAGE_EXT_PATH_PREFIX) == 0) {
|
||||
SDInfo sd_info;
|
||||
FS_Error error = storage_sd_info(api, &sd_info);
|
||||
|
||||
@@ -78,10 +78,10 @@ static void storage_cli_info(Cli* cli, string_t path) {
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
};
|
||||
|
||||
static void storage_cli_format(Cli* cli, string_t path) {
|
||||
if(string_cmp_str(path, STORAGE_INT_PATH_PREFIX) == 0) {
|
||||
static void storage_cli_format(Cli* cli, FuriString* path) {
|
||||
if(furi_string_cmp_str(path, STORAGE_INT_PATH_PREFIX) == 0) {
|
||||
storage_cli_print_error(FSE_NOT_IMPLEMENTED);
|
||||
} else if(string_cmp_str(path, STORAGE_EXT_PATH_PREFIX) == 0) {
|
||||
} else if(furi_string_cmp_str(path, STORAGE_EXT_PATH_PREFIX) == 0) {
|
||||
printf("Formatting SD card, All data will be lost! Are you sure (y/n)?\r\n");
|
||||
char answer = cli_getc(cli);
|
||||
if(answer == 'y' || answer == 'Y') {
|
||||
@@ -104,9 +104,9 @@ static void storage_cli_format(Cli* cli, string_t path) {
|
||||
}
|
||||
};
|
||||
|
||||
static void storage_cli_list(Cli* cli, string_t path) {
|
||||
static void storage_cli_list(Cli* cli, FuriString* path) {
|
||||
UNUSED(cli);
|
||||
if(string_cmp_str(path, "/") == 0) {
|
||||
if(furi_string_cmp_str(path, "/") == 0) {
|
||||
printf("\t[D] int\r\n");
|
||||
printf("\t[D] ext\r\n");
|
||||
printf("\t[D] any\r\n");
|
||||
@@ -114,7 +114,7 @@ static void storage_cli_list(Cli* cli, string_t path) {
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(api);
|
||||
|
||||
if(storage_dir_open(file, string_get_cstr(path))) {
|
||||
if(storage_dir_open(file, furi_string_get_cstr(path))) {
|
||||
FileInfo fileinfo;
|
||||
char name[MAX_NAME_LENGTH];
|
||||
bool read_done = false;
|
||||
@@ -141,28 +141,31 @@ static void storage_cli_list(Cli* cli, string_t path) {
|
||||
}
|
||||
}
|
||||
|
||||
static void storage_cli_tree(Cli* cli, string_t path) {
|
||||
if(string_cmp_str(path, "/") == 0) {
|
||||
string_set(path, STORAGE_INT_PATH_PREFIX);
|
||||
static void storage_cli_tree(Cli* cli, FuriString* path) {
|
||||
if(furi_string_cmp_str(path, "/") == 0) {
|
||||
furi_string_set(path, STORAGE_INT_PATH_PREFIX);
|
||||
storage_cli_tree(cli, path);
|
||||
string_set(path, STORAGE_EXT_PATH_PREFIX);
|
||||
furi_string_set(path, STORAGE_EXT_PATH_PREFIX);
|
||||
storage_cli_tree(cli, path);
|
||||
} else {
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
DirWalk* dir_walk = dir_walk_alloc(api);
|
||||
string_t name;
|
||||
string_init(name);
|
||||
FuriString* name;
|
||||
name = furi_string_alloc();
|
||||
|
||||
if(dir_walk_open(dir_walk, string_get_cstr(path))) {
|
||||
if(dir_walk_open(dir_walk, furi_string_get_cstr(path))) {
|
||||
FileInfo fileinfo;
|
||||
bool read_done = false;
|
||||
|
||||
while(dir_walk_read(dir_walk, name, &fileinfo) == DirWalkOK) {
|
||||
read_done = true;
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
printf("\t[D] %s\r\n", string_get_cstr(name));
|
||||
printf("\t[D] %s\r\n", furi_string_get_cstr(name));
|
||||
} else {
|
||||
printf("\t[F] %s %lub\r\n", string_get_cstr(name), (uint32_t)(fileinfo.size));
|
||||
printf(
|
||||
"\t[F] %s %lub\r\n",
|
||||
furi_string_get_cstr(name),
|
||||
(uint32_t)(fileinfo.size));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,18 +176,18 @@ static void storage_cli_tree(Cli* cli, string_t path) {
|
||||
storage_cli_print_error(dir_walk_get_error(dir_walk));
|
||||
}
|
||||
|
||||
string_clear(name);
|
||||
furi_string_free(name);
|
||||
dir_walk_free(dir_walk);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
}
|
||||
|
||||
static void storage_cli_read(Cli* cli, string_t path) {
|
||||
static void storage_cli_read(Cli* cli, FuriString* path) {
|
||||
UNUSED(cli);
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(api);
|
||||
|
||||
if(storage_file_open(file, string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||
if(storage_file_open(file, furi_string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||
const uint16_t buffer_size = 128;
|
||||
uint16_t read_size = 0;
|
||||
uint8_t* data = malloc(buffer_size);
|
||||
@@ -210,14 +213,14 @@ static void storage_cli_read(Cli* cli, string_t path) {
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void storage_cli_write(Cli* cli, string_t path) {
|
||||
static void storage_cli_write(Cli* cli, FuriString* path) {
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(api);
|
||||
|
||||
const uint16_t buffer_size = 512;
|
||||
uint8_t* buffer = malloc(buffer_size);
|
||||
|
||||
if(storage_file_open(file, string_get_cstr(path), FSAM_WRITE, FSOM_OPEN_APPEND)) {
|
||||
if(storage_file_open(file, furi_string_get_cstr(path), FSAM_WRITE, FSOM_OPEN_APPEND)) {
|
||||
printf("Just write your text data. New line by Ctrl+Enter, exit by Ctrl+C.\r\n");
|
||||
|
||||
uint32_t read_index = 0;
|
||||
@@ -264,16 +267,16 @@ static void storage_cli_write(Cli* cli, string_t path) {
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void storage_cli_read_chunks(Cli* cli, string_t path, string_t args) {
|
||||
static void storage_cli_read_chunks(Cli* cli, FuriString* path, FuriString* args) {
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(api);
|
||||
|
||||
uint32_t buffer_size;
|
||||
int parsed_count = sscanf(string_get_cstr(args), "%lu", &buffer_size);
|
||||
int parsed_count = sscanf(furi_string_get_cstr(args), "%lu", &buffer_size);
|
||||
|
||||
if(parsed_count == EOF || parsed_count != 1) {
|
||||
storage_cli_print_usage();
|
||||
} else if(storage_file_open(file, string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||
} else if(storage_file_open(file, furi_string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||
uint64_t file_size = storage_file_size(file);
|
||||
|
||||
printf("Size: %lu\r\n", (uint32_t)file_size);
|
||||
@@ -304,17 +307,17 @@ static void storage_cli_read_chunks(Cli* cli, string_t path, string_t args) {
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void storage_cli_write_chunk(Cli* cli, string_t path, string_t args) {
|
||||
static void storage_cli_write_chunk(Cli* cli, FuriString* path, FuriString* args) {
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(api);
|
||||
|
||||
uint32_t buffer_size;
|
||||
int parsed_count = sscanf(string_get_cstr(args), "%lu", &buffer_size);
|
||||
int parsed_count = sscanf(furi_string_get_cstr(args), "%lu", &buffer_size);
|
||||
|
||||
if(parsed_count == EOF || parsed_count != 1) {
|
||||
storage_cli_print_usage();
|
||||
} else {
|
||||
if(storage_file_open(file, string_get_cstr(path), FSAM_WRITE, FSOM_OPEN_APPEND)) {
|
||||
if(storage_file_open(file, furi_string_get_cstr(path), FSAM_WRITE, FSOM_OPEN_APPEND)) {
|
||||
printf("Ready\r\n");
|
||||
|
||||
if(buffer_size) {
|
||||
@@ -342,20 +345,20 @@ static void storage_cli_write_chunk(Cli* cli, string_t path, string_t args) {
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void storage_cli_stat(Cli* cli, string_t path) {
|
||||
static void storage_cli_stat(Cli* cli, FuriString* path) {
|
||||
UNUSED(cli);
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
|
||||
if(string_cmp_str(path, "/") == 0) {
|
||||
if(furi_string_cmp_str(path, "/") == 0) {
|
||||
printf("Storage\r\n");
|
||||
} else if(
|
||||
string_cmp_str(path, STORAGE_EXT_PATH_PREFIX) == 0 ||
|
||||
string_cmp_str(path, STORAGE_INT_PATH_PREFIX) == 0 ||
|
||||
string_cmp_str(path, STORAGE_ANY_PATH_PREFIX) == 0) {
|
||||
furi_string_cmp_str(path, STORAGE_EXT_PATH_PREFIX) == 0 ||
|
||||
furi_string_cmp_str(path, STORAGE_INT_PATH_PREFIX) == 0 ||
|
||||
furi_string_cmp_str(path, STORAGE_ANY_PATH_PREFIX) == 0) {
|
||||
uint64_t total_space;
|
||||
uint64_t free_space;
|
||||
FS_Error error =
|
||||
storage_common_fs_info(api, string_get_cstr(path), &total_space, &free_space);
|
||||
storage_common_fs_info(api, furi_string_get_cstr(path), &total_space, &free_space);
|
||||
|
||||
if(error != FSE_OK) {
|
||||
storage_cli_print_error(error);
|
||||
@@ -367,7 +370,7 @@ static void storage_cli_stat(Cli* cli, string_t path) {
|
||||
}
|
||||
} else {
|
||||
FileInfo fileinfo;
|
||||
FS_Error error = storage_common_stat(api, string_get_cstr(path), &fileinfo);
|
||||
FS_Error error = storage_common_stat(api, furi_string_get_cstr(path), &fileinfo);
|
||||
|
||||
if(error == FSE_OK) {
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
@@ -383,31 +386,31 @@ static void storage_cli_stat(Cli* cli, string_t path) {
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void storage_cli_copy(Cli* cli, string_t old_path, string_t args) {
|
||||
static void storage_cli_copy(Cli* cli, FuriString* old_path, FuriString* args) {
|
||||
UNUSED(cli);
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
string_t new_path;
|
||||
string_init(new_path);
|
||||
FuriString* new_path;
|
||||
new_path = furi_string_alloc();
|
||||
|
||||
if(!args_read_probably_quoted_string_and_trim(args, new_path)) {
|
||||
storage_cli_print_usage();
|
||||
} else {
|
||||
FS_Error error =
|
||||
storage_common_copy(api, string_get_cstr(old_path), string_get_cstr(new_path));
|
||||
FS_Error error = storage_common_copy(
|
||||
api, furi_string_get_cstr(old_path), furi_string_get_cstr(new_path));
|
||||
|
||||
if(error != FSE_OK) {
|
||||
storage_cli_print_error(error);
|
||||
}
|
||||
}
|
||||
|
||||
string_clear(new_path);
|
||||
furi_string_free(new_path);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void storage_cli_remove(Cli* cli, string_t path) {
|
||||
static void storage_cli_remove(Cli* cli, FuriString* path) {
|
||||
UNUSED(cli);
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
FS_Error error = storage_common_remove(api, string_get_cstr(path));
|
||||
FS_Error error = storage_common_remove(api, furi_string_get_cstr(path));
|
||||
|
||||
if(error != FSE_OK) {
|
||||
storage_cli_print_error(error);
|
||||
@@ -416,31 +419,31 @@ static void storage_cli_remove(Cli* cli, string_t path) {
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void storage_cli_rename(Cli* cli, string_t old_path, string_t args) {
|
||||
static void storage_cli_rename(Cli* cli, FuriString* old_path, FuriString* args) {
|
||||
UNUSED(cli);
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
string_t new_path;
|
||||
string_init(new_path);
|
||||
FuriString* new_path;
|
||||
new_path = furi_string_alloc();
|
||||
|
||||
if(!args_read_probably_quoted_string_and_trim(args, new_path)) {
|
||||
storage_cli_print_usage();
|
||||
} else {
|
||||
FS_Error error =
|
||||
storage_common_rename(api, string_get_cstr(old_path), string_get_cstr(new_path));
|
||||
FS_Error error = storage_common_rename(
|
||||
api, furi_string_get_cstr(old_path), furi_string_get_cstr(new_path));
|
||||
|
||||
if(error != FSE_OK) {
|
||||
storage_cli_print_error(error);
|
||||
}
|
||||
}
|
||||
|
||||
string_clear(new_path);
|
||||
furi_string_free(new_path);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void storage_cli_mkdir(Cli* cli, string_t path) {
|
||||
static void storage_cli_mkdir(Cli* cli, FuriString* path) {
|
||||
UNUSED(cli);
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
FS_Error error = storage_common_mkdir(api, string_get_cstr(path));
|
||||
FS_Error error = storage_common_mkdir(api, furi_string_get_cstr(path));
|
||||
|
||||
if(error != FSE_OK) {
|
||||
storage_cli_print_error(error);
|
||||
@@ -449,12 +452,12 @@ static void storage_cli_mkdir(Cli* cli, string_t path) {
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
static void storage_cli_md5(Cli* cli, string_t path) {
|
||||
static void storage_cli_md5(Cli* cli, FuriString* path) {
|
||||
UNUSED(cli);
|
||||
Storage* api = furi_record_open(RECORD_STORAGE);
|
||||
File* file = storage_file_alloc(api);
|
||||
|
||||
if(storage_file_open(file, string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||
if(storage_file_open(file, furi_string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
|
||||
const uint16_t buffer_size = 512;
|
||||
const uint8_t hash_size = 16;
|
||||
uint8_t* data = malloc(buffer_size);
|
||||
@@ -487,12 +490,12 @@ static void storage_cli_md5(Cli* cli, string_t path) {
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
}
|
||||
|
||||
void storage_cli(Cli* cli, string_t args, void* context) {
|
||||
void storage_cli(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(context);
|
||||
string_t cmd;
|
||||
string_t path;
|
||||
string_init(cmd);
|
||||
string_init(path);
|
||||
FuriString* cmd;
|
||||
FuriString* path;
|
||||
cmd = furi_string_alloc();
|
||||
path = furi_string_alloc();
|
||||
|
||||
do {
|
||||
if(!args_read_string_and_trim(args, cmd)) {
|
||||
@@ -505,72 +508,72 @@ void storage_cli(Cli* cli, string_t args, void* context) {
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "info") == 0) {
|
||||
if(furi_string_cmp_str(cmd, "info") == 0) {
|
||||
storage_cli_info(cli, path);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "format") == 0) {
|
||||
if(furi_string_cmp_str(cmd, "format") == 0) {
|
||||
storage_cli_format(cli, path);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "list") == 0) {
|
||||
if(furi_string_cmp_str(cmd, "list") == 0) {
|
||||
storage_cli_list(cli, path);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "tree") == 0) {
|
||||
if(furi_string_cmp_str(cmd, "tree") == 0) {
|
||||
storage_cli_tree(cli, path);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "read") == 0) {
|
||||
if(furi_string_cmp_str(cmd, "read") == 0) {
|
||||
storage_cli_read(cli, path);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "read_chunks") == 0) {
|
||||
if(furi_string_cmp_str(cmd, "read_chunks") == 0) {
|
||||
storage_cli_read_chunks(cli, path, args);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "write") == 0) {
|
||||
if(furi_string_cmp_str(cmd, "write") == 0) {
|
||||
storage_cli_write(cli, path);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "write_chunk") == 0) {
|
||||
if(furi_string_cmp_str(cmd, "write_chunk") == 0) {
|
||||
storage_cli_write_chunk(cli, path, args);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "copy") == 0) {
|
||||
if(furi_string_cmp_str(cmd, "copy") == 0) {
|
||||
storage_cli_copy(cli, path, args);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "remove") == 0) {
|
||||
if(furi_string_cmp_str(cmd, "remove") == 0) {
|
||||
storage_cli_remove(cli, path);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "rename") == 0) {
|
||||
if(furi_string_cmp_str(cmd, "rename") == 0) {
|
||||
storage_cli_rename(cli, path, args);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "mkdir") == 0) {
|
||||
if(furi_string_cmp_str(cmd, "mkdir") == 0) {
|
||||
storage_cli_mkdir(cli, path);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "md5") == 0) {
|
||||
if(furi_string_cmp_str(cmd, "md5") == 0) {
|
||||
storage_cli_md5(cli, path);
|
||||
break;
|
||||
}
|
||||
|
||||
if(string_cmp_str(cmd, "stat") == 0) {
|
||||
if(furi_string_cmp_str(cmd, "stat") == 0) {
|
||||
storage_cli_stat(cli, path);
|
||||
break;
|
||||
}
|
||||
@@ -578,11 +581,11 @@ void storage_cli(Cli* cli, string_t args, void* context) {
|
||||
storage_cli_print_usage();
|
||||
} while(false);
|
||||
|
||||
string_clear(path);
|
||||
string_clear(cmd);
|
||||
furi_string_free(path);
|
||||
furi_string_free(cmd);
|
||||
}
|
||||
|
||||
static void storage_cli_factory_reset(Cli* cli, string_t args, void* context) {
|
||||
static void storage_cli_factory_reset(Cli* cli, FuriString* args, void* context) {
|
||||
UNUSED(args);
|
||||
UNUSED(context);
|
||||
printf("All data will be lost! Are you sure (y/n)?\r\n");
|
||||
|
@@ -1,6 +1,5 @@
|
||||
#include <core/log.h>
|
||||
#include <core/record.h>
|
||||
#include <m-string.h>
|
||||
#include "storage.h"
|
||||
#include "storage_i.h"
|
||||
#include "storage_message.h"
|
||||
@@ -374,13 +373,13 @@ static FS_Error
|
||||
storage_copy_recursive(Storage* storage, const char* old_path, const char* new_path) {
|
||||
FS_Error error = storage_common_mkdir(storage, new_path);
|
||||
DirWalk* dir_walk = dir_walk_alloc(storage);
|
||||
string_t path;
|
||||
string_t tmp_new_path;
|
||||
string_t tmp_old_path;
|
||||
FuriString* path;
|
||||
FuriString* tmp_new_path;
|
||||
FuriString* tmp_old_path;
|
||||
FileInfo fileinfo;
|
||||
string_init(path);
|
||||
string_init(tmp_new_path);
|
||||
string_init(tmp_old_path);
|
||||
path = furi_string_alloc();
|
||||
tmp_new_path = furi_string_alloc();
|
||||
tmp_old_path = furi_string_alloc();
|
||||
|
||||
do {
|
||||
if(error != FSE_OK) break;
|
||||
@@ -399,15 +398,17 @@ static FS_Error
|
||||
} else if(res == DirWalkLast) {
|
||||
break;
|
||||
} else {
|
||||
string_set(tmp_old_path, path);
|
||||
string_right(path, strlen(old_path));
|
||||
string_printf(tmp_new_path, "%s%s", new_path, string_get_cstr(path));
|
||||
furi_string_set(tmp_old_path, path);
|
||||
furi_string_right(path, strlen(old_path));
|
||||
furi_string_printf(tmp_new_path, "%s%s", new_path, furi_string_get_cstr(path));
|
||||
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
error = storage_common_mkdir(storage, string_get_cstr(tmp_new_path));
|
||||
error = storage_common_mkdir(storage, furi_string_get_cstr(tmp_new_path));
|
||||
} else {
|
||||
error = storage_common_copy(
|
||||
storage, string_get_cstr(tmp_old_path), string_get_cstr(tmp_new_path));
|
||||
storage,
|
||||
furi_string_get_cstr(tmp_old_path),
|
||||
furi_string_get_cstr(tmp_new_path));
|
||||
}
|
||||
|
||||
if(error != FSE_OK) break;
|
||||
@@ -416,9 +417,9 @@ static FS_Error
|
||||
|
||||
} while(false);
|
||||
|
||||
string_clear(tmp_new_path);
|
||||
string_clear(tmp_old_path);
|
||||
string_clear(path);
|
||||
furi_string_free(tmp_new_path);
|
||||
furi_string_free(tmp_old_path);
|
||||
furi_string_free(path);
|
||||
dir_walk_free(dir_walk);
|
||||
return error;
|
||||
}
|
||||
@@ -459,11 +460,11 @@ static FS_Error
|
||||
storage_merge_recursive(Storage* storage, const char* old_path, const char* new_path) {
|
||||
FS_Error error = storage_common_mkdir(storage, new_path);
|
||||
DirWalk* dir_walk = dir_walk_alloc(storage);
|
||||
string_t path, file_basename, tmp_new_path;
|
||||
FuriString *path, *file_basename, *tmp_new_path;
|
||||
FileInfo fileinfo;
|
||||
string_init(path);
|
||||
string_init(file_basename);
|
||||
string_init(tmp_new_path);
|
||||
path = furi_string_alloc();
|
||||
file_basename = furi_string_alloc();
|
||||
tmp_new_path = furi_string_alloc();
|
||||
|
||||
do {
|
||||
if((error != FSE_OK) && (error != FSE_EXIST)) break;
|
||||
@@ -483,14 +484,15 @@ static FS_Error
|
||||
} else if(res == DirWalkLast) {
|
||||
break;
|
||||
} else {
|
||||
path_extract_basename(string_get_cstr(path), file_basename);
|
||||
path_concat(new_path, string_get_cstr(file_basename), tmp_new_path);
|
||||
path_extract_basename(furi_string_get_cstr(path), file_basename);
|
||||
path_concat(new_path, furi_string_get_cstr(file_basename), tmp_new_path);
|
||||
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
if(storage_common_stat(storage, string_get_cstr(tmp_new_path), &fileinfo) ==
|
||||
FSE_OK) {
|
||||
if(storage_common_stat(
|
||||
storage, furi_string_get_cstr(tmp_new_path), &fileinfo) == FSE_OK) {
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
error = storage_common_mkdir(storage, string_get_cstr(tmp_new_path));
|
||||
error =
|
||||
storage_common_mkdir(storage, furi_string_get_cstr(tmp_new_path));
|
||||
if(error != FSE_OK) {
|
||||
break;
|
||||
}
|
||||
@@ -498,7 +500,7 @@ static FS_Error
|
||||
}
|
||||
}
|
||||
error = storage_common_merge(
|
||||
storage, string_get_cstr(path), string_get_cstr(tmp_new_path));
|
||||
storage, furi_string_get_cstr(path), furi_string_get_cstr(tmp_new_path));
|
||||
|
||||
if(error != FSE_OK) {
|
||||
break;
|
||||
@@ -508,9 +510,9 @@ static FS_Error
|
||||
|
||||
} while(false);
|
||||
|
||||
string_clear(tmp_new_path);
|
||||
string_clear(file_basename);
|
||||
string_clear(path);
|
||||
furi_string_free(tmp_new_path);
|
||||
furi_string_free(file_basename);
|
||||
furi_string_free(path);
|
||||
dir_walk_free(dir_walk);
|
||||
return error;
|
||||
}
|
||||
@@ -518,8 +520,8 @@ static FS_Error
|
||||
FS_Error storage_common_merge(Storage* storage, const char* old_path, const char* new_path) {
|
||||
FS_Error error;
|
||||
const char* new_path_tmp;
|
||||
string_t new_path_next;
|
||||
string_init(new_path_next);
|
||||
FuriString* new_path_next;
|
||||
new_path_next = furi_string_alloc();
|
||||
|
||||
FileInfo fileinfo;
|
||||
error = storage_common_stat(storage, old_path, &fileinfo);
|
||||
@@ -530,13 +532,13 @@ FS_Error storage_common_merge(Storage* storage, const char* old_path, const char
|
||||
} else {
|
||||
error = storage_common_stat(storage, new_path, &fileinfo);
|
||||
if(error == FSE_OK) {
|
||||
string_set_str(new_path_next, new_path);
|
||||
string_t dir_path;
|
||||
string_t filename;
|
||||
furi_string_set(new_path_next, new_path);
|
||||
FuriString* dir_path;
|
||||
FuriString* filename;
|
||||
char extension[MAX_EXT_LEN];
|
||||
|
||||
string_init(dir_path);
|
||||
string_init(filename);
|
||||
dir_path = furi_string_alloc();
|
||||
filename = furi_string_alloc();
|
||||
|
||||
path_extract_filename(new_path_next, filename, true);
|
||||
path_extract_dirname(new_path, dir_path);
|
||||
@@ -544,17 +546,18 @@ FS_Error storage_common_merge(Storage* storage, const char* old_path, const char
|
||||
|
||||
storage_get_next_filename(
|
||||
storage,
|
||||
string_get_cstr(dir_path),
|
||||
string_get_cstr(filename),
|
||||
furi_string_get_cstr(dir_path),
|
||||
furi_string_get_cstr(filename),
|
||||
extension,
|
||||
new_path_next,
|
||||
255);
|
||||
string_cat_printf(dir_path, "/%s%s", string_get_cstr(new_path_next), extension);
|
||||
string_set(new_path_next, dir_path);
|
||||
furi_string_cat_printf(
|
||||
dir_path, "/%s%s", furi_string_get_cstr(new_path_next), extension);
|
||||
furi_string_set(new_path_next, dir_path);
|
||||
|
||||
string_clear(dir_path);
|
||||
string_clear(filename);
|
||||
new_path_tmp = string_get_cstr(new_path_next);
|
||||
furi_string_free(dir_path);
|
||||
furi_string_free(filename);
|
||||
new_path_tmp = furi_string_get_cstr(new_path_next);
|
||||
} else {
|
||||
new_path_tmp = new_path;
|
||||
}
|
||||
@@ -577,7 +580,7 @@ FS_Error storage_common_merge(Storage* storage, const char* old_path, const char
|
||||
}
|
||||
}
|
||||
|
||||
string_clear(new_path_next);
|
||||
furi_string_free(new_path_next);
|
||||
|
||||
return error;
|
||||
}
|
||||
@@ -707,8 +710,8 @@ bool storage_simply_remove_recursive(Storage* storage, const char* path) {
|
||||
furi_assert(path);
|
||||
FileInfo fileinfo;
|
||||
bool result = false;
|
||||
string_t fullname;
|
||||
string_t cur_dir;
|
||||
FuriString* fullname;
|
||||
FuriString* cur_dir;
|
||||
|
||||
if(storage_simply_remove(storage, path)) {
|
||||
return true;
|
||||
@@ -716,26 +719,26 @@ bool storage_simply_remove_recursive(Storage* storage, const char* path) {
|
||||
|
||||
char* name = malloc(MAX_NAME_LENGTH + 1);
|
||||
File* dir = storage_file_alloc(storage);
|
||||
string_init_set_str(cur_dir, path);
|
||||
cur_dir = furi_string_alloc_set(path);
|
||||
bool go_deeper = false;
|
||||
|
||||
while(1) {
|
||||
if(!storage_dir_open(dir, string_get_cstr(cur_dir))) {
|
||||
if(!storage_dir_open(dir, furi_string_get_cstr(cur_dir))) {
|
||||
storage_dir_close(dir);
|
||||
break;
|
||||
}
|
||||
|
||||
while(storage_dir_read(dir, &fileinfo, name, MAX_NAME_LENGTH)) {
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
string_cat_printf(cur_dir, "/%s", name);
|
||||
furi_string_cat_printf(cur_dir, "/%s", name);
|
||||
go_deeper = true;
|
||||
break;
|
||||
}
|
||||
|
||||
string_init_printf(fullname, "%s/%s", string_get_cstr(cur_dir), name);
|
||||
FS_Error error = storage_common_remove(storage, string_get_cstr(fullname));
|
||||
fullname = furi_string_alloc_printf("%s/%s", furi_string_get_cstr(cur_dir), name);
|
||||
FS_Error error = storage_common_remove(storage, furi_string_get_cstr(fullname));
|
||||
furi_check(error == FSE_OK);
|
||||
string_clear(fullname);
|
||||
furi_string_free(fullname);
|
||||
}
|
||||
storage_dir_close(dir);
|
||||
|
||||
@@ -744,13 +747,13 @@ bool storage_simply_remove_recursive(Storage* storage, const char* path) {
|
||||
continue;
|
||||
}
|
||||
|
||||
FS_Error error = storage_common_remove(storage, string_get_cstr(cur_dir));
|
||||
FS_Error error = storage_common_remove(storage, furi_string_get_cstr(cur_dir));
|
||||
furi_check(error == FSE_OK);
|
||||
|
||||
if(string_cmp(cur_dir, path)) {
|
||||
size_t last_char = string_search_rchar(cur_dir, '/');
|
||||
furi_assert(last_char != STRING_FAILURE);
|
||||
string_left(cur_dir, last_char);
|
||||
if(furi_string_cmp(cur_dir, path)) {
|
||||
size_t last_char = furi_string_search_rchar(cur_dir, '/');
|
||||
furi_assert(last_char != FURI_STRING_FAILURE);
|
||||
furi_string_left(cur_dir, last_char);
|
||||
} else {
|
||||
result = true;
|
||||
break;
|
||||
@@ -758,7 +761,7 @@ bool storage_simply_remove_recursive(Storage* storage, const char* path) {
|
||||
}
|
||||
|
||||
storage_file_free(dir);
|
||||
string_clear(cur_dir);
|
||||
furi_string_free(cur_dir);
|
||||
free(name);
|
||||
return result;
|
||||
}
|
||||
@@ -780,22 +783,22 @@ void storage_get_next_filename(
|
||||
const char* dirname,
|
||||
const char* filename,
|
||||
const char* fileextension,
|
||||
string_t nextfilename,
|
||||
FuriString* nextfilename,
|
||||
uint8_t max_len) {
|
||||
string_t temp_str;
|
||||
FuriString* temp_str;
|
||||
uint16_t num = 0;
|
||||
|
||||
string_init_printf(temp_str, "%s/%s%s", dirname, filename, fileextension);
|
||||
temp_str = furi_string_alloc_printf("%s/%s%s", dirname, filename, fileextension);
|
||||
|
||||
while(storage_common_stat(storage, string_get_cstr(temp_str), NULL) == FSE_OK) {
|
||||
while(storage_common_stat(storage, furi_string_get_cstr(temp_str), NULL) == FSE_OK) {
|
||||
num++;
|
||||
string_printf(temp_str, "%s/%s%d%s", dirname, filename, num, fileextension);
|
||||
furi_string_printf(temp_str, "%s/%s%d%s", dirname, filename, num, fileextension);
|
||||
}
|
||||
if(num && (max_len > strlen(filename))) {
|
||||
string_printf(nextfilename, "%s%d", filename, num);
|
||||
furi_string_printf(nextfilename, "%s%d", filename, num);
|
||||
} else {
|
||||
string_printf(nextfilename, "%s", filename);
|
||||
furi_string_printf(nextfilename, "%s", filename);
|
||||
}
|
||||
|
||||
string_clear(temp_str);
|
||||
furi_string_free(temp_str);
|
||||
}
|
||||
|
@@ -7,25 +7,25 @@ void storage_file_init(StorageFile* obj) {
|
||||
obj->file = NULL;
|
||||
obj->type = ST_ERROR;
|
||||
obj->file_data = NULL;
|
||||
string_init(obj->path);
|
||||
obj->path = furi_string_alloc();
|
||||
}
|
||||
|
||||
void storage_file_init_set(StorageFile* obj, const StorageFile* src) {
|
||||
obj->file = src->file;
|
||||
obj->type = src->type;
|
||||
obj->file_data = src->file_data;
|
||||
string_init_set(obj->path, src->path);
|
||||
obj->path = furi_string_alloc_set(src->path);
|
||||
}
|
||||
|
||||
void storage_file_set(StorageFile* obj, const StorageFile* src) {
|
||||
obj->file = src->file;
|
||||
obj->type = src->type;
|
||||
obj->file_data = src->file_data;
|
||||
string_set(obj->path, src->path);
|
||||
furi_string_set(obj->path, src->path);
|
||||
}
|
||||
|
||||
void storage_file_clear(StorageFile* obj) {
|
||||
string_clear(obj->path);
|
||||
furi_string_free(obj->path);
|
||||
}
|
||||
|
||||
/****************** storage data ******************/
|
||||
@@ -101,7 +101,7 @@ bool storage_has_file(const File* file, StorageData* storage_data) {
|
||||
return result;
|
||||
}
|
||||
|
||||
bool storage_path_already_open(string_t path, StorageFileList_t array) {
|
||||
bool storage_path_already_open(FuriString* path, StorageFileList_t array) {
|
||||
bool open = false;
|
||||
|
||||
StorageFileList_it_t it;
|
||||
@@ -109,7 +109,7 @@ bool storage_path_already_open(string_t path, StorageFileList_t array) {
|
||||
for(StorageFileList_it(it, array); !StorageFileList_end_p(it); StorageFileList_next(it)) {
|
||||
const StorageFile* storage_file = StorageFileList_cref(it);
|
||||
|
||||
if(string_cmp(storage_file->path, path) == 0) {
|
||||
if(furi_string_cmp(storage_file->path, path) == 0) {
|
||||
open = true;
|
||||
break;
|
||||
}
|
||||
@@ -158,14 +158,18 @@ void* storage_get_storage_file_data(const File* file, StorageData* storage) {
|
||||
return founded_file->file_data;
|
||||
}
|
||||
|
||||
void storage_push_storage_file(File* file, string_t path, StorageType type, StorageData* storage) {
|
||||
void storage_push_storage_file(
|
||||
File* file,
|
||||
FuriString* path,
|
||||
StorageType type,
|
||||
StorageData* storage) {
|
||||
StorageFile* storage_file = StorageFileList_push_new(storage->files);
|
||||
furi_check(storage_file != NULL);
|
||||
|
||||
file->file_id = (uint32_t)storage_file;
|
||||
storage_file->file = file;
|
||||
storage_file->type = type;
|
||||
string_set(storage_file->path, path);
|
||||
furi_string_set(storage_file->path, path);
|
||||
}
|
||||
|
||||
bool storage_pop_storage_file(File* file, StorageData* storage) {
|
||||
|
@@ -2,7 +2,6 @@
|
||||
|
||||
#include <furi.h>
|
||||
#include "filesystem_api_internal.h"
|
||||
#include <m-string.h>
|
||||
#include <m-list.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -21,7 +20,7 @@ typedef struct {
|
||||
File* file;
|
||||
StorageType type;
|
||||
void* file_data;
|
||||
string_t path;
|
||||
FuriString* path;
|
||||
} StorageFile;
|
||||
|
||||
typedef enum {
|
||||
@@ -62,12 +61,16 @@ struct StorageData {
|
||||
};
|
||||
|
||||
bool storage_has_file(const File* file, StorageData* storage_data);
|
||||
bool storage_path_already_open(string_t path, StorageFileList_t files);
|
||||
bool storage_path_already_open(FuriString* path, StorageFileList_t files);
|
||||
|
||||
void storage_set_storage_file_data(const File* file, void* file_data, StorageData* storage);
|
||||
void* storage_get_storage_file_data(const File* file, StorageData* storage);
|
||||
|
||||
void storage_push_storage_file(File* file, string_t path, StorageType type, StorageData* storage);
|
||||
void storage_push_storage_file(
|
||||
File* file,
|
||||
FuriString* path,
|
||||
StorageType type,
|
||||
StorageData* storage);
|
||||
bool storage_pop_storage_file(File* file, StorageData* storage);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#include <core/record.h>
|
||||
#include <m-string.h>
|
||||
#include "storage.h"
|
||||
#include <toolbox/tar/tar_archive.h>
|
||||
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#include "storage_processing.h"
|
||||
#include <m-list.h>
|
||||
#include <m-dict.h>
|
||||
#include <m-string.h>
|
||||
|
||||
#define FS_CALL(_storage, _fn) \
|
||||
storage_data_lock(_storage); \
|
||||
@@ -68,21 +67,22 @@ static StorageType storage_get_type_by_path(Storage* app, const char* path) {
|
||||
return type;
|
||||
}
|
||||
|
||||
static void storage_path_change_to_real_storage(string_t path, StorageType real_storage) {
|
||||
if(memcmp(string_get_cstr(path), STORAGE_ANY_PATH_PREFIX, strlen(STORAGE_ANY_PATH_PREFIX)) ==
|
||||
static void storage_path_change_to_real_storage(FuriString* path, StorageType real_storage) {
|
||||
if(memcmp(
|
||||
furi_string_get_cstr(path), STORAGE_ANY_PATH_PREFIX, strlen(STORAGE_ANY_PATH_PREFIX)) ==
|
||||
0) {
|
||||
switch(real_storage) {
|
||||
case ST_EXT:
|
||||
string_set_char(path, 0, STORAGE_EXT_PATH_PREFIX[0]);
|
||||
string_set_char(path, 1, STORAGE_EXT_PATH_PREFIX[1]);
|
||||
string_set_char(path, 2, STORAGE_EXT_PATH_PREFIX[2]);
|
||||
string_set_char(path, 3, STORAGE_EXT_PATH_PREFIX[3]);
|
||||
furi_string_set_char(path, 0, STORAGE_EXT_PATH_PREFIX[0]);
|
||||
furi_string_set_char(path, 1, STORAGE_EXT_PATH_PREFIX[1]);
|
||||
furi_string_set_char(path, 2, STORAGE_EXT_PATH_PREFIX[2]);
|
||||
furi_string_set_char(path, 3, STORAGE_EXT_PATH_PREFIX[3]);
|
||||
break;
|
||||
case ST_INT:
|
||||
string_set_char(path, 0, STORAGE_INT_PATH_PREFIX[0]);
|
||||
string_set_char(path, 1, STORAGE_INT_PATH_PREFIX[1]);
|
||||
string_set_char(path, 2, STORAGE_INT_PATH_PREFIX[2]);
|
||||
string_set_char(path, 3, STORAGE_INT_PATH_PREFIX[3]);
|
||||
furi_string_set_char(path, 0, STORAGE_INT_PATH_PREFIX[0]);
|
||||
furi_string_set_char(path, 1, STORAGE_INT_PATH_PREFIX[1]);
|
||||
furi_string_set_char(path, 2, STORAGE_INT_PATH_PREFIX[2]);
|
||||
furi_string_set_char(path, 3, STORAGE_INT_PATH_PREFIX[3]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -107,8 +107,8 @@ bool storage_process_file_open(
|
||||
file->error_id = FSE_INVALID_NAME;
|
||||
} else {
|
||||
storage = storage_get_storage_by_type(app, type);
|
||||
string_t real_path;
|
||||
string_init_set(real_path, path);
|
||||
FuriString* real_path;
|
||||
real_path = furi_string_alloc_set(path);
|
||||
storage_path_change_to_real_storage(real_path, type);
|
||||
|
||||
if(storage_path_already_open(real_path, storage->files)) {
|
||||
@@ -118,7 +118,7 @@ bool storage_process_file_open(
|
||||
FS_CALL(storage, file.open(storage, file, remove_vfs(path), access_mode, open_mode));
|
||||
}
|
||||
|
||||
string_clear(real_path);
|
||||
furi_string_free(real_path);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -266,8 +266,8 @@ bool storage_process_dir_open(Storage* app, File* file, const char* path) {
|
||||
file->error_id = FSE_INVALID_NAME;
|
||||
} else {
|
||||
storage = storage_get_storage_by_type(app, type);
|
||||
string_t real_path;
|
||||
string_init_set(real_path, path);
|
||||
FuriString* real_path;
|
||||
real_path = furi_string_alloc_set(path);
|
||||
storage_path_change_to_real_storage(real_path, type);
|
||||
|
||||
if(storage_path_already_open(real_path, storage->files)) {
|
||||
@@ -276,7 +276,7 @@ bool storage_process_dir_open(Storage* app, File* file, const char* path) {
|
||||
storage_push_storage_file(file, real_path, type, storage);
|
||||
FS_CALL(storage, dir.open(storage, file, remove_vfs(path)));
|
||||
}
|
||||
string_clear(real_path);
|
||||
furi_string_free(real_path);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -350,8 +350,8 @@ static FS_Error storage_process_common_remove(Storage* app, const char* path) {
|
||||
FS_Error ret = FSE_OK;
|
||||
StorageType type = storage_get_type_by_path(app, path);
|
||||
|
||||
string_t real_path;
|
||||
string_init_set(real_path, path);
|
||||
FuriString* real_path;
|
||||
real_path = furi_string_alloc_set(path);
|
||||
storage_path_change_to_real_storage(real_path, type);
|
||||
|
||||
do {
|
||||
@@ -369,7 +369,7 @@ static FS_Error storage_process_common_remove(Storage* app, const char* path) {
|
||||
FS_CALL(storage, common.remove(storage, remove_vfs(path)));
|
||||
} while(false);
|
||||
|
||||
string_clear(real_path);
|
||||
furi_string_free(real_path);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@@ -224,13 +224,12 @@ static void do_dir_test(Storage* api, const char* path) {
|
||||
}
|
||||
|
||||
static void do_test_start(Storage* api, const char* path) {
|
||||
string_t str_path;
|
||||
string_init_printf(str_path, "%s/test-folder", path);
|
||||
FuriString* str_path = furi_string_alloc_printf("%s/test-folder", path);
|
||||
|
||||
FURI_LOG_I(TAG, "--------- START \"%s\" ---------", path);
|
||||
|
||||
// mkdir
|
||||
FS_Error result = storage_common_mkdir(api, string_get_cstr(str_path));
|
||||
FS_Error result = storage_common_mkdir(api, furi_string_get_cstr(str_path));
|
||||
|
||||
if(result == FSE_OK) {
|
||||
FURI_LOG_I(TAG, "mkdir ok");
|
||||
@@ -240,7 +239,7 @@ static void do_test_start(Storage* api, const char* path) {
|
||||
|
||||
// stat
|
||||
FileInfo fileinfo;
|
||||
result = storage_common_stat(api, string_get_cstr(str_path), &fileinfo);
|
||||
result = storage_common_stat(api, furi_string_get_cstr(str_path), &fileinfo);
|
||||
|
||||
if(result == FSE_OK) {
|
||||
if(fileinfo.flags & FSF_DIRECTORY) {
|
||||
@@ -252,16 +251,14 @@ static void do_test_start(Storage* api, const char* path) {
|
||||
FURI_LOG_E(TAG, "stat #1, %s", storage_error_get_desc(result));
|
||||
}
|
||||
|
||||
string_clear(str_path);
|
||||
furi_string_free(str_path);
|
||||
}
|
||||
|
||||
static void do_test_end(Storage* api, const char* path) {
|
||||
uint64_t total_space;
|
||||
uint64_t free_space;
|
||||
string_t str_path_1;
|
||||
string_t str_path_2;
|
||||
string_init_printf(str_path_1, "%s/test-folder", path);
|
||||
string_init_printf(str_path_2, "%s/test-folder2", path);
|
||||
FuriString* str_path_1 = furi_string_alloc_printf("%s/test-folder", path);
|
||||
FuriString* str_path_2 = furi_string_alloc_printf("%s/test-folder2", path);
|
||||
|
||||
FURI_LOG_I(TAG, "--------- END \"%s\" ---------", path);
|
||||
|
||||
@@ -277,7 +274,8 @@ static void do_test_end(Storage* api, const char* path) {
|
||||
}
|
||||
|
||||
// rename #1
|
||||
result = storage_common_rename(api, string_get_cstr(str_path_1), string_get_cstr(str_path_2));
|
||||
result = storage_common_rename(
|
||||
api, furi_string_get_cstr(str_path_1), furi_string_get_cstr(str_path_2));
|
||||
if(result == FSE_OK) {
|
||||
FURI_LOG_I(TAG, "rename #1 ok");
|
||||
} else {
|
||||
@@ -285,7 +283,7 @@ static void do_test_end(Storage* api, const char* path) {
|
||||
}
|
||||
|
||||
// remove #1
|
||||
result = storage_common_remove(api, string_get_cstr(str_path_2));
|
||||
result = storage_common_remove(api, furi_string_get_cstr(str_path_2));
|
||||
if(result == FSE_OK) {
|
||||
FURI_LOG_I(TAG, "remove #1 ok");
|
||||
} else {
|
||||
@@ -293,10 +291,11 @@ static void do_test_end(Storage* api, const char* path) {
|
||||
}
|
||||
|
||||
// rename #2
|
||||
string_printf(str_path_1, "%s/test.txt", path);
|
||||
string_printf(str_path_2, "%s/test2.txt", path);
|
||||
furi_string_printf(str_path_1, "%s/test.txt", path);
|
||||
furi_string_printf(str_path_2, "%s/test2.txt", path);
|
||||
|
||||
result = storage_common_rename(api, string_get_cstr(str_path_1), string_get_cstr(str_path_2));
|
||||
result = storage_common_rename(
|
||||
api, furi_string_get_cstr(str_path_1), furi_string_get_cstr(str_path_2));
|
||||
if(result == FSE_OK) {
|
||||
FURI_LOG_I(TAG, "rename #2 ok");
|
||||
} else {
|
||||
@@ -304,15 +303,15 @@ static void do_test_end(Storage* api, const char* path) {
|
||||
}
|
||||
|
||||
// remove #2
|
||||
result = storage_common_remove(api, string_get_cstr(str_path_2));
|
||||
result = storage_common_remove(api, furi_string_get_cstr(str_path_2));
|
||||
if(result == FSE_OK) {
|
||||
FURI_LOG_I(TAG, "remove #2 ok");
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "remove #2, %s", storage_error_get_desc(result));
|
||||
}
|
||||
|
||||
string_clear(str_path_1);
|
||||
string_clear(str_path_2);
|
||||
furi_string_free(str_path_1);
|
||||
furi_string_free(str_path_2);
|
||||
}
|
||||
|
||||
int32_t storage_test_app(void* p) {
|
||||
|
@@ -338,11 +338,12 @@ static bool storage_int_file_open(
|
||||
storage_set_storage_file_data(file, handle, storage);
|
||||
|
||||
if(!enough_free_space) {
|
||||
string_t filename;
|
||||
string_init(filename);
|
||||
FuriString* filename;
|
||||
filename = furi_string_alloc();
|
||||
path_extract_basename(path, filename);
|
||||
bool is_dot_file = (!string_empty_p(filename) && (string_get_char(filename, 0) == '.'));
|
||||
string_clear(filename);
|
||||
bool is_dot_file =
|
||||
(!furi_string_empty(filename) && (furi_string_get_char(filename, 0) == '.'));
|
||||
furi_string_free(filename);
|
||||
|
||||
/* Restrict write & creation access to all non-dot files */
|
||||
if(!is_dot_file && (flags & (LFS_O_CREAT | LFS_O_WRONLY))) {
|
||||
|
Reference in New Issue
Block a user