Mercurial > hg > toybox
comparison toys/cp.c @ 271:7d625cbdde25
Update cp -r to work better, add relevant tests to test suite.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 25 Mar 2008 17:09:40 -0500 |
parents | 7b3d9594bf9c |
children | a5652aa22f38 |
comparison
equal
deleted
inserted
replaced
270:e9f75ffd3200 | 271:7d625cbdde25 |
---|---|
121 char *s = path+strlen(path); | 121 char *s = path+strlen(path); |
122 struct dirtree *n; | 122 struct dirtree *n; |
123 | 123 |
124 // Find appropriate chunk of path for destination. | 124 // Find appropriate chunk of path for destination. |
125 | 125 |
126 for (n = node;;n = n->parent) { | 126 n = node; |
127 if (!TT.destisdir) n = n->parent; | |
128 for (;;n = n->parent) { | |
127 while (s!=path) { | 129 while (s!=path) { |
128 if (*(--s)=='/') break; | 130 if (*(--s)=='/') break; |
129 } | 131 } |
130 if (!n) break; | 132 if (!n) break; |
131 } | 133 } |
178 perror_msg("'%s'", src); | 180 perror_msg("'%s'", src); |
179 toys.exitval = 1; | 181 toys.exitval = 1; |
180 continue; | 182 continue; |
181 } | 183 } |
182 | 184 |
183 dst = strrchr(src, '/'); | |
184 if (dst) dst++; | |
185 else dst=src; | |
186 | |
187 // Copy directory or file. | 185 // Copy directory or file. |
188 | 186 |
189 if (TT.destisdir) dst = xmsprintf("%s/%s", TT.destname, dst); | 187 if (TT.destisdir) { |
188 dst = strrchr(src, '/'); | |
189 if (dst) dst++; | |
190 else dst=src; | |
191 dst = xmsprintf("%s/%s", TT.destname, dst); | |
192 } else dst = TT.destname; | |
190 if (S_ISDIR(st.st_mode)) { | 193 if (S_ISDIR(st.st_mode)) { |
191 if (toys.optflags & FLAG_r) { | 194 if (toys.optflags & FLAG_r) { |
192 cp_file(src, dst, &st); | 195 cp_file(src, dst, &st); |
193 | 196 |
194 TT.keep_symlinks++; | 197 TT.keep_symlinks++; |