From: Graham Percival Date: Fri, 23 Sep 2016 17:56:21 +0000 (-0700) Subject: Issue 774, 782: chmod() after creating a file or dir X-Git-Tag: v3.2.2~9^2~15^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=38b3f516df865e2dffd0a1bbc9feb923ab2efc38;p=thirdparty%2Flibarchive.git Issue 774, 782: chmod() after creating a file or dir 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. --- diff --git a/libarchive/test/main.c b/libarchive/test/main.c index 9fa26fbf8..2fec93963 100644 --- a/libarchive/test/main.c +++ b/libarchive/test/main.c @@ -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 }