@@ -11,13 +11,15 @@ test_description="test how the unix files api interacts with the gc"
11
11
test_init_ipfs
12
12
13
13
test_expect_success " object not removed after gc" '
14
- echo "hello world" | ipfs files write --create /hello.txt &&
14
+ echo "hello world" > hello.txt &&
15
+ cat hello.txt | ipfs files write --create /hello.txt &&
15
16
ipfs repo gc &&
16
17
ipfs cat QmVib14uvPnCP73XaCDpwugRuwfTsVbGyWbatHAmLSdZUS
17
18
'
18
19
19
20
test_expect_success " /hello.txt still accessible after gc" '
20
- ipfs files read /hello.txt
21
+ ipfs files read /hello.txt > hello-actual &&
22
+ test_cmp hello.txt hello-actual
21
23
'
22
24
23
25
ADIR_HASH=QmbCgoMYVuZq8m1vK31JQx9DorwQdLMF1M3sJ7kygLLqnW
@@ -27,7 +29,6 @@ test_expect_success "gc okay after adding incomplete node -- prep" '
27
29
ipfs files mkdir /adir &&
28
30
echo "file1" | ipfs files write --create /adir/file1 &&
29
31
echo "file2" | ipfs files write --create /adir/file2 &&
30
- ipfs cat $FILE1_HASH &&
31
32
ipfs pin add --recursive=false $ADIR_HASH &&
32
33
ipfs files rm -r /adir &&
33
34
ipfs repo gc && # will remove /adir/file1 and /adir/file2 but not /adir
@@ -42,4 +43,34 @@ test_expect_success "gc okay after adding incomplete node" '
42
43
ipfs refs $ADIR_HASH
43
44
'
44
45
46
+ test_expect_success " add directory with direct pin" '
47
+ mkdir mydir/ &&
48
+ echo "hello world!" > mydir/hello.txt &&
49
+ FILE_UNPINNED=$(ipfs add --pin=false -q -r mydir/hello.txt) &&
50
+ DIR_PINNED=$(ipfs add --pin=false -q -r mydir | tail -n1) &&
51
+ ipfs add --pin=false -r mydir &&
52
+ ipfs pin add --recursive=false $DIR_PINNED &&
53
+ ipfs cat $FILE_UNPINNED
54
+ '
55
+
56
+ test_expect_success " run gc and make sure directory contents are removed" '
57
+ ipfs repo gc &&
58
+ test_must_fail ipfs cat $FILE_UNPINNED
59
+ '
60
+
61
+ test_expect_success " add incomplete directory and make sure gc is okay" '
62
+ ipfs files cp /ipfs/$DIR_PINNED /mydir &&
63
+ ipfs repo gc &&
64
+ test_must_fail ipfs cat $FILE_UNPINNED
65
+ '
66
+
67
+ test_expect_success " add back directory contents and run gc" '
68
+ ipfs add --pin=false mydir/hello.txt &&
69
+ ipfs repo gc
70
+ '
71
+
72
+ test_expect_success " make sure directory contents are not removed" '
73
+ ipfs cat $FILE_UNPINNED
74
+ '
75
+
45
76
test_done
0 commit comments