tar: code shrink, better help text
function old new delta tar_main 994 1013 +19 packed_usage 31893 31863 -30 writeTarFile 250 207 -43 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 19/-73) Total: -54 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
02e93b3a28
commit
931cf64ae7
@ -49,7 +49,7 @@
|
||||
//config: tarballs. Currently it works only on files (not pipes etc).
|
||||
//config:
|
||||
//config:config FEATURE_TAR_FROM
|
||||
//config: bool "Enable -X (exclude from) and -T (include from) options)"
|
||||
//config: bool "Enable -X (exclude from) and -T (include from) options"
|
||||
//config: default y
|
||||
//config: depends on TAR
|
||||
//config: help
|
||||
@ -156,7 +156,9 @@ typedef struct TarBallInfo {
|
||||
int tarFd; /* Open-for-write file descriptor
|
||||
* for the tarball */
|
||||
int verboseFlag; /* Whether to print extra stuff or not */
|
||||
# if ENABLE_FEATURE_TAR_FROM
|
||||
const llist_t *excludeList; /* List of files to not include */
|
||||
# endif
|
||||
HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */
|
||||
HardLinkInfo *hlInfo; /* Hard Link Info for the current file */
|
||||
//TODO: save only st_dev + st_ino
|
||||
@ -655,44 +657,41 @@ static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
|
||||
|
||||
# if !SEAMLESS_COMPRESSION
|
||||
/* Do not pass gzip flag to writeTarFile() */
|
||||
#define writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude, gzip) \
|
||||
writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude)
|
||||
#define writeTarFile(tbInfo, recurseFlags, filelist, gzip) \
|
||||
writeTarFile(tbInfo, recurseFlags, filelist)
|
||||
# endif
|
||||
/* 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, const char *gzip)
|
||||
static NOINLINE int writeTarFile(
|
||||
struct TarBallInfo *tbInfo,
|
||||
int recurseFlags,
|
||||
const llist_t *filelist,
|
||||
const char *gzip)
|
||||
{
|
||||
int errorFlag = FALSE;
|
||||
struct TarBallInfo tbInfo;
|
||||
|
||||
tbInfo.hlInfoHead = NULL;
|
||||
tbInfo.tarFd = tar_fd;
|
||||
tbInfo.verboseFlag = verboseFlag;
|
||||
/*tbInfo->hlInfoHead = NULL; - already is */
|
||||
|
||||
/* Store the stat info for the tarball's file, so
|
||||
* can avoid including the tarball into itself.... */
|
||||
xfstat(tbInfo.tarFd, &tbInfo.tarFileStatBuf, "can't stat tar file");
|
||||
xfstat(tbInfo->tarFd, &tbInfo->tarFileStatBuf, "can't stat tar file");
|
||||
|
||||
# if SEAMLESS_COMPRESSION
|
||||
if (gzip)
|
||||
vfork_compressor(tbInfo.tarFd, gzip);
|
||||
vfork_compressor(tbInfo->tarFd, gzip);
|
||||
# endif
|
||||
|
||||
tbInfo.excludeList = exclude;
|
||||
|
||||
/* Read the directory/files and iterate over them one at a time */
|
||||
while (include) {
|
||||
if (!recursive_action(include->data, recurseFlags,
|
||||
writeFileToTarball, writeFileToTarball, &tbInfo, 0)
|
||||
while (filelist) {
|
||||
if (!recursive_action(filelist->data, recurseFlags,
|
||||
writeFileToTarball, writeFileToTarball, tbInfo, 0)
|
||||
) {
|
||||
errorFlag = TRUE;
|
||||
}
|
||||
include = include->link;
|
||||
filelist = filelist->link;
|
||||
}
|
||||
/* Write two empty blocks to the end of the archive */
|
||||
memset(block_buf, 0, 2*TAR_BLOCK_SIZE);
|
||||
xwrite(tbInfo.tarFd, block_buf, 2*TAR_BLOCK_SIZE);
|
||||
xwrite(tbInfo->tarFd, block_buf, 2*TAR_BLOCK_SIZE);
|
||||
|
||||
/* To be pedantically correct, we would check if the tarball
|
||||
* is smaller than 20 tar blocks, and pad it if it was smaller,
|
||||
@ -700,11 +699,11 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
* so is considered a waste of space */
|
||||
|
||||
/* Close so the child process (if any) will exit */
|
||||
close(tbInfo.tarFd);
|
||||
close(tbInfo->tarFd);
|
||||
|
||||
/* Hang up the tools, close up shop, head home */
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
freeHardLinkInfo(&tbInfo.hlInfoHead);
|
||||
freeHardLinkInfo(&tbInfo->hlInfoHead);
|
||||
|
||||
if (errorFlag)
|
||||
bb_error_msg("error exit delayed from previous errors");
|
||||
@ -721,18 +720,22 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
# endif
|
||||
return errorFlag;
|
||||
}
|
||||
|
||||
#else /* !FEATURE_TAR_CREATE */
|
||||
|
||||
# define writeTarFile(...) 0
|
||||
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_TAR_FROM
|
||||
static llist_t *append_file_list_to_list(llist_t *list)
|
||||
{
|
||||
FILE *src_stream;
|
||||
char *line;
|
||||
llist_t *newlist = NULL;
|
||||
|
||||
while (list) {
|
||||
FILE *src_stream;
|
||||
char *line;
|
||||
|
||||
src_stream = xfopen_stdin(llist_pop(&list));
|
||||
while ((line = xmalloc_fgetline(src_stream)) != NULL) {
|
||||
/* kill trailing '/' unless the string is just "/" */
|
||||
@ -758,7 +761,7 @@ static llist_t *append_file_list_to_list(llist_t *list)
|
||||
//usage: IF_FEATURE_TAR_NOPRESERVE_TIME("m")
|
||||
//usage: "vO] "
|
||||
//usage: "[-f TARFILE] [-C DIR] "
|
||||
//usage: IF_FEATURE_TAR_FROM("[-T FILE] [-X FILE] "IF_FEATURE_TAR_LONG_OPTIONS("[--exclude PATTERN] "))
|
||||
//usage: IF_FEATURE_TAR_FROM("[-T FILE] [-X FILE] "IF_FEATURE_TAR_LONG_OPTIONS("[--exclude PATTERN]... "))
|
||||
//usage: "[FILE]..."
|
||||
//usage:#define tar_full_usage "\n\n"
|
||||
//usage: IF_FEATURE_TAR_CREATE("Create, extract, ")
|
||||
@ -1170,13 +1173,10 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (base_dir)
|
||||
xchdir(base_dir);
|
||||
|
||||
//if (SEAMLESS_COMPRESSION)
|
||||
// /* We need to know whether child (gzip/bzip/etc) exits abnormally */
|
||||
// signal(SIGCHLD, check_errors_in_children);
|
||||
|
||||
#if ENABLE_FEATURE_TAR_CREATE
|
||||
/* Create an archive */
|
||||
if (opt & OPT_CREATE) {
|
||||
struct TarBallInfo *tbInfo;
|
||||
# if SEAMLESS_COMPRESSION
|
||||
const char *zipMode = NULL;
|
||||
if (opt & OPT_COMPRESS)
|
||||
@ -1189,13 +1189,19 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
zipMode = "lzma";
|
||||
if (opt & OPT_XZ)
|
||||
zipMode = "xz";
|
||||
# endif
|
||||
tbInfo = xzalloc(sizeof(*tbInfo));
|
||||
tbInfo->tarFd = tar_handle->src_fd;
|
||||
tbInfo->verboseFlag = verboseFlag;
|
||||
# if ENABLE_FEATURE_TAR_FROM
|
||||
tbInfo->excludeList = tar_handle->reject;
|
||||
# endif
|
||||
/* NB: writeTarFile() closes tar_handle->src_fd */
|
||||
return writeTarFile(tar_handle->src_fd, verboseFlag,
|
||||
return writeTarFile(tbInfo,
|
||||
(opt & OPT_DEREFERENCE ? ACTION_FOLLOWLINKS : 0)
|
||||
| (opt & OPT_NORECURSION ? 0 : ACTION_RECURSE),
|
||||
tar_handle->accept,
|
||||
tar_handle->reject, zipMode);
|
||||
zipMode);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user