it occured to me that it's more efficient to pass around the string
itself instead of an enum, so here's patch v2.
On 09/20/2013 08:28 PM, John Spencer wrote:
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
>From 18028a5eb8f2bd1ef5cfa4844b2ebacca2ae9bb0 Mon Sep 17 00:00:00 2001
From: John Spencer <maillist-busy...@barfooze.de>
Date: Fri, 20 Sep 2013 19:28:29 +0200
Subject: [PATCH] tar: support xz compression as well
the previous patch by Boris Reisig, dfc2473b9ed88039697ac89ee2a4301cdaefcf84 ,
while adding the J flag for xz, did only add recognition of the J flag,
but did not activate usage of a compressor for xz files.
so usage of `tar cJf etc.tar.xz /etc/` resulted in a regular uncompressed
tarball.
unfortunately busybox currently does not offer xz compression support,
but this makes it at least able to use the J flag when the full xz is
installed without having to install a separate tar program.
in order to implement this effectively, some old ifdef cruft was removed,
which resulted in a 12-byte smaller tar binary when no compressor support
was enabled at all. i decided to sacrifice these 12bytes in this uncommon
usage case for readability.
---
archival/tar.c | 50 ++++++++++++++++++--------------------------------
1 files changed, 18 insertions(+), 32 deletions(-)
diff --git a/archival/tar.c b/archival/tar.c
index 3cd033b..16270bc 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -58,13 +58,6 @@
#define block_buf bb_common_bufsiz1
-#if !ENABLE_FEATURE_SEAMLESS_GZ && !ENABLE_FEATURE_SEAMLESS_BZ2
-/* Do not pass gzip flag to writeTarFile() */
-#define writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude, gzip) \
- writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude)
-#endif
-
-
#if ENABLE_FEATURE_TAR_CREATE
/*
@@ -519,21 +512,12 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
return TRUE;
}
-#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
-# if !(ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2)
-# define vfork_compressor(tar_fd, gzip) vfork_compressor(tar_fd)
-# endif
+#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 || ENABLE_FEATURE_SEAMLESS_XZ
/* Don't inline: vfork scares gcc and pessimizes code */
-static void NOINLINE vfork_compressor(int tar_fd, int gzip)
+static void NOINLINE vfork_compressor(int tar_fd, const char* zip_exec)
{
pid_t gzipPid;
-# if ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2
- const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
-# elif ENABLE_FEATURE_SEAMLESS_GZ
- const char *zip_exec = "gzip";
-# else /* only ENABLE_FEATURE_SEAMLESS_BZ2 */
- const char *zip_exec = "bzip2";
-# endif
+
// On Linux, vfork never unpauses parent early, although standard
// allows for that. Do we want to waste bytes checking for it?
# define WAIT_FOR_CHILD 0
@@ -593,13 +577,13 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip)
bb_perror_msg_and_die("can't execute '%s'", zip_exec);
}
}
-#endif /* ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 */
+#endif /* ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 || ENABLE_FEATURE_SEAMLESS_XZ */
/* gcc 4.2.1 inlines it, making code bigger */
static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
int recurseFlags, const llist_t *include,
- const llist_t *exclude, int gzip)
+ const llist_t *exclude, const char* compressor)
{
int errorFlag = FALSE;
struct TarBallInfo tbInfo;
@@ -612,9 +596,9 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
* can avoid including the tarball into itself.... */
xfstat(tbInfo.tarFd, &tbInfo.tarFileStatBuf, "can't stat tar file");
-#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
- if (gzip)
- vfork_compressor(tbInfo.tarFd, gzip);
+#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 || ENABLE_FEATURE_SEAMLESS_XZ
+ if (compressor)
+ vfork_compressor(tbInfo.tarFd, compressor);
#endif
tbInfo.excludeList = exclude;
@@ -647,13 +631,13 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
if (errorFlag)
bb_error_msg("error exit delayed from previous errors");
-#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
- if (gzip) {
+#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 || ENABLE_FEATURE_SEAMLESS_XZ
+ if (compressor) {
int status;
if (safe_waitpid(-1, &status, 0) == -1)
bb_perror_msg("waitpid");
else if (!WIFEXITED(status) || WEXITSTATUS(status))
- /* gzip was killed or has exited with nonzero! */
+ /* compressor was killed or has exited with nonzero! */
errorFlag = TRUE;
}
#endif
@@ -662,7 +646,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
#else
int writeTarFile(int tar_fd, int verboseFlag,
int recurseFlags, const llist_t *include,
- const llist_t *exclude, int gzip);
+ const llist_t *exclude, const char *compressor);
#endif /* FEATURE_TAR_CREATE */
#if ENABLE_FEATURE_TAR_FROM
@@ -1053,12 +1037,14 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
/* Create an archive */
if (opt & OPT_CREATE) {
-#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
- int zipMode = 0;
+ const char *zipMode = 0;
+#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 || ENABLE_FEATURE_SEAMLESS_XZ
if (ENABLE_FEATURE_SEAMLESS_GZ && (opt & OPT_GZIP))
- zipMode = 1;
+ zipMode = "gzip";
if (ENABLE_FEATURE_SEAMLESS_BZ2 && (opt & OPT_BZIP2))
- zipMode = 2;
+ zipMode = "bzip2";
+ if (ENABLE_FEATURE_SEAMLESS_XZ && (opt & OPT_XZ))
+ zipMode = "xz";
#endif
/* NB: writeTarFile() closes tar_handle->src_fd */
return writeTarFile(tar_handle->src_fd, verboseFlag,
--
1.7.3.4
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox