]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Issue 774, 782: chmod() after creating a file or dir 774/head
authorGraham Percival <gperciva@tarsnap.com>
Fri, 23 Sep 2016 17:56:21 +0000 (10:56 -0700)
committerGraham Percival <gperciva@tarsnap.com>
Fri, 23 Sep 2016 17:56:21 +0000 (10:56 -0700)
If the user's system has a default umask, then
    mkdir(pathname, mode);
will report "success" even if the created dir does not match the specified
mode.  Presumably that is desired in the general case, but when it comes to
testing libarchive this can generate false errors in `make check`.

chmod() is not affected by umask, so we call that after creating the file
or directory.

Sponsored by: Tarsnap Backup Inc.

libarchive/test/main.c

index 9fa26fbf8640be1b61d88506e1851287d2141c7a..2fec9396314f68ecca3cd26f06f50c637ddcf5ad 100644 (file)
@@ -1607,8 +1607,12 @@ assertion_make_dir(const char *file, int line, const char *dirname, int mode)
        if (0 == _mkdir(dirname))
                return (1);
 #else
-       if (0 == mkdir(dirname, mode))
-               return (1);
+       if (0 == mkdir(dirname, mode)) {
+               if (0 == chmod(dirname, mode)) {
+                       assertion_file_mode(file, line, dirname, mode);
+                       return (1);
+               }
+       }
 #endif
        failure_start(file, line, "Could not create directory %s", dirname);
        failure_finish(NULL);
@@ -1657,6 +1661,11 @@ assertion_make_file(const char *file, int line,
                failure_finish(NULL);
                return (0);
        }
+       if (0 != chmod(path, mode)) {
+               failure_start(file, line, "Could not chmod %s", path);
+               failure_finish(NULL);
+               return (0);
+       }
        if (contents != NULL) {
                ssize_t wsize;
 
@@ -1673,6 +1682,7 @@ assertion_make_file(const char *file, int line,
                }
        }
        close(fd);
+       assertion_file_mode(file, line, path, mode);
        return (1);
 #endif
 }