From bd9f2b6ff70581a935a666e67ee3d099070e9832 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 18 Jul 2023 00:23:05 +0100 Subject: [PATCH] Add migrate to storage cli --- applications/services/storage/storage_cli.c | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/applications/services/storage/storage_cli.c b/applications/services/storage/storage_cli.c index 096060d82..447e76afc 100644 --- a/applications/services/storage/storage_cli.c +++ b/applications/services/storage/storage_cli.c @@ -29,6 +29,7 @@ static void storage_cli_print_usage() { "\twrite_chunk\t - read data from cli and append it to file, should contain how many bytes you want to write\r\n"); printf("\tcopy\t - copy file to new file, must contain new path\r\n"); printf("\trename\t - move file to new file, must contain new path\r\n"); + printf("\tmigrate\t - \r\n"); printf("\tmkdir\t - creates a new directory\r\n"); printf("\tmd5\t - md5 hash of the file\r\n"); printf("\tstat\t - info about file or dir\r\n"); @@ -466,6 +467,27 @@ static void storage_cli_rename(Cli* cli, FuriString* old_path, FuriString* args) furi_record_close(RECORD_STORAGE); } +static void storage_cli_migrate(Cli* cli, FuriString* old_path, FuriString* args) { + UNUSED(cli); + Storage* api = furi_record_open(RECORD_STORAGE); + 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_migrate( + api, furi_string_get_cstr(old_path), furi_string_get_cstr(new_path)); + + if(error != FSE_OK) { + storage_cli_print_error(error); + } + } + + furi_string_free(new_path); + furi_record_close(RECORD_STORAGE); +} + static void storage_cli_mkdir(Cli* cli, FuriString* path) { UNUSED(cli); Storage* api = furi_record_open(RECORD_STORAGE); @@ -589,6 +611,11 @@ void storage_cli(Cli* cli, FuriString* args, void* context) { break; } + if(furi_string_cmp_str(cmd, "migrate") == 0) { + storage_cli_migrate(cli, path, args); + break; + } + if(furi_string_cmp_str(cmd, "mkdir") == 0) { storage_cli_mkdir(cli, path); break;