diff options
author | Ron Yorston <rmy@pobox.com> | 2015-05-27 15:23:31 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2015-05-27 15:30:36 +0100 |
commit | 316ecf214a051121516730f794721f5e7b3036ac (patch) | |
tree | 3002051097aebc579cfe3a2e008ff43fe100c1c9 /archival/tar.c | |
parent | 8a61b67d502ed4fbd5f480ca9458884b55ce7a95 (diff) | |
download | busybox-w32-316ecf214a051121516730f794721f5e7b3036ac.tar.gz busybox-w32-316ecf214a051121516730f794721f5e7b3036ac.tar.bz2 busybox-w32-316ecf214a051121516730f794721f5e7b3036ac.zip |
Enable seamless compression for WIN32
In the archival code we pretend that WIN32 is a no-MMU platform and
use the new mingw_popen_fd routine to pipe data to/from commands
to compress/decompress.
The pretence is maintained by redefining MMU macros in bb_archive.h.
This is mostly used in the archival code but there are a handful
of places where it's used to access public interfaces. The symbol
BB_ARCHIVE_PUBLIC is defined in these places.
With these changes:
tar supports seamless compression/decompression
rpm2cpio and dpkg-deb can be enabled
Diffstat (limited to 'archival/tar.c')
-rw-r--r-- | archival/tar.c | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/archival/tar.c b/archival/tar.c index 85551684b..1f9dd23d2 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -617,6 +617,7 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb | |||
617 | } | 617 | } |
618 | 618 | ||
619 | #if SEAMLESS_COMPRESSION | 619 | #if SEAMLESS_COMPRESSION |
620 | #if !ENABLE_PLATFORM_MINGW32 | ||
620 | /* Don't inline: vfork scares gcc and pessimizes code */ | 621 | /* Don't inline: vfork scares gcc and pessimizes code */ |
621 | static void NOINLINE vfork_compressor(int tar_fd, const char *gzip) | 622 | static void NOINLINE vfork_compressor(int tar_fd, const char *gzip) |
622 | { | 623 | { |
@@ -676,6 +677,27 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip) | |||
676 | bb_perror_msg_and_die("can't execute '%s'", gzip); | 677 | bb_perror_msg_and_die("can't execute '%s'", gzip); |
677 | } | 678 | } |
678 | } | 679 | } |
680 | #else | ||
681 | static pid_t vfork_compressor(int tar_fd, const char *gzip) | ||
682 | { | ||
683 | char *cmd; | ||
684 | int fd1; | ||
685 | pid_t pid; | ||
686 | |||
687 | if (find_applet_by_name(gzip) >= 0) { | ||
688 | cmd = xasprintf("%s %s -cf -", bb_busybox_exec_path, gzip); | ||
689 | } | ||
690 | else { | ||
691 | cmd = xasprintf("%s -cf -", gzip); | ||
692 | } | ||
693 | if ( (fd1=mingw_popen_fd(cmd, "w", tar_fd, &pid)) == -1 ) { | ||
694 | bb_perror_msg_and_die("can't execute '%s'", gzip); | ||
695 | } | ||
696 | free(cmd); | ||
697 | xmove_fd(fd1, tar_fd); | ||
698 | return pid; | ||
699 | } | ||
700 | #endif /* ENABLE_PLATFORM_MINGW32 */ | ||
679 | #endif /* SEAMLESS_COMPRESSION */ | 701 | #endif /* SEAMLESS_COMPRESSION */ |
680 | 702 | ||
681 | 703 | ||
@@ -691,6 +713,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag, | |||
691 | { | 713 | { |
692 | int errorFlag = FALSE; | 714 | int errorFlag = FALSE; |
693 | struct TarBallInfo tbInfo; | 715 | struct TarBallInfo tbInfo; |
716 | IF_PLATFORM_MINGW32(pid_t pid = 0;) | ||
694 | 717 | ||
695 | tbInfo.hlInfoHead = NULL; | 718 | tbInfo.hlInfoHead = NULL; |
696 | tbInfo.tarFd = tar_fd; | 719 | tbInfo.tarFd = tar_fd; |
@@ -702,7 +725,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag, | |||
702 | 725 | ||
703 | #if SEAMLESS_COMPRESSION | 726 | #if SEAMLESS_COMPRESSION |
704 | if (gzip) | 727 | if (gzip) |
705 | vfork_compressor(tbInfo.tarFd, gzip); | 728 | IF_PLATFORM_MINGW32(pid = )vfork_compressor(tbInfo.tarFd, gzip); |
706 | #endif | 729 | #endif |
707 | 730 | ||
708 | tbInfo.excludeList = exclude; | 731 | tbInfo.excludeList = exclude; |
@@ -738,7 +761,11 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag, | |||
738 | #if SEAMLESS_COMPRESSION | 761 | #if SEAMLESS_COMPRESSION |
739 | if (gzip) { | 762 | if (gzip) { |
740 | int status; | 763 | int status; |
764 | #if !ENABLE_PLATFORM_MINGW32 | ||
741 | if (safe_waitpid(-1, &status, 0) == -1) | 765 | if (safe_waitpid(-1, &status, 0) == -1) |
766 | #else | ||
767 | if (safe_waitpid(pid, &status, 0) == -1) | ||
768 | #endif | ||
742 | bb_perror_msg("waitpid"); | 769 | bb_perror_msg("waitpid"); |
743 | else if (!WIFEXITED(status) || WEXITSTATUS(status)) | 770 | else if (!WIFEXITED(status) || WEXITSTATUS(status)) |
744 | /* gzip was killed or has exited with nonzero! */ | 771 | /* gzip was killed or has exited with nonzero! */ |
@@ -1208,10 +1235,12 @@ int tar_main(int argc UNUSED_PARAM, char **argv) | |||
1208 | if (ENABLE_FEATURE_CLEAN_UP /* && tar_handle->src_fd != STDIN_FILENO */) | 1235 | if (ENABLE_FEATURE_CLEAN_UP /* && tar_handle->src_fd != STDIN_FILENO */) |
1209 | close(tar_handle->src_fd); | 1236 | close(tar_handle->src_fd); |
1210 | 1237 | ||
1238 | #if !ENABLE_PLATFORM_MINGW32 | ||
1211 | if (SEAMLESS_COMPRESSION || OPT_COMPRESS) { | 1239 | if (SEAMLESS_COMPRESSION || OPT_COMPRESS) { |
1212 | /* Set bb_got_signal to 1 if a child died with !0 exitcode */ | 1240 | /* Set bb_got_signal to 1 if a child died with !0 exitcode */ |
1213 | check_errors_in_children(0); | 1241 | check_errors_in_children(0); |
1214 | } | 1242 | } |
1243 | #endif | ||
1215 | 1244 | ||
1216 | return bb_got_signal; | 1245 | return bb_got_signal; |
1217 | } | 1246 | } |