From 38b3f516df865e2dffd0a1bbc9feb923ab2efc38 Mon Sep 17 00:00:00 2001 From: Graham Percival Date: Fri, 23 Sep 2016 10:56:21 -0700 Subject: [PATCH] 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. --- libarchive/test/main.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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 } -- 2.47.2