aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2008-03-25 17:09:40 -0500
committerRob Landley <rob@landley.net>2008-03-25 17:09:40 -0500
commit5ba6663ad463973a39fd65397f9ebda52657eb7c (patch)
tree0bf04e0419d85270b2fda9c2852969ac2840b259 /toys
parent603a93d3f04e3f713c5e64d10464720018c51f29 (diff)
downloadtoybox-5ba6663ad463973a39fd65397f9ebda52657eb7c.tar.gz
Update cp -r to work better, add relevant tests to test suite.
Diffstat (limited to 'toys')
-rw-r--r--toys/cp.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/toys/cp.c b/toys/cp.c
index 0e2d04ed..13cb9672 100644
--- a/toys/cp.c
+++ b/toys/cp.c
@@ -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);