Fixes with help from Stefan, Typo in prerm script, and when reinstall a package the...
[oweals/busybox.git] / archival / tar.c
index e68194ff79ef65d12589682c9a8b5c5f7e32bb4f..389d7f02e26ae1298f540ef45c20b6be5e8caefa 100644 (file)
@@ -284,6 +284,10 @@ extern int tar_main(int argc, char **argv)
                /* unzip tarFd in a seperate process */
                if (unzipFlag == TRUE) {
                        comp_file = fdopen(tarFd, "r");
+
+                       /* set the buffer size */
+                       setvbuf(comp_file, NULL, _IOFBF, 0x8000);
+
                        if ((tarFd = fileno(gz_open(comp_file, &pid))) == EXIT_FAILURE) {
                                error_msg_and_die("Couldnt unzip file");
                        }
@@ -330,7 +334,7 @@ tarExtractRegularFile(TarInfo *header, int extractFlag, int tostdoutFlag)
        size_t  writeSize;
        size_t  readSize;
        size_t  actualWriteSz;
-       char    buffer[BUFSIZ];
+       char    buffer[20 * TAR_BLOCK_SIZE];
        size_t  size = header->size;
        int outFd=fileno(stdout);
 
@@ -338,9 +342,11 @@ tarExtractRegularFile(TarInfo *header, int extractFlag, int tostdoutFlag)
        if (extractFlag==TRUE && tostdoutFlag==FALSE) {
                /* Create the path to the file, just in case it isn't there...
                 * This should not screw up path permissions or anything. */
-               char *dir = dirname (header->name);
+               char *buf, *dir;
+               buf = xstrdup (header->name);
+               dir = dirname (buf);
                make_directory (dir, -1, FILEUTILS_RECUR);
-               free (dir);
+               free (buf);
                if ((outFd=open(header->name, O_CREAT|O_TRUNC|O_WRONLY, 
                                                header->mode & ~S_IFMT)) < 0) {
                        error_msg(io_error, header->name, strerror(errno)); 
@@ -354,9 +360,9 @@ tarExtractRegularFile(TarInfo *header, int extractFlag, int tostdoutFlag)
                if ( size > sizeof(buffer) )
                        writeSize = readSize = sizeof(buffer);
                else {
-                       int mod = size % 512;
+                       int mod = size % TAR_BLOCK_SIZE;
                        if ( mod != 0 )
-                               readSize = size + (512 - mod);
+                               readSize = size + (TAR_BLOCK_SIZE - mod);
                        else
                                readSize = size;
                        writeSize = size;
@@ -399,16 +405,8 @@ tarExtractDirectory(TarInfo *header, int extractFlag, int tostdoutFlag)
        if (extractFlag==FALSE || tostdoutFlag==TRUE)
                return( TRUE);
 
-       if (make_directory(header->name, header->mode, FILEUTILS_RECUR) < 0) {
+       if (make_directory(header->name, header->mode, FILEUTILS_RECUR) < 0)
                return( FALSE);
-       }
-       /* make the final component, just in case it was
-        * omitted by create_path() (which will skip the
-        * directory if it doesn't have a terminating '/') */
-       if (mkdir(header->name, header->mode) < 0 && errno != EEXIST) {
-               perror_msg("%s", header->name);
-               return FALSE;
-       }
 
        fixUpPermissions(header);
        return( TRUE);