]>
Commit | Line | Data |
---|---|---|
1 | #include <unistd.h> | |
2 | #include <sys/stat.h> | |
3 | #include <spawn.h> | |
4 | ||
5 | #include "hfs-tests.h" | |
6 | #include "test-utils.h" | |
7 | #include "disk-image.h" | |
8 | ||
9 | TEST(deep_rm) | |
10 | ||
11 | static disk_image_t *di; | |
12 | ||
13 | static void rm_all(const char *path) | |
14 | { | |
15 | char *p = strdup(path); | |
16 | ||
17 | pid_t pid; | |
18 | assert_no_err(posix_spawn(&pid, "/bin/rm", NULL, NULL, | |
19 | (char *[]){ "rm", "-rf", p, NULL }, NULL)); | |
20 | ||
21 | free(p); | |
22 | ||
23 | int stat; | |
24 | assert_with_errno(waitpid(pid, &stat, 0) == pid); | |
25 | } | |
26 | ||
27 | int run_deep_rm(__unused test_ctx_t *ctx) | |
28 | { | |
29 | di = disk_image_get(); | |
30 | ||
31 | char *dir; | |
32 | asprintf(&dir, "%s/deep-rm-test", di->mount_point); | |
33 | ||
34 | rm_all(dir); | |
35 | ||
36 | assert_no_err(mkdir(dir, 0777)); | |
37 | ||
38 | char path[4096]; | |
39 | strcpy(path, dir); | |
40 | ||
41 | char *end = path + strlen(path); | |
42 | ||
43 | for (int i = 0; i < 100; ++i) { | |
44 | memcpy(end, "/dir", 5); | |
45 | assert_no_err(mkdir(path, 0777)); | |
46 | end += 4; | |
47 | } | |
48 | ||
49 | assert_no_err(chdir(path)); | |
50 | ||
51 | rm_all(dir); | |
52 | ||
53 | assert_no_err(chdir(di->mount_point)); | |
54 | free(dir); | |
55 | ||
56 | return 0; | |
57 | } |