]> git.proxmox.com Git - libgit2.git/blob - tests-clay/core/rmdir.c
fileops/repository: create (most) directories with 0777 permissions
[libgit2.git] / tests-clay / core / rmdir.c
1 #include "clay_libgit2.h"
2 #include "fileops.h"
3
4 static const char *empty_tmp_dir = "test_gitfo_rmdir_recurs_test";
5
6 void test_core_rmdir__initialize(void)
7 {
8 char path[GIT_PATH_MAX];
9
10 cl_must_pass(p_mkdir(empty_tmp_dir, 0777));
11
12 git_path_join(path, empty_tmp_dir, "/one");
13 cl_must_pass(p_mkdir(path, 0777));
14
15 git_path_join(path, empty_tmp_dir, "/one/two_one");
16 cl_must_pass(p_mkdir(path, 0777));
17
18 git_path_join(path, empty_tmp_dir, "/one/two_two");
19 cl_must_pass(p_mkdir(path, 0777));
20
21 git_path_join(path, empty_tmp_dir, "/one/two_two/three");
22 cl_must_pass(p_mkdir(path, 0777));
23
24 git_path_join(path, empty_tmp_dir, "/two");
25 cl_must_pass(p_mkdir(path, 0777));
26 }
27
28 /* make sure empty dir can be deleted recusively */
29 void test_core_rmdir__delete_recursive(void)
30 {
31 cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, 0));
32 }
33
34 /* make sure non-empty dir cannot be deleted recusively */
35 void test_core_rmdir__fail_to_delete_non_empty_dir(void)
36 {
37 char file[GIT_PATH_MAX];
38 int fd;
39
40 git_path_join(file, empty_tmp_dir, "/two/file.txt");
41
42 fd = p_creat(file, 0755);
43 cl_assert(fd >= 0);
44
45 cl_must_pass(p_close(fd));
46 cl_git_fail(git_futils_rmdir_r(empty_tmp_dir, 0));
47
48 cl_must_pass(p_unlink(file));
49 cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, 0));
50 }