diff options
author | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-01-09 03:07:44 +0000 |
---|---|---|
committer | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-01-09 03:07:44 +0000 |
commit | 9560356705cbf00afd76aadb9c7e49d63e5fb642 (patch) | |
tree | 213b2aaeea588afe1e1116f01803524765232538 | |
parent | 1c4720283c0c1fd2dd9d3328481084d9f792c44b (diff) | |
download | busybox-w32-9560356705cbf00afd76aadb9c7e49d63e5fb642.tar.gz busybox-w32-9560356705cbf00afd76aadb9c7e49d63e5fb642.tar.bz2 busybox-w32-9560356705cbf00afd76aadb9c7e49d63e5fb642.zip |
Bug 547: writing out the tar file header before we confirm we can actually
open and read from the file isn't something we can recover from after the
fact. Resequence things to check first, write second.
git-svn-id: svn://busybox.net/trunk/busybox@13189 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | archival/tar.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/archival/tar.c b/archival/tar.c index cd89a7566..d5fa954d2 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -331,6 +331,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, | |||
331 | { | 331 | { |
332 | struct TarBallInfo *tbInfo = (struct TarBallInfo *) userData; | 332 | struct TarBallInfo *tbInfo = (struct TarBallInfo *) userData; |
333 | const char *header_name; | 333 | const char *header_name; |
334 | int inputFileFd = -1; | ||
334 | 335 | ||
335 | /* | 336 | /* |
336 | ** Check to see if we are dealing with a hard link. | 337 | ** Check to see if we are dealing with a hard link. |
@@ -385,30 +386,32 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, | |||
385 | return SKIP; | 386 | return SKIP; |
386 | } | 387 | } |
387 | 388 | ||
388 | if (writeTarHeader(tbInfo, header_name, fileName, statbuf) == FALSE) { | 389 | /* Is this a regular file? */ |
389 | return (FALSE); | 390 | if ((tbInfo->hlInfo == NULL) && (S_ISREG(statbuf->st_mode))) { |
390 | } | ||
391 | |||
392 | /* Now, if the file is a regular file, copy it out to the tarball */ | ||
393 | if ((tbInfo->hlInfo == NULL) | ||
394 | && (S_ISREG(statbuf->st_mode))) { | ||
395 | int inputFileFd; | ||
396 | ssize_t readSize = 0; | ||
397 | 391 | ||
398 | /* open the file we want to archive, and make sure all is well */ | 392 | /* open the file we want to archive, and make sure all is well */ |
399 | if ((inputFileFd = open(fileName, O_RDONLY)) < 0) { | 393 | if ((inputFileFd = open(fileName, O_RDONLY)) < 0) { |
400 | bb_perror_msg("%s: Cannot open", fileName); | 394 | bb_perror_msg("%s: Cannot open", fileName); |
401 | return (FALSE); | 395 | return (FALSE); |
402 | } | 396 | } |
397 | } | ||
398 | |||
399 | /* Add an entry to the tarball */ | ||
400 | if (writeTarHeader(tbInfo, header_name, fileName, statbuf) == FALSE) { | ||
401 | return (FALSE); | ||
402 | } | ||
403 | |||
404 | /* If it was a regular file, write out the body */ | ||
405 | if (inputFileFd >= 0 ) { | ||
406 | ssize_t readSize = 0; | ||
403 | 407 | ||
404 | /* write the file to the archive */ | 408 | /* write the file to the archive */ |
405 | readSize = bb_copyfd_eof(inputFileFd, tbInfo->tarFd); | 409 | readSize = bb_copyfd_eof(inputFileFd, tbInfo->tarFd); |
410 | close(inputFileFd); | ||
406 | 411 | ||
407 | /* Pad the file up to the tar block size */ | 412 | /* Pad the file up to the tar block size */ |
408 | for (; (readSize % TAR_BLOCK_SIZE) != 0; readSize++) | 413 | for (; (readSize % TAR_BLOCK_SIZE) != 0; readSize++) |
409 | write(tbInfo->tarFd, "\0", 1); | 414 | write(tbInfo->tarFd, "\0", 1); |
410 | |||
411 | close(inputFileFd); | ||
412 | } | 415 | } |
413 | 416 | ||
414 | return (TRUE); | 417 | return (TRUE); |