1#! /bin/sh
2# writable.sh:  Will get over-write a writable file?
3
4# Import common functions & definitions.
5. ../../common/test-common
6
7# You cannot run the test suite as root.
8# The test suite fails if you run it as root, particularly because
9# "test -w foo" returns 0 if you are root, even if foo is a readonly
10# file. We try to avoid this by calling the "wtest" function instead
11# of just "test".
12# Please don't run the test suite as root, because it may spuriously
13# fail.
14. ../../common/not-root
15
16remove command.log log log.stdout log.stderr
17
18f=wrtest
19gfile=_g.$f
20remove s.$f
21
22# Generate empty file.
23: > $f
24
25# Create the s. file and make sure it exists.
26docommand W1 "$admin -n -i$f s.$f" 0 "" IGNORE
27
28test -r s.$f         || fail admin did not create s.$f
29remove $f
30echo foo > $f
31chmod +w $f
32
33# Try running get when gfile was writable -- it should fail.
34docommand W2 "${vg_get} s.$f" 1 IGNORE IGNORE
35remove $gfile
36test -f $gfile	    && miscarry could not remove _g.$f
37
38# Now run get with the -G option and it should work even
39# though the file's usual name is occupied by a writable file.
40docommand W3 "${vg_get} -G$gfile s.$f" 0 "1.1\n0 lines\n" IGNORE
41
42
43# If you specify the "-k" option, the gotten file should be read-write.
44# If you don't specify -k or -e, it will be read-only.  -e implies -k.
45remove $gfile $f
46docommand W4 "${vg_get} s.$f" 0 "1.1\n0 lines\n" IGNORE
47
48# Make sure the file is read only.
49echo_nonl "W5..."
50#if test -w $f
51if wtest -w $f
52then
53    fail W5: "get s.$f created writable $f"
54fi
55echo passed
56
57
58
59# Now do the same again, using the -k option.
60remove $gfile $f
61docommand W6 "${vg_get} -k s.$f" 0 "1.1\n0 lines\n" IGNORE
62
63# Make sure the file is read only.
64echo_nonl "W7..."
65#if test -w $f
66if wtest -w $f
67then
68    true
69else
70    fail W5: "get -k s.$f created read-only $f.  It should be writable"
71fi
72echo passed
73
74
75
76
77
78remove $f s.$f $gfile
79remove command.log
80success
81