|
3 | 3 | # Path should be relative |
4 | 4 | # |
5 | 5 | #https://specifications.freedesktop.org/trash-spec/1.0/#id-1.6.10.1 The key |
6 | | -#“Path” contains the original location of the file/directory, as either an |
7 | | -#absolute pathname (starting with the slash character “/”) or a relative |
| 6 | +#"Path" contains the original location of the file/directory, as either an |
| 7 | +#absolute pathname (starting with the slash character "/") or a relative |
8 | 8 | #pathname (starting with any other character). A relative pathname is to be |
9 | 9 | #from the directory in which the trash directory resides (for example, from |
10 | | -#$XDG_DATA_HOME for the “home trash” directory); it MUST not include a “..” |
11 | | -#directory, and for files not “under” that directory, absolute pathnames must |
12 | | -#be used. The system SHOULD support absolute pathnames only in the “home trash” |
| 10 | +#$XDG_DATA_HOME for the "home trash" directory); it MUST not include a ".." |
| 11 | +#directory, and for files not "under" that directory, absolute pathnames must |
| 12 | +#be used. The system SHOULD support absolute pathnames only in the "home trash" |
13 | 13 | #directory, not in the directories under $topdir. |
14 | 14 |
|
15 | 15 | set -ve |
|
20 | 20 | . "${MESON_SOURCE_ROOT}/test/COMMON" |
21 | 21 | fi |
22 | 22 |
|
23 | | -# This test will only work on Andy's workstation. |
24 | | -# The media root, /home/andy/src is on a different partition than /home/andy |
25 | | -# It's mounted with 'bind' and therefore has a different device id |
26 | | -test ! -d /mnt/918375c2 && exit 0; |
| 23 | +# This test needs a file and waste folder on the same device, but a different |
| 24 | +# device than $HOME. Check whether /tmp qualifies. |
| 25 | +tmp_dev=$(stat -c %d /tmp 2>/dev/null || stat -f %d /tmp 2>/dev/null || echo "") |
| 26 | +home_dev=$(stat -c %d "$RMW_FAKE_HOME" 2>/dev/null || stat -f %d "$RMW_FAKE_HOME" 2>/dev/null || echo "") |
27 | 27 |
|
28 | | -# This test use Andy's regular config, outside of the test sandbox, so don't |
29 | | -# run it if the epoch test setup is being used. Otherwise all the waste dirs |
30 | | -# will be purged. |
31 | | -test -n "$RMW_TEST_EPOCHALYPSE" && exit 0; |
32 | | -echo "hello" |
| 28 | +if [ -z "$tmp_dev" ] || [ "$tmp_dev" = "$home_dev" ]; then |
| 29 | + echo "/tmp is on the same device as home, or stat is unavailable; skipping" |
| 30 | + exit 0 |
| 31 | +fi |
33 | 32 |
|
| 33 | +# /tmp is on a different device — use it as the simulated media root. |
| 34 | +TRASH_DIR="/tmp/.Trash-$(id -u)" |
| 35 | +TEST_DIR="/tmp/rmw-media-root-test" |
34 | 36 | test_file="media_root_test" |
35 | | -PREV_RMW_FAKE_HOME=${RMW_FAKE_HOME} |
36 | | -# needs to be unset so rmw will use $HOME instead |
37 | | -unset RMW_FAKE_HOME |
38 | | -mkdir -p "$PREV_RMW_FAKE_HOME" |
39 | | -test_file_path=${PREV_RMW_FAKE_HOME}/$test_file |
40 | | -if test -f "$test_file_path"; then |
41 | | - rm "$test_file_path" |
42 | | -fi |
43 | | -if test -f /home/andy/src/rmw-project/.Trash-1000/files/$test_file; then |
44 | | - rm /home/andy/src/rmw-project/.Trash-1000/files/$test_file |
45 | | -fi |
46 | | -if test -f /home/andy/src/rmw-project/.Trash-1000/info/$test_file.trashinfo; then |
47 | | - rm /home/andy/src/rmw-project/.Trash-1000/info/$test_file.trashinfo |
48 | | -fi |
| 37 | +test_file_path="$TEST_DIR/$test_file" |
| 38 | + |
| 39 | +# Clean up any leftovers from a previous run |
| 40 | +rm -rf "$TRASH_DIR" "$TEST_DIR" |
| 41 | + |
| 42 | +# Create test config pointing the waste folder to /tmp |
| 43 | +mkdir -p "$RMW_FAKE_HOME" |
| 44 | +TEST_CONFIG="$RMW_FAKE_HOME/media-root.testrc" |
| 45 | +printf 'WASTE = /tmp/.Trash-%s, removable\nexpire_age = 90\n' "$(id -u)" > "$TEST_CONFIG" |
| 46 | + |
| 47 | +# Create waste dir manually (required because it is marked removable) |
| 48 | +mkdir -p "$TRASH_DIR/files" "$TRASH_DIR/info" |
| 49 | +mkdir -p "$TEST_DIR" |
| 50 | + |
49 | 51 | touch "$test_file_path" |
50 | | -"$BIN_DIR"/rmw -c /home/andy/.config/rmwrc "$test_file_path" |
| 52 | +"$BIN_DIR"/rmw -c "$TEST_CONFIG" "$test_file_path" |
51 | 53 |
|
52 | | -output=$(grep Path /home/andy/src/rmw-project/.Trash-1000/info/$test_file.trashinfo) |
| 54 | +test -f "$TRASH_DIR/info/$test_file.trashinfo" |
| 55 | +test -f "$TRASH_DIR/files/$test_file" |
| 56 | +test ! -f "$test_file_path" |
53 | 57 |
|
54 | | -# There should be no leading '/' in the filename. |
55 | | -path_expected=$(echo "${MESON_BUILD_ROOT}" | sed -e "s/\/home\/andy\/src\/rmw-project\///g") |
56 | | -echo "$path_expected" |
57 | | -test "$output" = "Path=${path_expected}/test/rmw-tests-home/test_media_root.sh_dir/media_root_test" |
| 58 | +# The Path must be relative (no leading '/') since the waste folder is at |
| 59 | +# the topdir of /tmp's partition. |
| 60 | +output=$(grep '^Path=' "$TRASH_DIR/info/$test_file.trashinfo") |
| 61 | +echo "trashinfo: $output" |
| 62 | +case "$output" in |
| 63 | + Path=/*) |
| 64 | + echo "FAIL: Path is absolute, expected relative" |
| 65 | + exit 1 |
| 66 | + ;; |
| 67 | + Path=*) |
| 68 | + echo "PASS: Path is relative" |
| 69 | + ;; |
| 70 | + *) |
| 71 | + echo "FAIL: Path line not found" |
| 72 | + exit 1 |
| 73 | + ;; |
| 74 | +esac |
58 | 75 |
|
59 | | -output=$("$BIN_DIR"/rmw -uvv -c /home/andy/.config/rmwrc | grep media_root_test) |
| 76 | +# Restore and verify |
| 77 | +"$BIN_DIR"/rmw -uvv -c "$TEST_CONFIG" |
| 78 | +test -f "$test_file_path" |
| 79 | +test ! -f "$TRASH_DIR/info/$test_file.trashinfo" |
60 | 80 |
|
61 | | -test "$output" = "+'/home/andy/src/rmw-project/.Trash-1000/files/media_root_test' -> '${MESON_BUILD_ROOT}/test/rmw-tests-home/test_media_root.sh_dir/media_root_test' |
62 | | --/home/andy/src/rmw-project/.Trash-1000/info/media_root_test.trashinfo" |
| 81 | +# Cleanup |
| 82 | +rm -f "$TEST_CONFIG" |
| 83 | +rm -rf "$TRASH_DIR" "$TEST_DIR" |
63 | 84 |
|
64 | 85 | exit 0 |
0 commit comments