diff options
author | hanhuihui <h30015730@china.huawei.com> | 2023-05-11 15:04:45 +0800 |
---|---|---|
committer | Philip Withnall <pwithnall@endlessos.org> | 2023-05-11 11:46:08 +0100 |
commit | e2973c9a41760df9bbf1823c748e39e48ee8a163 (patch) | |
tree | 92d262ff02629b86d691328bc09e21801da4a7e1 | |
parent | d5d5fb9b5f04eacd31ea6bb013e9dec222e6a741 (diff) | |
download | glib-e2973c9a41760df9bbf1823c748e39e48ee8a163.tar.gz |
tests: Fix assertion failures when running fileutils test as root
-rw-r--r-- | glib/tests/fileutils.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/glib/tests/fileutils.c b/glib/tests/fileutils.c index 0d6012a5f..ab5b574cc 100644 --- a/glib/tests/fileutils.c +++ b/glib/tests/fileutils.c @@ -812,6 +812,9 @@ static void test_mkdir_with_parents (void) { gchar *cwd, *new_path; +#ifndef G_OS_WIN32 + gboolean can_override_dac = check_cap_dac_override (NULL); +#endif if (g_test_verbose()) g_printerr ("checking g_mkdir_with_parents() in subdir ./hum/"); test_mkdir_with_parents_1 ("hum"); @@ -838,10 +841,20 @@ test_mkdir_with_parents (void) g_remove ("./test"); #ifndef G_OS_WIN32 - g_assert_cmpint (g_mkdir_with_parents ("/usr/b/c", 0), ==, -1); - /* EPERM or EROFS may be returned if the filesystem as a whole is read-only */ - if (errno != EPERM && errno != EROFS) - g_assert_cmpint (errno, ==, EACCES); + if (can_override_dac) + { + g_assert_cmpint (g_mkdir_with_parents ("/usr/b/c", 0), ==, 0); + g_remove ("/usr/b/c"); + g_remove ("/usr/b"); + } + else + { + g_assert_cmpint (g_mkdir_with_parents ("/usr/b/c", 0), ==, -1); + /* EPERM or EROFS may be returned if the filesystem as a whole is read-only */ + if (errno != EPERM && errno != EROFS) + g_assert_cmpint (errno, ==, EACCES); + } + #endif g_assert_cmpint (g_mkdir_with_parents (NULL, 0), ==, -1); |