mirror of
https://github.com/sheumann/hush.git
synced 2025-01-27 06:34:03 +00:00
Dirk Clemens pointed out how easy it is to support bzip2 compression, since we
shell out to an external program to handle gzip anyway...
This commit is contained in:
parent
de55987667
commit
cc8885f6f3
@ -431,12 +431,7 @@ static inline int writeTarFile(const int tar_fd, const int verboseFlag,
|
|||||||
const unsigned long dereferenceFlag, const llist_t *include,
|
const unsigned long dereferenceFlag, const llist_t *include,
|
||||||
const llist_t *exclude, const int gzip)
|
const llist_t *exclude, const int gzip)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_FEATURE_TAR_GZIP
|
|
||||||
int gzipDataPipe[2] = { -1, -1 };
|
|
||||||
int gzipStatusPipe[2] = { -1, -1 };
|
|
||||||
pid_t gzipPid = 0;
|
pid_t gzipPid = 0;
|
||||||
volatile int vfork_exec_errno = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int errorFlag = FALSE;
|
int errorFlag = FALSE;
|
||||||
ssize_t size;
|
ssize_t size;
|
||||||
@ -453,10 +448,15 @@ static inline int writeTarFile(const int tar_fd, const int verboseFlag,
|
|||||||
if (fstat(tbInfo.tarFd, &tbInfo.statBuf) < 0)
|
if (fstat(tbInfo.tarFd, &tbInfo.statBuf) < 0)
|
||||||
bb_perror_msg_and_die("Couldnt stat tar file");
|
bb_perror_msg_and_die("Couldnt stat tar file");
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_TAR_GZIP
|
if ((ENABLE_FEATURE_TAR_GZIP || ENABLE_FEATURE_TAR_BZIP2) && gzip) {
|
||||||
if (gzip) {
|
int gzipDataPipe[2] = { -1, -1 };
|
||||||
|
int gzipStatusPipe[2] = { -1, -1 };
|
||||||
|
volatile int vfork_exec_errno = 0;
|
||||||
|
char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
|
||||||
|
|
||||||
|
|
||||||
if (pipe(gzipDataPipe) < 0 || pipe(gzipStatusPipe) < 0) {
|
if (pipe(gzipDataPipe) < 0 || pipe(gzipStatusPipe) < 0) {
|
||||||
bb_perror_msg_and_die("Failed to create gzip pipe");
|
bb_perror_msg_and_die("Failed to create pipe");
|
||||||
}
|
}
|
||||||
|
|
||||||
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
|
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,
|
|||||||
close(gzipStatusPipe[0]);
|
close(gzipStatusPipe[0]);
|
||||||
fcntl(gzipStatusPipe[1], F_SETFD, FD_CLOEXEC); /* close on exec shows sucess */
|
fcntl(gzipStatusPipe[1], F_SETFD, FD_CLOEXEC); /* close on exec shows sucess */
|
||||||
|
|
||||||
execl("/bin/gzip", "gzip", "-f", 0);
|
execlp(zip_exec, zip_exec, "-f", 0);
|
||||||
vfork_exec_errno = errno;
|
vfork_exec_errno = errno;
|
||||||
|
|
||||||
close(gzipStatusPipe[1]);
|
close(gzipStatusPipe[1]);
|
||||||
@ -495,7 +495,7 @@ static inline int writeTarFile(const int tar_fd, const int verboseFlag,
|
|||||||
|
|
||||||
if (n == 0 && vfork_exec_errno != 0) {
|
if (n == 0 && vfork_exec_errno != 0) {
|
||||||
errno = vfork_exec_errno;
|
errno = vfork_exec_errno;
|
||||||
bb_perror_msg_and_die("Could not exec gzip process");
|
bb_perror_msg_and_die("Could not exec %s",zip_exec);
|
||||||
} else if ((n < 0) && (errno == EAGAIN || errno == EINTR))
|
} else if ((n < 0) && (errno == EAGAIN || errno == EINTR))
|
||||||
continue; /* try it again */
|
continue; /* try it again */
|
||||||
break;
|
break;
|
||||||
@ -507,7 +507,6 @@ static inline int writeTarFile(const int tar_fd, const int verboseFlag,
|
|||||||
bb_perror_msg_and_die("Failed to vfork gzip process");
|
bb_perror_msg_and_die("Failed to vfork gzip process");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
tbInfo.excludeList = exclude;
|
tbInfo.excludeList = exclude;
|
||||||
|
|
||||||
@ -537,12 +536,10 @@ static inline int writeTarFile(const int tar_fd, const int verboseFlag,
|
|||||||
|
|
||||||
freeHardLinkInfo(&tbInfo.hlInfoHead);
|
freeHardLinkInfo(&tbInfo.hlInfoHead);
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_TAR_GZIP
|
if (gzipPid) {
|
||||||
if (gzip && gzipPid) {
|
|
||||||
if (waitpid(gzipPid, NULL, 0) == -1)
|
if (waitpid(gzipPid, NULL, 0) == -1)
|
||||||
printf("Couldnt wait ?");
|
printf("Couldnt wait ?");
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
return !errorFlag;
|
return !errorFlag;
|
||||||
}
|
}
|
||||||
@ -846,16 +843,16 @@ int tar_main(int argc, char **argv)
|
|||||||
/* create an archive */
|
/* create an archive */
|
||||||
if (opt & CTX_CREATE) {
|
if (opt & CTX_CREATE) {
|
||||||
int verboseFlag = FALSE;
|
int verboseFlag = FALSE;
|
||||||
int gzipFlag = FALSE;
|
int zipMode = 0;
|
||||||
|
|
||||||
# ifdef CONFIG_FEATURE_TAR_GZIP
|
# ifdef CONFIG_FEATURE_TAR_GZIP
|
||||||
if (get_header_ptr == get_header_tar_gz) {
|
if (get_header_ptr == get_header_tar_gz) {
|
||||||
gzipFlag = TRUE;
|
zipMode = 1;
|
||||||
}
|
}
|
||||||
# endif /* CONFIG_FEATURE_TAR_GZIP */
|
# endif /* CONFIG_FEATURE_TAR_GZIP */
|
||||||
# ifdef CONFIG_FEATURE_TAR_BZIP2
|
# ifdef CONFIG_FEATURE_TAR_BZIP2
|
||||||
if (get_header_ptr == get_header_tar_bz2) {
|
if (get_header_ptr == get_header_tar_bz2) {
|
||||||
bb_error_msg_and_die("Creating bzip2 compressed archives is not currently supported.");
|
zipMode = 2;
|
||||||
}
|
}
|
||||||
# endif /* CONFIG_FEATURE_TAR_BZIP2 */
|
# endif /* CONFIG_FEATURE_TAR_BZIP2 */
|
||||||
|
|
||||||
@ -864,7 +861,7 @@ int tar_main(int argc, char **argv)
|
|||||||
verboseFlag = TRUE;
|
verboseFlag = TRUE;
|
||||||
}
|
}
|
||||||
writeTarFile(tar_handle->src_fd, verboseFlag, opt & TAR_OPT_DEREFERNCE, tar_handle->accept,
|
writeTarFile(tar_handle->src_fd, verboseFlag, opt & TAR_OPT_DEREFERNCE, tar_handle->accept,
|
||||||
tar_handle->reject, gzipFlag);
|
tar_handle->reject, zipMode);
|
||||||
} else
|
} else
|
||||||
#endif /* CONFIG_FEATURE_TAR_CREATE */
|
#endif /* CONFIG_FEATURE_TAR_CREATE */
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user