]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
some bugs fixed (WIP)
authorLeo C <erbl259-lmu@yahoo.de>
Wed, 11 Apr 2018 12:37:07 +0000 (14:37 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Wed, 11 Apr 2018 12:37:07 +0000 (14:37 +0200)
avr/cmd_fat.c

index 7717d6ec9a3dec2da8478393371054eabc405eef..633834c136ca06a7be25343e8ac6098474c209dc 100644 (file)
@@ -561,7 +561,7 @@ void copy_file(FILINFO *fs, uint_fast8_t dne)
        FRESULT fr;
 
 debug("==== copy_file(): dne: %u\n", dne);
-debug("==== from:'%s'  to:'%s'\n", from->p_path, to->p_path);
+debug("     from:'%s'  to:'%s'\n", from->p_path, to->p_path);
 
        if ((fr = f_open(&from_fd, from->p_path, FA_READ)) != FR_OK) {
                err(PSTR("%s: %S"), from->p_path, rctostr(fr));
@@ -621,8 +621,12 @@ debug("==== from:'%s'  to:'%s'\n", from->p_path, to->p_path);
 #if 1
 static void copy_dir(void)
 {
-       printf(PSTR("directory copy not supported, ommitting dir '%s'\n"),
+debug("==== copy_dir()");
+debug("     from:'%s'  to:'%s'\n", from->p_path, to->p_path);
+
+       printf_P(PSTR("directory copy not supported, ommitting dir '%s'\n"),
                from->p_path);
+       command_ret = CMD_RET_FAILURE;
 }
 #else
 static void copy_dir(void)
@@ -632,6 +636,9 @@ static void copy_dir(void)
        int dir_cnt, i;
        char *old_from, *old_to;
 
+debug("==== copy_file(): dne: %u\n", dne);
+debug("     from:'%s'  to:'%s'\n", from->p_path, to->p_path);
+
        dir_cnt = scandir(from->p_path, &dir_list, NULL, NULL);
        if (dir_cnt == -1) {
                (void)fprintf(stderr, "%s: can't read directory %s.\n",
@@ -712,10 +719,10 @@ static void copy()
        FRESULT fr;
 
 debug("==== copy()\n");
-debug("==== from:'%s'  to:'%s'\n", from->p_path, to->p_path);
+debug("     from:'%s'  to:'%s'\n", from->p_path, to->p_path);
 
        fr = f_stat(from->p_path, &from_stat);
-       if (fr) {
+       if (fr != FR_OK) {
                err(PSTR("%s: %S"), from->p_path, rctostr(fr));
                return;
        }
@@ -724,7 +731,7 @@ debug("==== from:'%s'  to:'%s'\n", from->p_path, to->p_path);
        if (f_stat(to->p_path, &to_stat) != FR_OK)
                dne = 1;
        else {
-               if (strcmp(to->p_path, from->p_path) !=0) {
+               if (strcmp(to->p_path, from->p_path) == 0) {
                        (void)printf_P(PSTR("%s and %s are identical (not copied).\n"),
                                        to->p_path, from->p_path);
                        command_ret = CMD_RET_FAILURE;
@@ -735,7 +742,7 @@ debug("==== from:'%s'  to:'%s'\n", from->p_path, to->p_path);
 
        if(from_stat.fattrib & AM_DIR) {
                if (!(flags & R_FLAG)) {
-                       (void)printf(PSTR("-r not specified; ommitting dir '%s'\n"),
+                       (void)printf_P(PSTR("-r not specified; ommitting dir '%s'\n"),
                            from->p_path);
                        command_ret = CMD_RET_FAILURE;
                        return;
@@ -847,12 +854,15 @@ command_ret_t do_cp(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc,
         */
 
        fr = f_stat(to->p_path, &to_stat);
-       if (fr != FR_OK && fr != FR_NO_FILE) {
-               err(PSTR("%s: %S"), to->p_path, rctostr(fr));
+debug("==== main, stat to: fr: %d, attr: %02x\n", fr, to_stat.fattrib);
+debug("     from:'%s'  to:'%s'\n", from->p_path, to->p_path);
+
+       if (fr != FR_OK && fr != FR_NO_FILE && fr != FR_NO_PATH) {
+               err(PSTR("Test1: %s: %S"), to->p_path, rctostr(fr));
                command_ret = CMD_RET_FAILURE;
                goto cleanup;
        }
-       if (fr != FR_OK || !(to_stat.fattrib & AM_DIR)) {
+       if (!(fr == FR_OK && (to_stat.fattrib & AM_DIR))) {
                /*
                 * Case (1).  Target is not a directory.
                 */
@@ -860,9 +870,10 @@ command_ret_t do_cp(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc,
                        command_ret = CMD_RET_USAGE;
                        goto cleanup;
                }
-               if (!path_set(from, *argv))
+               if (!path_set(from, *argv)) {
                        command_ret = CMD_RET_FAILURE;
                        goto cleanup;
+               }
                copy();
        }
        else {