]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix file flag setting on linux in the event that EXT2_IOC_GETFLAGS fails
authorColin Percival <cperciva@daemonology.net>
Tue, 16 Aug 2011 18:00:20 +0000 (14:00 -0400)
committerColin Percival <cperciva@daemonology.net>
Tue, 16 Aug 2011 18:00:20 +0000 (14:00 -0400)
the first time we call it and then succeeds a few lines later; prior to
this commit this peculiar scenario would result in 'newflags' being used
uninitialized.

While I'm here, fix spelling ("implicity" -> "implicitly", "occured" ->
"occurred", "SECURE_SYMLINK" -> "SECURE_SYMLINKS"), grammar ("is a
unusable"), and writespace.

Via: Tarsnap

SVN-Revision: 3627

libarchive/archive_write_disk_posix.c

index 69562246519b662ea922d66649b36d2c2b402f94..db375a4725472042f6af21b2ef95f33cc0d6abd3 100644 (file)
@@ -242,7 +242,7 @@ struct archive_write_disk {
 
 /*
  * Default mode for dirs created automatically (will be modified by umask).
- * Note that POSIX specifies 0777 for implicity-created dirs, "modified
+ * Note that POSIX specifies 0777 for implicitly-created dirs, "modified
  * by the process' file creation mask."
  */
 #define        DEFAULT_DIR_MODE 0777
@@ -315,7 +315,7 @@ lazy_stat(struct archive_write_disk *a)
 #endif
        /*
         * XXX At this point, symlinks should not be hit, otherwise
-        * XXX a race occured.  Do we want to check explicitly for that?
+        * XXX a race occurred.  Do we want to check explicitly for that?
         */
        if (lstat(a->name, &a->st) == 0) {
                a->pst = &a->st;
@@ -692,7 +692,7 @@ write_data_block(struct archive_write_disk *a, const char *buff, size_t size)
                                return (ARCHIVE_FATAL);
                        }
                        a->fd_offset = a->offset;
-               }
+               }
                bytes_written = write(a->fd, buff, bytes_to_write);
                if (bytes_written < 0) {
                        archive_set_error(&a->archive, errno, "Write failed");
@@ -1087,7 +1087,7 @@ restore_entry(struct archive_write_disk *a)
                 */
                int r = 0;
                /*
-                * The SECURE_SYMLINK logic has already removed a
+                * The SECURE_SYMLINKS logic has already removed a
                 * symlink to a dir if the client wants that.  So
                 * follow the symlink if we're creating a dir.
                 */
@@ -1634,7 +1634,7 @@ cleanup_pathname_win(struct archive_write_disk *a)
                        mb = 1;
                else
                        mb = 0;
-               /* Rewrite the path name if its character is a unusable. */
+               /* Rewrite the path name if its next character is unusable. */
                if (*p == ':' || *p == '*' || *p == '?' || *p == '"' ||
                    *p == '<' || *p == '>' || *p == '|')
                        *p = '_';
@@ -2399,22 +2399,25 @@ set_fflags_platform(struct archive_write_disk *a, int fd, const char *name,
         * to read the current flags from disk. XXX
         */
        ret = ARCHIVE_OK;
+
+       /* Read the current file flags. */
+       if (ioctl(myfd, EXT2_IOC_GETFLAGS, &oldflags) < 0)
+               goto fail;
+
        /* Try setting the flags as given. */
-       if (ioctl(myfd, EXT2_IOC_GETFLAGS, &oldflags) >= 0) {
-               newflags = (oldflags & ~clear) | set;
-               if (ioctl(myfd, EXT2_IOC_SETFLAGS, &newflags) >= 0)
-                       goto cleanup;
-               if (errno != EPERM)
-                       goto fail;
-       }
+       newflags = (oldflags & ~clear) | set;
+       if (ioctl(myfd, EXT2_IOC_SETFLAGS, &newflags) >= 0)
+               goto cleanup;
+       if (errno != EPERM)
+               goto fail;
+
        /* If we couldn't set all the flags, try again with a subset. */
-       if (ioctl(myfd, EXT2_IOC_GETFLAGS, &oldflags) >= 0) {
-               newflags &= ~sf_mask;
-               oldflags &= sf_mask;
-               newflags |= oldflags;
-               if (ioctl(myfd, EXT2_IOC_SETFLAGS, &newflags) >= 0)
-                       goto cleanup;
-       }
+       newflags &= ~sf_mask;
+       oldflags &= sf_mask;
+       newflags |= oldflags;
+       if (ioctl(myfd, EXT2_IOC_SETFLAGS, &newflags) >= 0)
+               goto cleanup;
+
        /* We couldn't set the flags, so report the failure. */
 fail:
        archive_set_error(&a->archive, errno,