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.
This commit is contained in:
parent
3d1bbf0a5f
commit
e569553aa0
@ -331,6 +331,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
|
|||||||
{
|
{
|
||||||
struct TarBallInfo *tbInfo = (struct TarBallInfo *) userData;
|
struct TarBallInfo *tbInfo = (struct TarBallInfo *) userData;
|
||||||
const char *header_name;
|
const char *header_name;
|
||||||
|
int inputFileFd = -1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Check to see if we are dealing with a hard link.
|
** Check to see if we are dealing with a hard link.
|
||||||
@ -385,30 +386,32 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf,
|
|||||||
return SKIP;
|
return SKIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (writeTarHeader(tbInfo, header_name, fileName, statbuf) == FALSE) {
|
/* Is this a regular file? */
|
||||||
return (FALSE);
|
if ((tbInfo->hlInfo == NULL) && (S_ISREG(statbuf->st_mode))) {
|
||||||
}
|
|
||||||
|
|
||||||
/* Now, if the file is a regular file, copy it out to the tarball */
|
|
||||||
if ((tbInfo->hlInfo == NULL)
|
|
||||||
&& (S_ISREG(statbuf->st_mode))) {
|
|
||||||
int inputFileFd;
|
|
||||||
ssize_t readSize = 0;
|
|
||||||
|
|
||||||
/* open the file we want to archive, and make sure all is well */
|
/* open the file we want to archive, and make sure all is well */
|
||||||
if ((inputFileFd = open(fileName, O_RDONLY)) < 0) {
|
if ((inputFileFd = open(fileName, O_RDONLY)) < 0) {
|
||||||
bb_perror_msg("%s: Cannot open", fileName);
|
bb_perror_msg("%s: Cannot open", fileName);
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Add an entry to the tarball */
|
||||||
|
if (writeTarHeader(tbInfo, header_name, fileName, statbuf) == FALSE) {
|
||||||
|
return (FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If it was a regular file, write out the body */
|
||||||
|
if (inputFileFd >= 0 ) {
|
||||||
|
ssize_t readSize = 0;
|
||||||
|
|
||||||
/* write the file to the archive */
|
/* write the file to the archive */
|
||||||
readSize = bb_copyfd_eof(inputFileFd, tbInfo->tarFd);
|
readSize = bb_copyfd_eof(inputFileFd, tbInfo->tarFd);
|
||||||
|
close(inputFileFd);
|
||||||
|
|
||||||
/* Pad the file up to the tar block size */
|
/* Pad the file up to the tar block size */
|
||||||
for (; (readSize % TAR_BLOCK_SIZE) != 0; readSize++)
|
for (; (readSize % TAR_BLOCK_SIZE) != 0; readSize++)
|
||||||
write(tbInfo->tarFd, "\0", 1);
|
write(tbInfo->tarFd, "\0", 1);
|
||||||
|
|
||||||
close(inputFileFd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
|
Loading…
Reference in New Issue
Block a user