aboutsummaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
Diffstat (limited to 'archival')
-rw-r--r--archival/cpio.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/archival/cpio.c b/archival/cpio.c
index be9fbd0b5..5eb393d57 100644
--- a/archival/cpio.c
+++ b/archival/cpio.c
@@ -298,6 +298,10 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
298 ; 298 ;
299#endif 299#endif
300 300
301 archive_handle = init_handle();
302 /* archive_handle->src_fd = STDIN_FILENO; - done by init_handle */
303 archive_handle->ah_flags = ARCHIVE_EXTRACT_NEWER;
304
301 /* As of now we do not enforce this: */ 305 /* As of now we do not enforce this: */
302 /* -i,-t,-o,-p are mutually exclusive */ 306 /* -i,-t,-o,-p are mutually exclusive */
303 /* -u,-d,-m make sense only with -i or -p */ 307 /* -u,-d,-m make sense only with -i or -p */
@@ -307,11 +311,17 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
307 /* no parameters */ 311 /* no parameters */
308 opt_complementary = "=0"; 312 opt_complementary = "=0";
309 opt = getopt32(argv, OPTION_STR, &cpio_filename); 313 opt = getopt32(argv, OPTION_STR, &cpio_filename);
314 if (opt & CPIO_OPT_FILE) { /* -F */
315 archive_handle->src_fd = xopen(cpio_filename, O_RDONLY);
316 }
310#else 317#else
311 /* _exactly_ one parameter for -p, thus <= 1 param if -p is allowed */ 318 /* _exactly_ one parameter for -p, thus <= 1 param if -p is allowed */
312 opt_complementary = ENABLE_FEATURE_CPIO_P ? "?1" : "=0"; 319 opt_complementary = ENABLE_FEATURE_CPIO_P ? "?1" : "=0";
313 opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt); 320 opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt);
314 argv += optind; 321 argv += optind;
322 if ((opt & (CPIO_OPT_FILE|CPIO_OPT_CREATE)) == CPIO_OPT_FILE) { /* -F without -o */
323 xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
324 }
315 if (opt & CPIO_OPT_PASSTHROUGH) { 325 if (opt & CPIO_OPT_PASSTHROUGH) {
316 pid_t pid; 326 pid_t pid;
317 struct fd_pair pp; 327 struct fd_pair pp;
@@ -367,11 +377,6 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
367 skip: 377 skip:
368#endif 378#endif
369 379
370 archive_handle = init_handle();
371 /* archive_handle->src_fd = STDIN_FILENO; - done by init_handle */
372 archive_handle->seek = seek_by_read;
373 archive_handle->ah_flags = ARCHIVE_EXTRACT_NEWER;
374
375 /* One of either extract or test options must be given */ 380 /* One of either extract or test options must be given */
376 if ((opt & (CPIO_OPT_TEST | CPIO_OPT_EXTRACT)) == 0) { 381 if ((opt & (CPIO_OPT_TEST | CPIO_OPT_EXTRACT)) == 0) {
377 bb_show_usage(); 382 bb_show_usage();
@@ -398,10 +403,6 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
398 archive_handle->action_header = header_list; 403 archive_handle->action_header = header_list;
399 } 404 }
400 } 405 }
401 if (opt & CPIO_OPT_FILE) { /* -F */
402 archive_handle->src_fd = xopen(cpio_filename, O_RDONLY);
403 archive_handle->seek = seek_by_jump;
404 }
405 if (opt & CPIO_OPT_CREATE_LEADING_DIR) { 406 if (opt & CPIO_OPT_CREATE_LEADING_DIR) {
406 archive_handle->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS; 407 archive_handle->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS;
407 } 408 }
@@ -422,8 +423,9 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
422 423
423 if (archive_handle->cpio__blocks != (off_t)-1 424 if (archive_handle->cpio__blocks != (off_t)-1
424 && !(opt & CPIO_OPT_QUIET) 425 && !(opt & CPIO_OPT_QUIET)
425 ) 426 ) {
426 printf("%"OFF_FMT"u blocks\n", archive_handle->cpio__blocks); 427 printf("%"OFF_FMT"u blocks\n", archive_handle->cpio__blocks);
428 }
427 429
428 return EXIT_SUCCESS; 430 return EXIT_SUCCESS;
429} 431}