static uint8_t flags;
-PATH_T from_static;
-PATH_T to_static;
-PATH_T *from = &from_static;
-PATH_T *to = &to_static;
+PATH_T from;
+PATH_T to;
+//PATH_T *from = &from_static;
+//PATH_T *to = &to_static;
static uint8_t *blockbuf;
static int blockbuf_size;
{
FRESULT fr;
- fr = f_utime(to->p_path, fs);
+ fr = f_utime(to.p_path, fs);
if (fr != FR_OK)
- err(PSTR("f_utime: %s: %S"), to->p_path, rctostr(fr));
- fr = f_chmod(to->p_path, fs->fattrib, AM_RDO|AM_ARC|AM_SYS|AM_HID);
+ err(PSTR("f_utime: %s: %S"), to.p_path, rctostr(fr));
+ fr = f_chmod(to.p_path, fs->fattrib, AM_RDO|AM_ARC|AM_SYS|AM_HID);
if (fr != FR_OK)
- err(PSTR("f_chmod: %s: %S"), to->p_path, rctostr(fr));
+ err(PSTR("f_chmod: %s: %S"), to.p_path, rctostr(fr));
}
}
debug_cp("==== copy_file(): dne: %u, blockbuf_size: %d\n", dne, blockbuf_size);
-debug_cp(" from:'%s' to:'%s'\n", from->p_path, to->p_path);
+debug_cp(" 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));
+ if ((fr = f_open(&from_fd, from.p_path, FA_READ)) != FR_OK) {
+ err(PSTR("%s: %S"), from.p_path, rctostr(fr));
return;
}
if (!dne) {
if (flags & N_FLAG) {
if (flags & V_FLAG)
- printf_P(PSTR("%s not overwritten\n"), to->p_path);
+ printf_P(PSTR("%s not overwritten\n"), to.p_path);
f_close(&from_fd);
return;
} if (flags & I_FLAG) {
- printf_P(PSTR("overwrite '%s'? "), to->p_path);
+ printf_P(PSTR("overwrite '%s'? "), to.p_path);
if (!confirm_yes()) {
f_close(&from_fd);
return;
}
if (flags & F_FLAG) {
/* Remove existing destination file name create a new file. */
- f_chmod(to->p_path,0, AM_RDO);
- f_unlink(to->p_path);
+ f_chmod(to.p_path,0, AM_RDO);
+ f_unlink(to.p_path);
open_mode = FA_WRITE|FA_CREATE_NEW;
} else {
/* Overwrite existing destination file name. */
} else {
open_mode = FA_WRITE|FA_CREATE_NEW;
}
- fr = f_open(&to_fd, to->p_path, open_mode);
+ fr = f_open(&to_fd, to.p_path, open_mode);
if (fr != FR_OK) {
- err(PSTR("%s: %S"), to->p_path, rctostr(fr));
+ err(PSTR("%s: %S"), to.p_path, rctostr(fr));
f_close(&from_fd);
return;
}
rcount > 0) {
fr = f_write(&to_fd, blockbuf, rcount, &wcount);
if (fr || wcount < rcount) {
- err(PSTR("%s: %S"), to->p_path, rctostr(fr));
+ err(PSTR("%s: %S"), to.p_path, rctostr(fr));
break;
}
}
if (fr != FR_OK)
- err(PSTR("%s: S"), from->p_path, rctostr(fr));
+ err(PSTR("%s: S"), from.p_path, rctostr(fr));
f_close(&from_fd);
if ((fr = f_close(&to_fd)) != FR_OK)
- err(PSTR("%s: %S"), to->p_path, rctostr(fr));
+ err(PSTR("%s: %S"), to.p_path, rctostr(fr));
if (flags & P_FLAG)
setfile(fs);
}
-#if 1
+static void copy();
+
+#if 0
static void copy_dir(void)
{
debug_cp("==== copy_dir()");
-debug_cp(" from:'%s' to:'%s'\n", from->p_path, to->p_path);
+debug_cp(" 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);
}
#else
static void copy_dir(void)
+{
+ DIR Dir; /* Directory object */
+ FILINFO Finfo;
+ char *old_from, *old_to;
+ FRESULT res;
+ char *pattern = {"*"};
+
+debug_cp("==== copy_dir()");
+debug_cp(" from:'%s' to:'%s'\n", from.p_path, to.p_path);
+
+
+ for (res = f_findfirst(&Dir, &Finfo, from.p_path, pattern);
+ res == FR_OK && Finfo.fname[0];
+ res = f_findfirst(&Dir, &Finfo, from.p_path, pattern)) {
+
+ if (!(Finfo.fattrib & AM_DIR) &&
+ (old_from = path_append(&from, Finfo.fname, 0))) {
+ if ((old_to = path_append(&to, Finfo.fname, 0))) {
+ copy();
+ path_restore(&to, old_to);
+ }
+ path_restore(&from, old_from);
+ }
+ }
+
+ for (res = f_findfirst(&Dir, &Finfo, from.p_path, pattern);
+ res == FR_OK && Finfo.fname[0];
+ res = f_findnext(&Dir, &Finfo)) {
+
+ if ((Finfo.fattrib & AM_DIR) &&
+ (old_from = path_append(&from, Finfo.fname, 0))) {
+ if ((old_to = path_append(&to, Finfo.fname, 0))) {
+ copy();
+ path_restore(&to, old_to);
+ }
+ path_restore(&from, old_from);
+ }
+ }
+}
+#endif
+#if 0
+static void copy_dir(void)
{
FILINFO from_stat;
struct dirent *dp, **dir_list;
char *old_from, *old_to;
debug_cp("==== copy_file(): dne: %u\n", dne);
-debug_cp(" from:'%s' to:'%s'\n", from->p_path, to->p_path);
+debug_cp(" 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) {
FRESULT fr;
debug_cp("==== copy()\n");
-debug_cp(" from:'%s' to:'%s'\n", from->p_path, to->p_path);
+debug_cp(" from:'%s' to:'%s'\n", from.p_path, to.p_path);
- fr = f_stat(from->p_path, &from_stat);
+ fr = f_stat(from.p_path, &from_stat);
if (fr != FR_OK) {
- err(PSTR("%s: %S"), from->p_path, rctostr(fr));
+ err(PSTR("%s: %S"), from.p_path, rctostr(fr));
return;
}
/* not an error, but need to remember it happened */
- if (f_stat(to->p_path, &to_stat) != FR_OK)
+ 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);
+ to.p_path, from.p_path);
command_ret = CMD_RET_FAILURE;
return;
}
if(from_stat.fattrib & AM_DIR) {
if (!(flags & R_FLAG)) {
(void)printf_P(PSTR("-r not specified; ommitting dir '%s'\n"),
- from->p_path);
+ from.p_path);
command_ret = CMD_RET_FAILURE;
return;
}
/*
* If the directory doesn't exist, create the new one.
*/
- if ((fr = f_mkdir(to->p_path)) != FR_OK) {
- err(PSTR("%s: %S"), to->p_path, rctostr(fr));
+ if ((fr = f_mkdir(to.p_path)) != FR_OK) {
+ err(PSTR("%s: %S"), to.p_path, rctostr(fr));
return;
}
}
else if (!(to_stat.fattrib & AM_DIR)) {
- (void)printf_P(PSTR("%s: not a directory.\n"), to->p_path);
+ (void)printf_P(PSTR("%s: not a directory.\n"), to.p_path);
return;
}
copy_dir();
goto cleanup;
}
#endif
- from->p_end = from->p_path; *from->p_path = '\0';
- to->p_end = to->p_path; *to->p_path = '\0';
+ from.p_end = from.p_path; from.p_path[0] = '\0';
+ to.p_end = to.p_path; to.p_path[0] = '\0';
/* last argument is destination */
- if (!path_set(to, argv[--argc]))
+ if (!path_set(&to, argv[--argc]))
goto cleanup;
/*
* In (2), the real target is not directory, but "directory/source".
*/
- fr = f_stat(to->p_path, &to_stat);
+ fr = f_stat(to.p_path, &to_stat);
debug_cp("==== main, stat to: fr: %d, attr: %02x, flags:%02x\n", fr, to_stat.fattrib, flags);
-debug_cp(" from:'%s' to:'%s'\n", from->p_path, to->p_path);
+debug_cp(" 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));
+ err(PSTR("Test1: %s: %S"), to.p_path, rctostr(fr));
command_ret = CMD_RET_FAILURE;
goto cleanup;
}
* Case (1). Target is not a directory.
*/
if (argc > 1) {
- err(PSTR("target '%s' is not a directory"), to->p_path);
+ err(PSTR("target '%s' is not a directory"), to.p_path);
//command_ret = CMD_RET_USAGE;
goto cleanup;
}
- if (!path_set(from, *argv)) {
+ if (!path_set(&from, *argv)) {
command_ret = CMD_RET_FAILURE;
goto cleanup;
}
* Case (2). Target is a directory.
*/
for (;; ++argv) {
- if (!path_set(from, *argv))
+ if (!path_set(&from, *argv))
continue;
- if (!(old_to = path_append(to, path_basename(from), -1)))
+ if (!(old_to = path_append(&to, path_basename(&from), -1)))
continue;
copy();
if (!--argc)
break;
- path_restore(to, old_to);
+ path_restore(&to, old_to);
}
}
#if 0
if (flags & V_FLAG)
- printf_P((PSTR("%s %s -> %s\n", badcp ? : "ERR:" : " ", curr->fts_path, to->p_path)));
+ printf_P((PSTR("%s %s -> %s\n", badcp ? : "ERR:" : " ", curr->fts_path, to.p_path)));
#endif