summaryrefslogtreecommitdiffstats
path: root/src/test/test-mkdir.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/test-mkdir.c')
-rw-r--r--src/test/test-mkdir.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/test/test-mkdir.c b/src/test/test-mkdir.c
index 4820b32..ef00729 100644
--- a/src/test/test-mkdir.c
+++ b/src/test/test-mkdir.c
@@ -96,7 +96,7 @@ TEST(mkdir_p_root) {
assert_se(mkdtemp_malloc("/tmp/test-mkdir-XXXXXX", &tmp) >= 0);
assert_se(p = path_join(tmp, "run/aaa/bbb"));
- assert_se(mkdir_p_root(tmp, "/run/aaa/bbb", UID_INVALID, GID_INVALID, 0755, NULL) >= 0);
+ assert_se(mkdir_p_root(tmp, "/run/aaa/bbb", UID_INVALID, GID_INVALID, 0755) >= 0);
assert_se(is_dir(p, false) > 0);
assert_se(is_dir(p, true) > 0);
@@ -109,18 +109,18 @@ TEST(mkdir_p_root) {
p = mfree(p);
assert_se(p = path_join(tmp, "var/run/hoge/foo/baz"));
- assert_se(mkdir_p_root(tmp, "/var/run/hoge/foo/baz", UID_INVALID, GID_INVALID, 0755, NULL) >= 0);
+ assert_se(mkdir_p_root(tmp, "/var/run/hoge/foo/baz", UID_INVALID, GID_INVALID, 0755) >= 0);
assert_se(is_dir(p, false) > 0);
assert_se(is_dir(p, true) > 0);
p = mfree(p);
assert_se(p = path_join(tmp, "not-exists"));
- assert_se(mkdir_p_root(p, "/aaa", UID_INVALID, GID_INVALID, 0755, NULL) == -ENOENT);
+ assert_se(mkdir_p_root(p, "/aaa", UID_INVALID, GID_INVALID, 0755) == -ENOENT);
p = mfree(p);
assert_se(p = path_join(tmp, "regular-file"));
assert_se(touch(p) >= 0);
- assert_se(mkdir_p_root(p, "/aaa", UID_INVALID, GID_INVALID, 0755, NULL) == -ENOTDIR);
+ assert_se(mkdir_p_root(p, "/aaa", UID_INVALID, GID_INVALID, 0755) == -ENOTDIR);
/* FIXME: The tests below do not work.
p = mfree(p);
@@ -138,4 +138,31 @@ TEST(mkdir_p_root) {
*/
}
+TEST(mkdir_p_root_full) {
+ _cleanup_(rm_rf_physical_and_freep) char *tmp = NULL;
+ _cleanup_free_ char *p = NULL;
+ struct stat st;
+
+ ASSERT_OK(mkdtemp_malloc("/tmp/test-mkdir-XXXXXX", &tmp));
+
+ ASSERT_NOT_NULL(p = path_join(tmp, "foo"));
+ ASSERT_OK(mkdir_p_root_full(tmp, "/foo", UID_INVALID, GID_INVALID, 0755, 2 * USEC_PER_SEC, NULL));
+ ASSERT_GT(is_dir(p, false), 0);
+ ASSERT_GT(is_dir(p, true), 0);
+ ASSERT_OK_ERRNO(stat(p, &st));
+ ASSERT_EQ(st.st_mtim.tv_sec, 2);
+ ASSERT_EQ(st.st_atim.tv_sec, 2);
+
+ p = mfree(p);
+ ASSERT_NOT_NULL(p = path_join(tmp, "dir-not-exists/foo"));
+ ASSERT_OK(mkdir_p_root_full(NULL, p, UID_INVALID, GID_INVALID, 0755, 90 * USEC_PER_HOUR, NULL));
+ ASSERT_GT(is_dir(p, false), 0);
+ ASSERT_GT(is_dir(p, true), 0);
+ p = mfree(p);
+ ASSERT_NOT_NULL(p = path_join(tmp, "dir-not-exists"));
+ ASSERT_OK_ERRNO(stat(p, &st));
+ ASSERT_EQ(st.st_mtim.tv_sec, 90 * 60 * 60);
+ ASSERT_EQ(st.st_atim.tv_sec, 90 * 60 * 60);
+}
+
DEFINE_TEST_MAIN(LOG_DEBUG);