diff options
Diffstat (limited to 'src/fcopy/main.c')
-rw-r--r-- | src/fcopy/main.c | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/src/fcopy/main.c b/src/fcopy/main.c index 4437b90e5..82d829bba 100644 --- a/src/fcopy/main.c +++ b/src/fcopy/main.c | |||
@@ -130,10 +130,16 @@ static int fs_copydir(const char *infname, const struct stat *st, int ftype, str | |||
130 | if (size_limit_reached) | 130 | if (size_limit_reached) |
131 | return 0; | 131 | return 0; |
132 | 132 | ||
133 | |||
133 | char *outfname; | 134 | char *outfname; |
134 | if (asprintf(&outfname, "%s%s", outpath, infname + strlen(inpath)) == -1) | 135 | if (asprintf(&outfname, "%s%s", outpath, infname + strlen(inpath)) == -1) |
135 | errExit("asprintf"); | 136 | errExit("asprintf"); |
136 | 137 | ||
138 | //printf("outpaht %s\n", outpath); | ||
139 | //printf("inpath %s\n", inpath); | ||
140 | //printf("infname %s\n", infname); | ||
141 | //printf("outfname %s\n\n", outfname); | ||
142 | |||
137 | // don't copy it if we already have the file | 143 | // don't copy it if we already have the file |
138 | struct stat s; | 144 | struct stat s; |
139 | if (stat(outfname, &s) == 0) { | 145 | if (stat(outfname, &s) == 0) { |
@@ -265,7 +271,7 @@ static void duplicate_link(const char *src, const char *dest, struct stat *s) { | |||
265 | static void usage(void) { | 271 | static void usage(void) { |
266 | printf("Usage: fcopy src dest\n"); | 272 | printf("Usage: fcopy src dest\n"); |
267 | printf("Copy src file in dest directory. If src is a directory, copy all the files in\n"); | 273 | printf("Copy src file in dest directory. If src is a directory, copy all the files in\n"); |
268 | printf("src recoursively\n"); | 274 | printf("src recoursively. If the destination directory does not exist, it will be created.\n"); |
269 | } | 275 | } |
270 | 276 | ||
271 | int main(int argc, char **argv) { | 277 | int main(int argc, char **argv) { |
@@ -276,25 +282,16 @@ int i; | |||
276 | for (i = 0; i < argc; i++) | 282 | for (i = 0; i < argc; i++) |
277 | printf("*%s* ", argv[i]); | 283 | printf("*%s* ", argv[i]); |
278 | printf("\n"); | 284 | printf("\n"); |
279 | } | 285 | } |
280 | #endif | 286 | #endif |
281 | if (argc != 3) { | 287 | if (argc != 3) { |
282 | fprintf(stderr, "Error fcopy: files missing\n"); | 288 | fprintf(stderr, "Error fcopy: files missing\n"); |
283 | usage(); | 289 | usage(); |
284 | exit(1); | 290 | exit(1); |
285 | } | 291 | } |
286 | 292 | ||
287 | int i; | ||
288 | int index = 1; | ||
289 | for (i = 1; i < (argc - 2); i++) { | ||
290 | if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") ==0) { | ||
291 | usage(); | ||
292 | return 0; | ||
293 | } | ||
294 | } | ||
295 | |||
296 | // check the two files; remove ending / | 293 | // check the two files; remove ending / |
297 | char *src = argv[index]; | 294 | char *src = argv[1]; |
298 | int len = strlen(src); | 295 | int len = strlen(src); |
299 | if (src[len - 1] == '/') | 296 | if (src[len - 1] == '/') |
300 | src[len - 1] = '\0'; | 297 | src[len - 1] = '\0'; |
@@ -303,7 +300,7 @@ printf("\n"); | |||
303 | exit(1); | 300 | exit(1); |
304 | } | 301 | } |
305 | 302 | ||
306 | char *dest = argv[index + 1]; | 303 | char *dest = argv[2]; |
307 | len = strlen(dest); | 304 | len = strlen(dest); |
308 | if (dest[len - 1] == '/') | 305 | if (dest[len - 1] == '/') |
309 | dest[len - 1] = '\0'; | 306 | dest[len - 1] = '\0'; |
@@ -313,14 +310,11 @@ printf("\n"); | |||
313 | } | 310 | } |
314 | 311 | ||
315 | 312 | ||
316 | // the destination should be a directory; remove ending / | 313 | // the destination should be a directory; |
317 | struct stat s; | 314 | struct stat s; |
318 | if (stat(dest, &s) == -1) { | 315 | if (stat(dest, &s) == -1 || |
319 | fprintf(stderr, "Error fcopy: cannot find destination directory\n"); | 316 | !S_ISDIR(s.st_mode)) { |
320 | exit(1); | 317 | fprintf(stderr, "Error fcopy: invalid destination directory\n"); |
321 | } | ||
322 | if (S_ISDIR(s.st_mode) == -1) { | ||
323 | fprintf(stderr, "Error fcopy: the destination should be a directory\n"); | ||
324 | exit(1); | 318 | exit(1); |
325 | } | 319 | } |
326 | 320 | ||