aboutsummaryrefslogtreecommitdiffstats
path: root/src/fcopy
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@yahoo.com>2016-11-16 16:40:12 -0500
committerLibravatar netblue30 <netblue30@yahoo.com>2016-11-16 16:40:12 -0500
commit98159c098b6afedfed20eecdc80719dae1f914ff (patch)
treed44407914904e81dcb4bd582bdae11e558705c3d /src/fcopy
parentfcopy part 1 (diff)
downloadfirejail-98159c098b6afedfed20eecdc80719dae1f914ff.tar.gz
firejail-98159c098b6afedfed20eecdc80719dae1f914ff.tar.zst
firejail-98159c098b6afedfed20eecdc80719dae1f914ff.zip
fcopy part 2
Diffstat (limited to 'src/fcopy')
-rw-r--r--src/fcopy/main.c36
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) {
265static void usage(void) { 271static 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
271int main(int argc, char **argv) { 277int main(int argc, char **argv) {
@@ -276,25 +282,16 @@ int i;
276for (i = 0; i < argc; i++) 282for (i = 0; i < argc; i++)
277 printf("*%s* ", argv[i]); 283 printf("*%s* ", argv[i]);
278printf("\n"); 284printf("\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