aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/cp.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2013-01-31 04:13:07 -0600
committerRob Landley <rob@landley.net>2013-01-31 04:13:07 -0600
commit22791083dab2de2b22154dd4e0e593ff6c48e08b (patch)
treec70bd416c9c2fe71ffae9ce9c81549fbda6ef94f /toys/posix/cp.c
parentc26ca6e71aaa70f0aedfabfa57e7c71d0d31fe92 (diff)
downloadtoybox-22791083dab2de2b22154dd4e0e593ff6c48e08b.tar.gz
Fix -in behavior: descend into existing directory without prompting, show full path in error messages, actually overwrite when answering yes to -i.
Diffstat (limited to 'toys/posix/cp.c')
-rw-r--r--toys/posix/cp.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/toys/posix/cp.c b/toys/posix/cp.c
index 94b134aa..705c4bfb 100644
--- a/toys/posix/cp.c
+++ b/toys/posix/cp.c
@@ -85,8 +85,19 @@ int cp_node(struct dirtree *try)
// Handle -inv
- if ((flags & (FLAG_i|FLAG_n)) && !faccessat(cfd, catch, R_OK, 0))
- if ((flags & FLAG_n) || !yesno("cp: overwrite", 1)) return 0;
+ if (!faccessat(cfd, catch, F_OK, 0) && !S_ISDIR(cst.st_mode)) {
+ char *s;
+
+ if (S_ISDIR(try->st.st_dev)) {
+ error_msg("dir at '%s'", s = dirtree_path(try, 0));
+ free(s);
+ } else if (flags & FLAG_n) return 0;
+ else if (flags & FLAG_i) {
+ fprintf(stderr, "cp: overwrite '%s'", s = dirtree_path(try, 0));
+ free(s);
+ if (!yesno("", 1)) return 0;
+ }
+ }
if (flags & FLAG_v) {
char *s = dirtree_path(try, 0);
@@ -160,7 +171,7 @@ int cp_node(struct dirtree *try)
close(fdin);
}
}
- } while (err && (flags & FLAG_f) && !unlinkat(cfd, catch, 0));
+ } while (err && (flags & (FLAG_f|FLAG_n)) && !unlinkat(cfd, catch, 0));
}
if (fdout != -1) {