}
-uint8_t flags = 0;
+static uint8_t flags;
PATH_T *from;
PATH_T *to;
-#define R_FLAG (1<<0)
-#define I_FLAG (1<<1)
-#define N_FLAG (1<<2)
-#define F_FLAG (1<<3)
-#define P_FLAG (1<<4)
-#define V_FLAG (1<<5)
+#define R_FLAG (1<<0) // copy directories recursively
+#define I_FLAG (1<<1) // prompt before overwrite (overrides a previous -n option)
+#define N_FLAG (1<<2) // do not overwrite an existing file (overrides a previous -i option)
+#define F_FLAG (1<<3) // if an existing destination file cannot be opened, remove it and try again (this option is ignored when the -n option is also used)
+#define P_FLAG (1<<4) // preserve attributes and timestamps
+#define V_FLAG (1<<5) // explain what is being done
static void
setfile(FILINFO *fs, FIL *fd)
*/
if (!dne) {
if (flags & I_FLAG) {
- int checkch, ch;
-
printf_P(PSTR("overwrite %s? "), to->p_path);
- checkch = ch = getchar();
- while (ch != '\n' && ch != EOF)
- ch = getchar();
- if (checkch != 'y') {
+ if (!confirm_yes()) {
f_close(&from_fd);
return;
}
char *old_to;
+ uint8_t tflags = 0;
command_ret = CMD_RET_SUCCESS;
/* reset getopt() */
optind = 0;
int opt;
- while ((opt = getopt(argc, argv, PSTR("Rrfip"))) != -1) {
+ while ((opt = getopt(argc, argv, PSTR("rfipv"))) != -1) {
switch (opt) {
case 'f':
- flags &= I_FLAG;
+ tflags &= ~I_FLAG;
+ tflags |= F_FLAG;
break;
case 'i':
- flags |= I_FLAG;
- flags &= F_FLAG;
+ tflags &= ~F_FLAG;
+ tflags |= I_FLAG;
break;
case 'p':
- flags |= P_FLAG;
+ tflags |= P_FLAG;
break;
- case 'R':
case 'r':
- flags |= R_FLAG;
+ tflags |= R_FLAG;
break;
case 'v':
- flags |= V_FLAG;
+ tflags |= V_FLAG;
break;
default:
return CMD_RET_USAGE;
break;
}
}
+ flags = tflags;
argc -= optind;
argv += optind;
*/
fr = f_stat(to->p_path, &to_stat);
-debug("==== main, stat to: fr: %d, attr: %02x\n", fr, to_stat.fattrib);
+debug("==== main, stat to: fr: %d, attr: %02x, flags:%02x\n", fr, to_stat.fattrib, flags);
debug(" from:'%s' to:'%s'\n", from->p_path, to->p_path);
if (fr != FR_OK && fr != FR_NO_FILE && fr != FR_NO_PATH) {
CMD_TBL_ITEM(
cp, CONFIG_SYS_MAXARGS, CTBL_DBG, do_cp,
"copy files",
- "[-R] [-f | -i | -n] [-aprv] source_file target_file\n"
- " - \n"
+ "[-f | -i | -n] [-prv] source_file target_file\n"
+ "cp [-f | -i | -n] [-prv] source_file ... target_dir\n"
+ " -f overwrite existing file ignoring write protection\n"
+ " this option is ignored when the -n option is also used\n"
+ " -i prompt before overwrite (overrides a previous -n option)\n"
+ " -n do not overwrite an existing file (overrides a previous -i option)\n"
+ " -p preserve attributes and timestamps\n"
+ " -r copy directories recursively\n"
+ " -v explain what is being done\n"
),
CMD_TBL_ITEM(