From e2973c9a41760df9bbf1823c748e39e48ee8a163 Mon Sep 17 00:00:00 2001 From: hanhuihui Date: Thu, 11 May 2023 15:04:45 +0800 Subject: tests: Fix assertion failures when running fileutils test as root --- glib/tests/fileutils.c | 21 +++++++++++++++++---- 1 file 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); -- cgit v1.2.1