diff options
author | Rob Landley <rob@landley.net> | 2014-09-01 12:47:32 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2014-09-01 12:47:32 -0500 |
commit | c164960f468ffae19b080b264f6e9960e0eb1027 (patch) | |
tree | 6b95206cea0ac581862feeaddf0346accf1524e2 /toys/posix/cp.c | |
parent | 658887a48c11b0933c74dd399b8fe5feaf0aa018 (diff) | |
download | toybox-c164960f468ffae19b080b264f6e9960e0eb1027.tar.gz |
Add cp -F to force delete of existing destination files, and make install command use that.
-F is equivalent to the gnu/dammit flag --we-think-long-options-without-short-options-are-a-good-idea
Diffstat (limited to 'toys/posix/cp.c')
-rw-r--r-- | toys/posix/cp.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/toys/posix/cp.c b/toys/posix/cp.c index c61190e5..d79819b2 100644 --- a/toys/posix/cp.c +++ b/toys/posix/cp.c @@ -7,8 +7,8 @@ // This is subtle: MV options must be in same order (right to left) as CP // for FLAG_X macros to work out right. -USE_CP(NEWTOY(cp, "<2RHLPp"USE_CP_MORE("rdaslvn")"fi[-HLPd]"USE_CP_MORE("[-ni]"), TOYFLAG_BIN)) -USE_CP_MV(OLDTOY(mv, cp, "<2"USE_CP_MORE("vn")"fi"USE_CP_MORE("[-ni]"), TOYFLAG_BIN)) +USE_CP(NEWTOY(cp, "<2RHLPp"USE_CP_MORE("rdaslvnF")"fi[-HLPd]"USE_CP_MORE("[-ni]"), TOYFLAG_BIN)) +USE_CP_MV(OLDTOY(mv, cp, "<2"USE_CP_MORE("vnF")"fi"USE_CP_MORE("[-ni]"), TOYFLAG_BIN)) USE_INSTALL(NEWTOY(install, "<1cdDpsvm:o:g:", TOYFLAG_USR|TOYFLAG_BIN)) * @@ -21,7 +21,8 @@ config CP Copy files from SOURCE to DEST. If more than one SOURCE, DEST must be a directory. - -f force copy by deleting destination file + -f delete destination files we can't write to + -F delete any existing destination file first (breaks hardlinks) -i interactive, prompt before overwriting existing DEST -p preserve timestamps, ownership, and permissions -R recurse into subdirectories (DEST must be a directory) @@ -142,6 +143,9 @@ int cp_node(struct dirtree *try) error_msg("dir at '%s'", s = dirtree_path(try, 0)); free(s); return 0; + } else if ((flags & FLAG_F) && unlinkat(cfd, catch, 0)) { + error_msg("unlink '%s'", catch); + return 0; } else if (flags & FLAG_n) return 0; else if (flags & FLAG_i) { fprintf(stderr, "cp: overwrite '%s'", s = dirtree_path(try, 0)); @@ -365,7 +369,7 @@ void install_main(void) if (toys.optc < 2) error_exit("needs 2 args"); // Translate flags from install to cp - toys.optflags = 4; // Force cp's FLAG_n + toys.optflags = 4; // Force cp's FLAG_F if (flags & FLAG_v) toys.optflags |= 8; // cp's FLAG_v if (flags & (FLAG_p|FLAG_o|FLAG_g)) toys.optflags |= 512; // cp's FLAG_p |