Remove debugging statement.
[oweals/busybox.git] / tar.c
diff --git a/tar.c b/tar.c
index 8dec4349d3f4a94892029b033856a6f2f540e03a..31443ee22aa7314d2c30922ce0363cf66864eaf4 100644 (file)
--- a/tar.c
+++ b/tar.c
@@ -151,6 +151,7 @@ extern int tar_main(int argc, char **argv)
        char** excludeList=NULL;
        char** extractList=NULL;
        const char *tarName="-";
+       const char *cwd=NULL;
 #if defined BB_FEATURE_TAR_EXCLUDE
        int excludeListSize=0;
        FILE *fileList;
@@ -181,9 +182,9 @@ extern int tar_main(int argc, char **argv)
 
        while (
 #ifndef BB_FEATURE_TAR_EXCLUDE
-                       (opt = getopt(argc, argv, "cxtzvOf:p"))
+                       (opt = getopt(argc, argv, "cxtzvOf:pC:"))
 #else
-                       (opt = getopt_long(argc, argv, "cxtzvOf:X:p", longopts, NULL))
+                       (opt = getopt_long(argc, argv, "cxtzvOf:X:pC:", longopts, NULL))
 #endif
                        > 0) {
                switch (opt) {
@@ -240,6 +241,13 @@ extern int tar_main(int argc, char **argv)
 #endif
                        case 'p':
                                break;
+                       case 'C':
+                               cwd = xgetcwd((char *)cwd);
+                               if (chdir(optarg)) {
+                                       printf("cd: %s: %s\n", optarg, strerror(errno));
+                                       return EXIT_FAILURE;
+                               }
+                               break;
                        default:
                                        show_usage();
                }
@@ -292,6 +300,8 @@ extern int tar_main(int argc, char **argv)
 #endif                 
        }
 
+       if (cwd)
+               chdir(cwd);
        if (status == TRUE)
                return EXIT_SUCCESS;
        else
@@ -320,7 +330,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);
 
@@ -328,7 +338,9 @@ 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. */
-               create_path(header->name, 0777);
+               char *dir = dirname (header->name);
+               make_directory (dir, -1, FILEUTILS_RECUR);
+               free (dir);
                if ((outFd=open(header->name, O_CREAT|O_TRUNC|O_WRONLY, 
                                                header->mode & ~S_IFMT)) < 0) {
                        error_msg(io_error, header->name, strerror(errno)); 
@@ -342,9 +354,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;
@@ -387,17 +399,8 @@ tarExtractDirectory(TarInfo *header, int extractFlag, int tostdoutFlag)
        if (extractFlag==FALSE || tostdoutFlag==TRUE)
                return( TRUE);
 
-       if (create_path(header->name, header->mode) != TRUE) {
-               perror_msg("%s: Cannot mkdir", header->name); 
+       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);