]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
add fat command mv
authorLeo C. <erbl259-lmu@yahoo.de>
Tue, 23 Jul 2024 19:07:38 +0000 (21:07 +0200)
committerLeo C. <erbl259-lmu@yahoo.de>
Tue, 23 Jul 2024 19:07:38 +0000 (21:07 +0200)
avr/cmd_fat.c

index c97fd79cdb51b5ba271cc5a159da06d4fab6fad3..41821e11584d0a7fcde879fd3689d21f73a6a2be 100644 (file)
@@ -408,6 +408,19 @@ void ff_copy(const TCHAR* path_old, const TCHAR* path_new)
     return;
 }
 
     return;
 }
 
+void ff_move(const TCHAR* path_old, const TCHAR* path_new)
+{
+    FRESULT res;
+
+       if (cmd_flags & V_FLAG)
+               printf_P(PSTR("'%s' -> '%s'\n"), path_old, path_new);
+    if ((res = f_rename(path_old, path_new)) != FR_OK)
+               cmd_error(0, res, PSTR("error copying '%s' to '%s'"), path_old, path_new);
+
+       exit_val = (res != FR_OK);
+    return;
+}
+
 void ff_iterate(fatfunc_t fatfunc, int count, char* const file[], char* dest)
 {
     FRESULT res = 0;
 void ff_iterate(fatfunc_t fatfunc, int count, char* const file[], char* dest)
 {
     FRESULT res = 0;
@@ -491,10 +504,11 @@ command_ret_t do_rm(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc,
        return exit_val;
 }
 
        return exit_val;
 }
 
-command_ret_t do_cp(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[])
+command_ret_t do_cp_or_mv(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc, char * const argv[])
 {
        exit_val = CMD_RET_SUCCESS;
        cmd_flags = 0;
 {
        exit_val = CMD_RET_SUCCESS;
        cmd_flags = 0;
+       fatfunc_t func = (argv[0][0] == 'c') ? ff_copy : ff_move;
 
        int opt;
        while ((opt = getopt(argc, argv, PSTR("v"))) != -1) {
 
        int opt;
        while ((opt = getopt(argc, argv, PSTR("v"))) != -1) {
@@ -515,7 +529,7 @@ command_ret_t do_cp(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc,
     if (argc < 2)
                return CMD_RET_USAGE;
 
     if (argc < 2)
                return CMD_RET_USAGE;
 
-    ff_iterate(ff_copy, argc - 1, argv, argv[argc - 1]);
+    ff_iterate(func, argc - 1, argv, argv[argc - 1]);
 
     return exit_val;
 }
 
     return exit_val;
 }
@@ -851,7 +865,7 @@ CMD_TBL_ITEM(
        "    -v explain what is being done"
 ),
 CMD_TBL_ITEM(
        "    -v explain what is being done"
 ),
 CMD_TBL_ITEM(
-       cp,     CONFIG_SYS_MAXARGS,     0,      do_cp,
+       cp,     CONFIG_SYS_MAXARGS,     0,      do_cp_or_mv,
        "Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.",
        "[OPTION]... SOURCE... DEST\n"
 //     "    -f overwrite existing file ignoring write protection\n"
        "Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.",
        "[OPTION]... SOURCE... DEST\n"
 //     "    -f overwrite existing file ignoring write protection\n"
@@ -861,6 +875,12 @@ CMD_TBL_ITEM(
 //     "    -p preserve attributes and timestamps\n"
        "    -v explain what is being done"
 ),
 //     "    -p preserve attributes and timestamps\n"
        "    -v explain what is being done"
 ),
+CMD_TBL_ITEM(
+       mv,     CONFIG_SYS_MAXARGS,     0,      do_cp_or_mv,
+       "Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.",
+       "[OPTION]... SOURCE DEST\n"
+       "    -v explain what is being done"
+),
 
 CMD_TBL_ITEM(
        load,   5,      0,      do_rw,
 
 CMD_TBL_ITEM(
        load,   5,      0,      do_rw,