Mercurial > hg > toybox
changeset 798:16bcabb8cf97
Fix -in behavior: descend into existing directory without prompting, show full path in error messages, actually overwrite when answering yes to -i.
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 31 Jan 2013 04:13:07 -0600 |
parents | 36b43eafab38 |
children | 6b8cc11d517c |
files | lib/lib.c toys/posix/cp.c |
diffstat | 2 files changed, 15 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/lib.c Thu Jan 31 04:05:56 2013 -0600 +++ b/lib/lib.c Thu Jan 31 04:13:07 2013 -0600 @@ -975,6 +975,7 @@ while (fread(&buf, 1, 1, stdin)) { int new; + // The letter changes the value, the newline (or space) returns it. if (isspace(buf)) break; if (-1 != (new = stridx("ny", tolower(buf)))) def = new; }
--- a/toys/posix/cp.c Thu Jan 31 04:05:56 2013 -0600 +++ b/toys/posix/cp.c Thu Jan 31 04:13:07 2013 -0600 @@ -85,8 +85,19 @@ // 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 @@ 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) {