Do not ever change permissions on existing directories, only
authorEric Andersen <andersen@codepoet.org>
Sun, 13 May 2001 15:39:30 +0000 (15:39 -0000)
committerEric Andersen <andersen@codepoet.org>
Sun, 13 May 2001 15:39:30 +0000 (15:39 -0000)
on directories we created while extracting a tarball.  Fix
based on bug report and patch from Konstantin Boldyshev
<konst@linuxassembly.org>
 -Erik

archival/tar.c
tar.c

index 135bfd186a9d670b866aa27368e09dd76f0a0c95..6af16f4bd82cbbd9c0c9a4dc99424f737c501e30 100644 (file)
@@ -382,6 +382,7 @@ tarExtractRegularFile(TarInfo *header, int extractFlag, int tostdoutFlag)
 static int
 tarExtractDirectory(TarInfo *header, int extractFlag, int tostdoutFlag)
 {
+       int result;
 
        if (extractFlag==FALSE || tostdoutFlag==TRUE)
                return( TRUE);
@@ -393,12 +394,15 @@ tarExtractDirectory(TarInfo *header, int extractFlag, int tostdoutFlag)
        /* 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) {
+       result = mkdir(header->name, header->mode);
+       /* Don't fix permissions on pre-existing directories */
+       if (result == 0) {
+               fixUpPermissions(header);
+       } else if (result < 0 && errno != EEXIST) {
                perror_msg("%s", header->name);
                return FALSE;
        }
 
-       fixUpPermissions(header);
        return( TRUE);
 }
 
diff --git a/tar.c b/tar.c
index 135bfd186a9d670b866aa27368e09dd76f0a0c95..6af16f4bd82cbbd9c0c9a4dc99424f737c501e30 100644 (file)
--- a/tar.c
+++ b/tar.c
@@ -382,6 +382,7 @@ tarExtractRegularFile(TarInfo *header, int extractFlag, int tostdoutFlag)
 static int
 tarExtractDirectory(TarInfo *header, int extractFlag, int tostdoutFlag)
 {
+       int result;
 
        if (extractFlag==FALSE || tostdoutFlag==TRUE)
                return( TRUE);
@@ -393,12 +394,15 @@ tarExtractDirectory(TarInfo *header, int extractFlag, int tostdoutFlag)
        /* 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) {
+       result = mkdir(header->name, header->mode);
+       /* Don't fix permissions on pre-existing directories */
+       if (result == 0) {
+               fixUpPermissions(header);
+       } else if (result < 0 && errno != EEXIST) {
                perror_msg("%s", header->name);
                return FALSE;
        }
 
-       fixUpPermissions(header);
        return( TRUE);
 }