77 . " ${MESON_SOURCE_ROOT} /test/COMMON"
88fi
99
10- BTRFS_IMAGE_MOUNTPOINT =" /tmp/rmw-loop"
11- IMAGE_PATH =" ${MESON_SOURCE_ROOT} /test/rmw-btrfs-test.img"
10+ BTRFS_MOUNTPOINT =" /tmp/rmw-loop"
11+ BTRFS_IMAGE =" ${MESON_SOURCE_ROOT} /test/rmw-btrfs-test.img"
1212
13- if [ ! -f " $IMAGE_PATH " ]; then
13+ if [ ! -f " $BTRFS_IMAGE " ]; then
1414 echo " Test image not found; skipping."
1515 exit 0
1616fi
@@ -20,63 +20,102 @@ if ! sudo -n true 2>/dev/null; then
2020 exit 0
2121fi
2222
23- if [ ! -d " $BTRFS_IMAGE_MOUNTPOINT " ]; then
24- sudo mkdir " $BTRFS_IMAGE_MOUNTPOINT "
23+ if [ ! -d " $BTRFS_MOUNTPOINT " ]; then
24+ sudo mkdir " $BTRFS_MOUNTPOINT "
2525fi
26- IS_BTRFS_MOUNTED=" $( mount | grep rmw-btrfs) " || true
27- if [ -z " $IS_BTRFS_MOUNTED " ]; then
28- sudo mount -o loop " $IMAGE_PATH " \
29- " $BTRFS_IMAGE_MOUNTPOINT "
30- sudo chown " $( id -u) " -R " $BTRFS_IMAGE_MOUNTPOINT "
26+
27+ if ! mount | grep -q rmw-btrfs; then
28+ sudo mount -o loop " $BTRFS_IMAGE " " $BTRFS_MOUNTPOINT "
29+ sudo chown " $( id -u) " -R " $BTRFS_MOUNTPOINT "
3130fi
3231
33- cd " $BTRFS_IMAGE_MOUNTPOINT "
34- RMW_TEST_CMD_STRING =" $BIN_DIR /rmw -c ${MESON_SOURCE_ROOT} /test/conf/btrfs_img.testrc"
32+ cd " $BTRFS_MOUNTPOINT "
33+ BTRFS_RMW_CMD =" $BIN_DIR /rmw -c ${MESON_SOURCE_ROOT} /test/conf/btrfs_img.testrc"
3534
36- SUBVOLUME_USED=" /tmp/rmw-loop/@two"
35+ BTRFS_SUBVOLUME=" $BTRFS_MOUNTPOINT /@two"
36+ BTRFS_WASTE_DIR=" $BTRFS_SUBVOLUME /Waste"
3737
38- WASTE_USED=" $SUBVOLUME_USED /Waste"
39- if [ -d " $WASTE_USED " ]; then
40- rm -rf " $WASTE_USED "
38+ if [ -d " $BTRFS_WASTE_DIR " ]; then
39+ rm -rf " $BTRFS_WASTE_DIR "
4140fi
4241
43- TEST_DIR=" $BTRFS_IMAGE_MOUNTPOINT /test_dir"
44- if [ -d " $TEST_DIR " ]; then
45- rm -rf " $TEST_DIR "
42+ # --- Test: move a directory with contents across btrfs subvolumes ---
43+ echo " == Test: move a directory with contents across btrfs subvolumes"
44+ BTRFS_TEST_DIR=" $BTRFS_MOUNTPOINT /test_dir"
45+ if [ -d " $BTRFS_TEST_DIR " ]; then
46+ rm -rf " $BTRFS_TEST_DIR "
4647fi
47-
48- mkdir " $TEST_DIR "
49- touch " $TEST_DIR /bar"
50- $RMW_TEST_CMD_STRING " $TEST_DIR "
51- test ! -d " $TEST_DIR "
52-
53- $RMW_TEST_CMD_STRING -u
54- test -d " $TEST_DIR "
55-
48+ mkdir " $BTRFS_TEST_DIR "
49+ touch " $BTRFS_TEST_DIR /bar"
50+ $BTRFS_RMW_CMD " $BTRFS_TEST_DIR "
51+ test ! -d " $BTRFS_TEST_DIR "
52+ test -d " $BTRFS_WASTE_DIR /files/test_dir"
53+ test -f " $BTRFS_WASTE_DIR /files/test_dir/bar"
54+ test -f " $BTRFS_WASTE_DIR /info/test_dir.trashinfo"
55+
56+ echo " == Test: restore the moved directory"
57+ $BTRFS_RMW_CMD -u
58+ test -d " $BTRFS_TEST_DIR "
59+ test -f " $BTRFS_TEST_DIR /bar"
60+ test ! -f " $BTRFS_WASTE_DIR /info/test_dir.trashinfo"
61+
62+ # --- Test: move a deeply nested directory across btrfs subvolumes ---
63+ echo " == Test: move a deeply nested directory across btrfs subvolumes"
64+ BTRFS_NESTED_DIR=" $BTRFS_MOUNTPOINT /nested_dir"
65+ if [ -d " $BTRFS_NESTED_DIR " ]; then
66+ rm -rf " $BTRFS_NESTED_DIR "
67+ fi
68+ mkdir -p " $BTRFS_NESTED_DIR /a/b/c"
69+ touch " $BTRFS_NESTED_DIR /a/b/c/deep_file"
70+ $BTRFS_RMW_CMD " $BTRFS_NESTED_DIR "
71+ test ! -d " $BTRFS_NESTED_DIR "
72+ test -d " $BTRFS_WASTE_DIR /files/nested_dir"
73+ test -f " $BTRFS_WASTE_DIR /files/nested_dir/a/b/c/deep_file"
74+ test -f " $BTRFS_WASTE_DIR /info/nested_dir.trashinfo"
75+
76+ echo " == Test: restore the nested directory"
77+ $BTRFS_RMW_CMD -u
78+ test -d " $BTRFS_NESTED_DIR /a/b/c"
79+ test -f " $BTRFS_NESTED_DIR /a/b/c/deep_file"
80+ test ! -f " $BTRFS_WASTE_DIR /info/nested_dir.trashinfo"
81+
82+ # --- Test: move a file across btrfs subvolumes ---
83+ echo " == Test: move a file across btrfs subvolumes"
5684touch foo
57- $RMW_TEST_CMD_STRING foo
58- test -f " $WASTE_USED /files/foo"
59- test -f " $WASTE_USED /info/foo.trashinfo"
85+ $BTRFS_RMW_CMD foo
86+ test -f " $BTRFS_WASTE_DIR /files/foo"
87+ test -f " $BTRFS_WASTE_DIR /info/foo.trashinfo"
6088test ! -f foo
61- $RMW_TEST_CMD_STRING -u
62- test -f foo
63-
64- RMW_FAKE_YEAR=true $RMW_TEST_CMD_STRING foo
65- test -f " $WASTE_USED /files/foo"
66- $RMW_TEST_CMD_STRING -g
67- test ! -f " $WASTE_USED /files/foo"
6889
90+ echo " == Test: restore the moved file"
91+ $BTRFS_RMW_CMD -u
92+ test -f foo
93+ test ! -f " $BTRFS_WASTE_DIR /info/foo.trashinfo"
94+
95+ # --- Test: purge an expired file from btrfs waste ---
96+ echo " == Test: purge an expired file from btrfs waste"
97+ RMW_FAKE_YEAR=true $BTRFS_RMW_CMD foo
98+ test -f " $BTRFS_WASTE_DIR /files/foo"
99+ test -f " $BTRFS_WASTE_DIR /info/foo.trashinfo"
100+ $BTRFS_RMW_CMD -g
101+ test ! -f " $BTRFS_WASTE_DIR /files/foo"
102+ test ! -f " $BTRFS_WASTE_DIR /info/foo.trashinfo"
103+
104+ # --- Test: cross-subvolume move from a non-btrfs home directory ---
105+ echo " == Test: move file from non-btrfs home to btrfs waste"
69106cd " $RMW_FAKE_HOME "
70107touch foo
71- $RMW_TEST_CMD_STRING foo -v
108+ $BTRFS_RMW_CMD foo -v
72109test ! -f foo
73- $RMW_TEST_CMD_STRING -u
110+
111+ echo " == Test: restore file to non-btrfs home from btrfs waste"
112+ $BTRFS_RMW_CMD -u
74113test -f foo
75114
76115cd
77116
78117if mount | grep -q rmw-btrfs; then
79- sudo umount " $BTRFS_IMAGE_MOUNTPOINT "
118+ sudo umount " $BTRFS_MOUNTPOINT "
80119fi
81120
82121exit 0
0 commit comments