diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-24 14:59:45 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-24 14:59:45 +0000 |
commit | b8a8e601df9e912faa20857b4b5c07024618f7b3 (patch) | |
tree | 2dde275d11a03e45f7fe4aca444d0195c415a59c /archival | |
parent | c50f370f98e5f5d24d18ca3df444770dacce1824 (diff) | |
download | busybox-w32-b8a8e601df9e912faa20857b4b5c07024618f7b3.tar.gz busybox-w32-b8a8e601df9e912faa20857b4b5c07024618f7b3.tar.bz2 busybox-w32-b8a8e601df9e912faa20857b4b5c07024618f7b3.zip |
tar: small fixes:
* size-optimize mapping code
* kill double close
Diffstat (limited to 'archival')
-rw-r--r-- | archival/tar.c | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/archival/tar.c b/archival/tar.c index 51d34ea19..be661cc32 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -150,7 +150,9 @@ static HardLinkInfo *findHardLinkInfo(HardLinkInfo * hlInfo, struct stat *statbu | |||
150 | 150 | ||
151 | /* Put an octal string into the specified buffer. | 151 | /* Put an octal string into the specified buffer. |
152 | * The number is zero padded and possibly null terminated. | 152 | * The number is zero padded and possibly null terminated. |
153 | * Returns TRUE if successful. - DISABLED (no caller ever checked) */ | 153 | * Returns TRUE if successful. - DISABLED (no caller ever checked) */ |
154 | /* FIXME: we leave field untouched if value doesn't fit. */ | ||
155 | /* This is not good - what will happen at untar time?? */ | ||
154 | static void putOctal(char *cp, int len, long long value) | 156 | static void putOctal(char *cp, int len, long long value) |
155 | { | 157 | { |
156 | int tempLength; | 158 | int tempLength; |
@@ -205,9 +207,7 @@ static int writeTarHeader(struct TarBallInfo *tbInfo, | |||
205 | putOctal(header.mode, sizeof(header.mode), statbuf->st_mode & 07777); | 207 | putOctal(header.mode, sizeof(header.mode), statbuf->st_mode & 07777); |
206 | putOctal(header.uid, sizeof(header.uid), statbuf->st_uid); | 208 | putOctal(header.uid, sizeof(header.uid), statbuf->st_uid); |
207 | putOctal(header.gid, sizeof(header.gid), statbuf->st_gid); | 209 | putOctal(header.gid, sizeof(header.gid), statbuf->st_gid); |
208 | if (sizeof(header.size) != sizeof("00000000000")) | 210 | memset(header.size, '0', sizeof(header.size)-1); /* Regular file size is handled later */ |
209 | BUG_tar_header_size(); | ||
210 | strcpy(header.size, "00000000000"); /* Regular file size is handled later */ | ||
211 | putOctal(header.mtime, sizeof(header.mtime), statbuf->st_mtime); | 211 | putOctal(header.mtime, sizeof(header.mtime), statbuf->st_mtime); |
212 | strcpy(header.magic, "ustar "); | 212 | strcpy(header.magic, "ustar "); |
213 | 213 | ||
@@ -401,7 +401,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, | |||
401 | /* tar will be corrupted. So bail out. */ | 401 | /* tar will be corrupted. So bail out. */ |
402 | /* NB: GNU tar 1.16 warns and pads with zeroes */ | 402 | /* NB: GNU tar 1.16 warns and pads with zeroes */ |
403 | /* or even seeks back and updates header */ | 403 | /* or even seeks back and updates header */ |
404 | bb_error_msg_and_die("short read from %s", fileName); | 404 | bb_error_msg_and_die("short read from %s, aborting", fileName); |
405 | } | 405 | } |
406 | /* Check that file did not grow in between? */ | 406 | /* Check that file did not grow in between? */ |
407 | /* if (safe_read(inputFileFd,1) == 1) warn but continue? */ | 407 | /* if (safe_read(inputFileFd,1) == 1) warn but continue? */ |
@@ -461,8 +461,7 @@ static int writeTarFile(const int tar_fd, const int verboseFlag, | |||
461 | dup2(gzipDataPipe[0], 0); | 461 | dup2(gzipDataPipe[0], 0); |
462 | close(gzipDataPipe[1]); | 462 | close(gzipDataPipe[1]); |
463 | 463 | ||
464 | if (tbInfo.tarFd != 1) | 464 | dup2(tbInfo.tarFd, 1); |
465 | dup2(tbInfo.tarFd, 1); | ||
466 | 465 | ||
467 | close(gzipStatusPipe[0]); | 466 | close(gzipStatusPipe[0]); |
468 | fcntl(gzipStatusPipe[1], F_SETFD, FD_CLOEXEC); /* close on exec shows success */ | 467 | fcntl(gzipStatusPipe[1], F_SETFD, FD_CLOEXEC); /* close on exec shows success */ |
@@ -831,7 +830,7 @@ int tar_main(int argc, char **argv) | |||
831 | flags = O_RDONLY; | 830 | flags = O_RDONLY; |
832 | } | 831 | } |
833 | 832 | ||
834 | if ((tar_filename[0] == '-') && (tar_filename[1] == '\0')) { | 833 | if (tar_filename[0] == '-' && !tar_filename[1]) { |
835 | tar_handle->src_fd = fileno(tar_stream); | 834 | tar_handle->src_fd = fileno(tar_stream); |
836 | tar_handle->seek = seek_by_read; | 835 | tar_handle->seek = seek_by_read; |
837 | } else { | 836 | } else { |
@@ -860,23 +859,24 @@ int tar_main(int argc, char **argv) | |||
860 | writeTarFile(tar_handle->src_fd, verboseFlag, opt & TAR_OPT_DEREFERENCE, | 859 | writeTarFile(tar_handle->src_fd, verboseFlag, opt & TAR_OPT_DEREFERENCE, |
861 | tar_handle->accept, | 860 | tar_handle->accept, |
862 | tar_handle->reject, zipMode); | 861 | tar_handle->reject, zipMode); |
863 | } else { | 862 | /* NB: writeTarFile() closes tar_handle->src_fd */ |
864 | while (get_header_ptr(tar_handle) == EXIT_SUCCESS) | 863 | return EXIT_SUCCESS; |
865 | /* nothing */; | ||
866 | |||
867 | /* Check that every file that should have been extracted was */ | ||
868 | while (tar_handle->accept) { | ||
869 | if (!find_list_entry(tar_handle->reject, tar_handle->accept->data) | ||
870 | && !find_list_entry(tar_handle->passed, tar_handle->accept->data) | ||
871 | ) { | ||
872 | bb_error_msg_and_die("%s: not found in archive", | ||
873 | tar_handle->accept->data); | ||
874 | } | ||
875 | tar_handle->accept = tar_handle->accept->link; | ||
876 | } | ||
877 | } | 864 | } |
878 | 865 | ||
879 | if (ENABLE_FEATURE_CLEAN_UP && tar_handle->src_fd != STDIN_FILENO) | 866 | while (get_header_ptr(tar_handle) == EXIT_SUCCESS) |
867 | /* nothing */; | ||
868 | |||
869 | /* Check that every file that should have been extracted was */ | ||
870 | while (tar_handle->accept) { | ||
871 | if (!find_list_entry(tar_handle->reject, tar_handle->accept->data) | ||
872 | && !find_list_entry(tar_handle->passed, tar_handle->accept->data) | ||
873 | ) { | ||
874 | bb_error_msg_and_die("%s: not found in archive", | ||
875 | tar_handle->accept->data); | ||
876 | } | ||
877 | tar_handle->accept = tar_handle->accept->link; | ||
878 | } | ||
879 | if (ENABLE_FEATURE_CLEAN_UP /* && tar_handle->src_fd != STDIN_FILENO */) | ||
880 | close(tar_handle->src_fd); | 880 | close(tar_handle->src_fd); |
881 | 881 | ||
882 | return EXIT_SUCCESS; | 882 | return EXIT_SUCCESS; |