]> git.saurik.com Git - apple/hfs.git/blame - tests/cases/test-deep-rm.c
hfs-366.70.1.tar.gz
[apple/hfs.git] / tests / cases / test-deep-rm.c
CommitLineData
558d2836
A
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
9TEST(deep_rm)
10
11static disk_image_t *di;
12
13static 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
27int 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}