aboutsummaryrefslogtreecommitdiff
path: root/archival/tar.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2005-08-30 03:40:03 +0000
committerRob Landley <rob@landley.net>2005-08-30 03:40:03 +0000
commitcc8885f6f336e6901791dbb082fdc31957303f0a (patch)
tree6d68a561a005832e3ac3956ba179cedf758f5492 /archival/tar.c
parentde5598766775902ff57fafb34d512afc0ed9c303 (diff)
downloadbusybox-w32-cc8885f6f336e6901791dbb082fdc31957303f0a.tar.gz
busybox-w32-cc8885f6f336e6901791dbb082fdc31957303f0a.tar.bz2
busybox-w32-cc8885f6f336e6901791dbb082fdc31957303f0a.zip
Dirk Clemens pointed out how easy it is to support bzip2 compression, since we
shell out to an external program to handle gzip anyway...
Diffstat (limited to 'archival/tar.c')
-rw-r--r--archival/tar.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/archival/tar.c b/archival/tar.c
index b2a212397..cf972f41d 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -431,12 +431,7 @@ static inline int writeTarFile(const int tar_fd, const int verboseFlag,
431 const unsigned long dereferenceFlag, const llist_t *include, 431 const unsigned long dereferenceFlag, const llist_t *include,
432 const llist_t *exclude, const int gzip) 432 const llist_t *exclude, const int gzip)
433{ 433{
434#ifdef CONFIG_FEATURE_TAR_GZIP
435 int gzipDataPipe[2] = { -1, -1 };
436 int gzipStatusPipe[2] = { -1, -1 };
437 pid_t gzipPid = 0; 434 pid_t gzipPid = 0;
438 volatile int vfork_exec_errno = 0;
439#endif
440 435
441 int errorFlag = FALSE; 436 int errorFlag = FALSE;
442 ssize_t size; 437 ssize_t size;
@@ -453,10 +448,15 @@ static inline int writeTarFile(const int tar_fd, const int verboseFlag,
453 if (fstat(tbInfo.tarFd, &tbInfo.statBuf) < 0) 448 if (fstat(tbInfo.tarFd, &tbInfo.statBuf) < 0)
454 bb_perror_msg_and_die("Couldnt stat tar file"); 449 bb_perror_msg_and_die("Couldnt stat tar file");
455 450
456#ifdef CONFIG_FEATURE_TAR_GZIP 451 if ((ENABLE_FEATURE_TAR_GZIP || ENABLE_FEATURE_TAR_BZIP2) && gzip) {
457 if (gzip) { 452 int gzipDataPipe[2] = { -1, -1 };
453 int gzipStatusPipe[2] = { -1, -1 };
454 volatile int vfork_exec_errno = 0;
455 char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
456
457
458 if (pipe(gzipDataPipe) < 0 || pipe(gzipStatusPipe) < 0) { 458 if (pipe(gzipDataPipe) < 0 || pipe(gzipStatusPipe) < 0) {
459 bb_perror_msg_and_die("Failed to create gzip pipe"); 459 bb_perror_msg_and_die("Failed to create pipe");
460 } 460 }
461 461
462 signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */ 462 signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
@@ -479,7 +479,7 @@ static inline int writeTarFile(const int tar_fd, const int verboseFlag,
479 close(gzipStatusPipe[0]); 479 close(gzipStatusPipe[0]);
480 fcntl(gzipStatusPipe[1], F_SETFD, FD_CLOEXEC); /* close on exec shows sucess */ 480 fcntl(gzipStatusPipe[1], F_SETFD, FD_CLOEXEC); /* close on exec shows sucess */
481 481
482 execl("/bin/gzip", "gzip", "-f", 0); 482 execlp(zip_exec, zip_exec, "-f", 0);
483 vfork_exec_errno = errno; 483 vfork_exec_errno = errno;
484 484
485 close(gzipStatusPipe[1]); 485 close(gzipStatusPipe[1]);
@@ -495,7 +495,7 @@ static inline int writeTarFile(const int tar_fd, const int verboseFlag,
495 495
496 if (n == 0 && vfork_exec_errno != 0) { 496 if (n == 0 && vfork_exec_errno != 0) {
497 errno = vfork_exec_errno; 497 errno = vfork_exec_errno;
498 bb_perror_msg_and_die("Could not exec gzip process"); 498 bb_perror_msg_and_die("Could not exec %s",zip_exec);
499 } else if ((n < 0) && (errno == EAGAIN || errno == EINTR)) 499 } else if ((n < 0) && (errno == EAGAIN || errno == EINTR))
500 continue; /* try it again */ 500 continue; /* try it again */
501 break; 501 break;
@@ -507,7 +507,6 @@ static inline int writeTarFile(const int tar_fd, const int verboseFlag,
507 bb_perror_msg_and_die("Failed to vfork gzip process"); 507 bb_perror_msg_and_die("Failed to vfork gzip process");
508 } 508 }
509 } 509 }
510#endif
511 510
512 tbInfo.excludeList = exclude; 511 tbInfo.excludeList = exclude;
513 512
@@ -537,12 +536,10 @@ static inline int writeTarFile(const int tar_fd, const int verboseFlag,
537 536
538 freeHardLinkInfo(&tbInfo.hlInfoHead); 537 freeHardLinkInfo(&tbInfo.hlInfoHead);
539 538
540#ifdef CONFIG_FEATURE_TAR_GZIP 539 if (gzipPid) {
541 if (gzip && gzipPid) {
542 if (waitpid(gzipPid, NULL, 0) == -1) 540 if (waitpid(gzipPid, NULL, 0) == -1)
543 printf("Couldnt wait ?"); 541 printf("Couldnt wait ?");
544 } 542 }
545#endif
546 543
547 return !errorFlag; 544 return !errorFlag;
548} 545}
@@ -846,16 +843,16 @@ int tar_main(int argc, char **argv)
846 /* create an archive */ 843 /* create an archive */
847 if (opt & CTX_CREATE) { 844 if (opt & CTX_CREATE) {
848 int verboseFlag = FALSE; 845 int verboseFlag = FALSE;
849 int gzipFlag = FALSE; 846 int zipMode = 0;
850 847
851# ifdef CONFIG_FEATURE_TAR_GZIP 848# ifdef CONFIG_FEATURE_TAR_GZIP
852 if (get_header_ptr == get_header_tar_gz) { 849 if (get_header_ptr == get_header_tar_gz) {
853 gzipFlag = TRUE; 850 zipMode = 1;
854 } 851 }
855# endif /* CONFIG_FEATURE_TAR_GZIP */ 852# endif /* CONFIG_FEATURE_TAR_GZIP */
856# ifdef CONFIG_FEATURE_TAR_BZIP2 853# ifdef CONFIG_FEATURE_TAR_BZIP2
857 if (get_header_ptr == get_header_tar_bz2) { 854 if (get_header_ptr == get_header_tar_bz2) {
858 bb_error_msg_and_die("Creating bzip2 compressed archives is not currently supported."); 855 zipMode = 2;
859 } 856 }
860# endif /* CONFIG_FEATURE_TAR_BZIP2 */ 857# endif /* CONFIG_FEATURE_TAR_BZIP2 */
861 858
@@ -864,7 +861,7 @@ int tar_main(int argc, char **argv)
864 verboseFlag = TRUE; 861 verboseFlag = TRUE;
865 } 862 }
866 writeTarFile(tar_handle->src_fd, verboseFlag, opt & TAR_OPT_DEREFERNCE, tar_handle->accept, 863 writeTarFile(tar_handle->src_fd, verboseFlag, opt & TAR_OPT_DEREFERNCE, tar_handle->accept,
867 tar_handle->reject, gzipFlag); 864 tar_handle->reject, zipMode);
868 } else 865 } else
869#endif /* CONFIG_FEATURE_TAR_CREATE */ 866#endif /* CONFIG_FEATURE_TAR_CREATE */
870 { 867 {