1 #include "clar_libgit2.h"
5 void test_core_copy__file(void)
8 const char *content
= "This is some stuff to copy\n";
10 cl_git_mkfile("copy_me", content
);
12 cl_git_pass(git_futils_cp("copy_me", "copy_me_two", 0664));
14 cl_git_pass(git_fs_path_lstat("copy_me_two", &st
));
15 cl_assert(S_ISREG(st
.st_mode
));
16 cl_assert(strlen(content
) == (size_t)st
.st_size
);
18 cl_git_pass(p_unlink("copy_me_two"));
19 cl_git_pass(p_unlink("copy_me"));
22 void test_core_copy__file_in_dir(void)
25 const char *content
= "This is some other stuff to copy\n";
27 cl_git_pass(git_futils_mkdir("an_dir/in_a_dir", 0775, GIT_MKDIR_PATH
));
28 cl_git_mkfile("an_dir/in_a_dir/copy_me", content
);
29 cl_assert(git_fs_path_isdir("an_dir"));
31 cl_git_pass(git_futils_mkpath2file
32 ("an_dir/second_dir/and_more/copy_me_two", 0775));
34 cl_git_pass(git_futils_cp
35 ("an_dir/in_a_dir/copy_me",
36 "an_dir/second_dir/and_more/copy_me_two",
39 cl_git_pass(git_fs_path_lstat("an_dir/second_dir/and_more/copy_me_two", &st
));
40 cl_assert(S_ISREG(st
.st_mode
));
41 cl_assert(strlen(content
) == (size_t)st
.st_size
);
43 cl_git_pass(git_futils_rmdir_r("an_dir", NULL
, GIT_RMDIR_REMOVE_FILES
));
44 cl_assert(!git_fs_path_isdir("an_dir"));
48 static void assert_hard_link(const char *path
)
50 /* we assert this by checking that there's more than one link to the file */
53 cl_assert(git_fs_path_isfile(path
));
54 cl_git_pass(p_stat(path
, &st
));
55 cl_assert(st
.st_nlink
> 1);
59 void test_core_copy__tree(void)
62 const char *content
= "File content\n";
64 cl_git_pass(git_futils_mkdir("src/b", 0775, GIT_MKDIR_PATH
));
65 cl_git_pass(git_futils_mkdir("src/c/d", 0775, GIT_MKDIR_PATH
));
66 cl_git_pass(git_futils_mkdir("src/c/e", 0775, GIT_MKDIR_PATH
));
68 cl_git_mkfile("src/f1", content
);
69 cl_git_mkfile("src/b/f2", content
);
70 cl_git_mkfile("src/c/f3", content
);
71 cl_git_mkfile("src/c/d/f4", content
);
72 cl_git_mkfile("src/c/d/.f5", content
);
75 cl_assert(p_symlink("../../b/f2", "src/c/d/l1") == 0);
78 cl_assert(git_fs_path_isdir("src"));
79 cl_assert(git_fs_path_isdir("src/b"));
80 cl_assert(git_fs_path_isdir("src/c/d"));
81 cl_assert(git_fs_path_isfile("src/c/d/f4"));
83 /* copy with no empty dirs, yes links, no dotfiles, no overwrite */
86 git_futils_cp_r("src", "t1", GIT_CPDIR_COPY_SYMLINKS
, 0) );
88 cl_assert(git_fs_path_isdir("t1"));
89 cl_assert(git_fs_path_isdir("t1/b"));
90 cl_assert(git_fs_path_isdir("t1/c"));
91 cl_assert(git_fs_path_isdir("t1/c/d"));
92 cl_assert(!git_fs_path_isdir("t1/c/e"));
94 cl_assert(git_fs_path_isfile("t1/f1"));
95 cl_assert(git_fs_path_isfile("t1/b/f2"));
96 cl_assert(git_fs_path_isfile("t1/c/f3"));
97 cl_assert(git_fs_path_isfile("t1/c/d/f4"));
98 cl_assert(!git_fs_path_isfile("t1/c/d/.f5"));
100 cl_git_pass(git_fs_path_lstat("t1/c/f3", &st
));
101 cl_assert(S_ISREG(st
.st_mode
));
102 cl_assert(strlen(content
) == (size_t)st
.st_size
);
105 cl_git_pass(git_fs_path_lstat("t1/c/d/l1", &st
));
106 cl_assert(S_ISLNK(st
.st_mode
));
109 cl_git_pass(git_futils_rmdir_r("t1", NULL
, GIT_RMDIR_REMOVE_FILES
));
110 cl_assert(!git_fs_path_isdir("t1"));
112 /* copy with empty dirs, no links, yes dotfiles, no overwrite */
115 git_futils_cp_r("src", "t2", GIT_CPDIR_CREATE_EMPTY_DIRS
| GIT_CPDIR_COPY_DOTFILES
, 0) );
117 cl_assert(git_fs_path_isdir("t2"));
118 cl_assert(git_fs_path_isdir("t2/b"));
119 cl_assert(git_fs_path_isdir("t2/c"));
120 cl_assert(git_fs_path_isdir("t2/c/d"));
121 cl_assert(git_fs_path_isdir("t2/c/e"));
123 cl_assert(git_fs_path_isfile("t2/f1"));
124 cl_assert(git_fs_path_isfile("t2/b/f2"));
125 cl_assert(git_fs_path_isfile("t2/c/f3"));
126 cl_assert(git_fs_path_isfile("t2/c/d/f4"));
127 cl_assert(git_fs_path_isfile("t2/c/d/.f5"));
130 cl_git_fail(git_fs_path_lstat("t2/c/d/l1", &st
));
133 cl_git_pass(git_futils_rmdir_r("t2", NULL
, GIT_RMDIR_REMOVE_FILES
));
134 cl_assert(!git_fs_path_isdir("t2"));
137 cl_git_pass(git_futils_cp_r("src", "t3", GIT_CPDIR_CREATE_EMPTY_DIRS
| GIT_CPDIR_LINK_FILES
, 0));
138 cl_assert(git_fs_path_isdir("t3"));
140 cl_assert(git_fs_path_isdir("t3"));
141 cl_assert(git_fs_path_isdir("t3/b"));
142 cl_assert(git_fs_path_isdir("t3/c"));
143 cl_assert(git_fs_path_isdir("t3/c/d"));
144 cl_assert(git_fs_path_isdir("t3/c/e"));
146 assert_hard_link("t3/f1");
147 assert_hard_link("t3/b/f2");
148 assert_hard_link("t3/c/f3");
149 assert_hard_link("t3/c/d/f4");
152 cl_git_pass(git_futils_rmdir_r("src", NULL
, GIT_RMDIR_REMOVE_FILES
));