aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archival/tar.c25
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);