diff options
author | Rob Landley <rob@landley.net> | 2008-03-25 17:09:40 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2008-03-25 17:09:40 -0500 |
commit | 5ba6663ad463973a39fd65397f9ebda52657eb7c (patch) | |
tree | 0bf04e0419d85270b2fda9c2852969ac2840b259 /toys | |
parent | 603a93d3f04e3f713c5e64d10464720018c51f29 (diff) | |
download | toybox-5ba6663ad463973a39fd65397f9ebda52657eb7c.tar.gz |
Update cp -r to work better, add relevant tests to test suite.
Diffstat (limited to 'toys')
-rw-r--r-- | toys/cp.c | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -123,7 +123,9 @@ int cp_node(char *path, struct dirtree *node) // Find appropriate chunk of path for destination. - for (n = node;;n = n->parent) { + n = node; + if (!TT.destisdir) n = n->parent; + for (;;n = n->parent) { while (s!=path) { if (*(--s)=='/') break; } @@ -180,13 +182,14 @@ void cp_main(void) continue; } - dst = strrchr(src, '/'); - if (dst) dst++; - else dst=src; - // Copy directory or file. - if (TT.destisdir) dst = xmsprintf("%s/%s", TT.destname, dst); + if (TT.destisdir) { + dst = strrchr(src, '/'); + if (dst) dst++; + else dst=src; + dst = xmsprintf("%s/%s", TT.destname, dst); + } else dst = TT.destname; if (S_ISDIR(st.st_mode)) { if (toys.optflags & FLAG_r) { cp_file(src, dst, &st); |