@@ -30,30 +30,36 @@ for n in $files ; do
3030done
3131dbgecho passed the happy path
3232
33- # now try to make a hardlink to somewhere that fails.
34- # ideally, we want to partitions so it is not possible to hardlink,
35- # but it is difficult to fix that unless the test environment
36- # is setup that way. therefore, make the hardlinking fail by
37- # trying to hardlink something we do not have access to.
38- # unless run as root which would be horrible.
39- if [ " $( id -u) " -eq 0 ]; then
40- dbgecho " running as root or through sudo, dangerous! Will not proceed with this unit tests."
41- exit 1
42- fi
33+ # try to make a hardlink to somewhere that fails.
4334
4435reset_teststate
45- system_file=$( which ls)
46- cp $system_file .
47- $rdfind -makehardlinks true . $system_file 2>&1 | tee rdfind.out
36+ mkdir -p $datadir /readonly.d/
37+ echo xxx > $datadir /readonly.d/a
38+ echo xxx > $datadir /readonly.d/b
39+ chmod 500 $datadir /readonly.d/
40+
41+ if [ " $( id -u) " -eq 0 ]; then
42+ # if running as root, directory rights are not respected. drop the capability
43+ # for doing that (requires capsh from package libcap2-bin)
44+ MAYBEDROP=" capsh --drop=CAP_DAC_OVERRIDE -- -c"
45+ else
46+ MAYBEDROP=" /bin/sh -c"
47+ fi
48+ $MAYBEDROP " $rdfind -makehardlinks true $datadir /readonly.d/" 2>&1 | tee rdfind.out
4849if ! grep -iq " failed" rdfind.out ; then
49- dbgecho " expected failure when trying to make hardlink on system partition "
50+ dbgecho " expected failure when trying to make hardlink on readonly directory "
5051 exit 1
5152fi
5253
5354# make sure that our own copy is still there
54- if [ ! -e $( basename $system_file ) ] ; then
55- dbgecho file is missing, rdfind should not have removed it!
56- exit 1
57- fi
55+ for f in a b ; do
56+ if [ ! -e $datadir /readonly.d/$f ] ; then
57+ dbgecho file $f is missing, rdfind should not have removed it!
58+ exit 1
59+ fi
60+ done
61+
62+ # make sure it can be cleaned up
63+ chmod 700 $datadir /readonly.d/
5864
5965dbgecho " all is good in this test!"
0 commit comments