]> arthur.barton.de Git - bup.git/blob - t/test-ls.sh
TagDir._mksubs: remove duplicate FakeSymlink arg
[bup.git] / t / test-ls.sh
1 #!/usr/bin/env bash
2 . ./wvtest-bup.sh || exit $?
3
4 set -o pipefail
5
6 top="$(WVPASS pwd)" || exit $?
7 tmpdir="$(WVPASS wvmktempdir)" || exit $?
8
9 export BUP_DIR="$tmpdir/bup"
10 export GIT_DIR="$tmpdir/bup"
11
12 bup() { "$top/bup" "$@"; }
13
14 export TZ=UTC
15
16 WVPASS bup init
17 WVPASS cd "$tmpdir"
18
19 WVPASS mkdir src
20 WVPASS touch src/.dotfile src/executable
21 WVPASS mkfifo src/fifo
22 WVPASS "$top"/t/mksock src/socket
23 WVPASS bup random 1k > src/file
24 WVPASS chmod u+x src/executable
25 WVPASS chmod -R u=rwX,g-rwx,o-rwx .
26 WVPASS touch -t 196907202018 src/.dotfile src/*
27 (WVPASS cd src; WVPASS ln -s file symlink) || exit $?
28 WVPASS touch -t 196907202018 src
29 WVPASS touch -t 196907202018 .
30 WVPASS bup index src
31 WVPASS bup save -n src -d 242312160 src
32 WVPASS bup tag some-tag src
33
34
35 WVSTART "ls (short)"
36
37 WVPASSEQ "$(WVPASS bup ls /)" "src"
38
39 WVPASSEQ "$(WVPASS bup ls -A /)" ".commit
40 .tag
41 src"
42
43 WVPASSEQ "$(WVPASS bup ls -AF /)" ".commit/
44 .tag/
45 src/"
46
47 WVPASSEQ "$(WVPASS bup ls -a /)" ".
48 ..
49 .commit
50 .tag
51 src"
52
53 WVPASSEQ "$(WVPASS bup ls -aF /)" "./
54 ../
55 .commit/
56 .tag/
57 src/"
58
59 WVPASSEQ "$(WVPASS bup ls /.tag)" "some-tag"
60
61 WVPASSEQ "$(WVPASS bup ls /src)" \
62 "1977-09-05-125600
63 latest
64 some-tag"
65
66 WVPASSEQ "$(WVPASS bup ls src/latest/"$tmpdir"/src)" "executable
67 fifo
68 file
69 socket
70 symlink"
71
72 WVPASSEQ "$(WVPASS bup ls -A src/latest/"$tmpdir"/src)" ".dotfile
73 executable
74 fifo
75 file
76 socket
77 symlink"
78
79 WVPASSEQ "$(WVPASS bup ls -a src/latest/"$tmpdir"/src)" ".
80 ..
81 .dotfile
82 executable
83 fifo
84 file
85 socket
86 symlink"
87
88 WVPASSEQ "$(WVPASS bup ls -F src/latest/"$tmpdir"/src)" "executable*
89 fifo|
90 file
91 socket=
92 symlink@"
93
94 WVPASSEQ "$(WVPASS bup ls --file-type src/latest/"$tmpdir"/src)" "executable
95 fifo|
96 file
97 socket=
98 symlink@"
99
100 WVPASSEQ "$(WVPASS bup ls -d src/latest/"$tmpdir"/src)" "src/latest$tmpdir/src"
101
102
103 WVSTART "ls (long)"
104
105 WVPASSEQ "$(WVPASS bup ls -l / | tr -s ' ' ' ')" \
106 "d--------- ?/? 0 1970-01-01 00:00 src"
107
108 WVPASSEQ "$(WVPASS bup ls -lA / | tr -s ' ' ' ')" \
109 "d--------- ?/? 0 1970-01-01 00:00 .commit
110 d--------- ?/? 0 1970-01-01 00:00 .tag
111 d--------- ?/? 0 1970-01-01 00:00 src"
112
113 WVPASSEQ "$(WVPASS bup ls -lAF / | tr -s ' ' ' ')" \
114 "d--------- ?/? 0 1970-01-01 00:00 .commit/
115 d--------- ?/? 0 1970-01-01 00:00 .tag/
116 d--------- ?/? 0 1970-01-01 00:00 src/"
117
118 WVPASSEQ "$(WVPASS bup ls -la / | tr -s ' ' ' ')" \
119 "d--------- ?/? 0 1970-01-01 00:00 .
120 d--------- ?/? 0 1970-01-01 00:00 ..
121 d--------- ?/? 0 1970-01-01 00:00 .commit
122 d--------- ?/? 0 1970-01-01 00:00 .tag
123 d--------- ?/? 0 1970-01-01 00:00 src"
124
125 WVPASSEQ "$(WVPASS bup ls -laF / | tr -s ' ' ' ')" \
126 "d--------- ?/? 0 1970-01-01 00:00 ./
127 d--------- ?/? 0 1970-01-01 00:00 ../
128 d--------- ?/? 0 1970-01-01 00:00 .commit/
129 d--------- ?/? 0 1970-01-01 00:00 .tag/
130 d--------- ?/? 0 1970-01-01 00:00 src/"
131
132 symlink_mode="$(WVPASS ls -l src/symlink | cut -b -10)" || exit $?
133
134 symlink_bup_info="$(WVPASS bup ls -l src/latest"$tmpdir"/src | grep symlink)" \
135     || exit $?
136 symlink_date="$(WVPASS echo "$symlink_bup_info" \
137   | WVPASS perl -ne 'm/.*? (\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d)/ and print $2')" \
138     || exit $?
139
140 if test "$(uname -s)" != NetBSD; then
141     symlink_size="$(WVPASS python -c "import os
142 print os.lstat('src/symlink').st_size")" || exit $?
143 else
144     # NetBSD appears to return varying sizes, so for now, just ignore it.
145     symlink_size="$(WVPASS echo "$symlink_bup_info" \
146       | WVPASS perl -ne 'm/.*? (\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d)/ and print $1')" \
147         || exit $?
148 fi
149
150 uid="$(id -u)" || exit $?
151 gid="$(python -c 'import os; print os.stat("src").st_gid')" || exit $?
152 user="$(id -un)" || exit $?
153 group="$(python -c 'import grp, os;
154 print grp.getgrgid(os.stat("src").st_gid)[0]')" || exit $?
155
156 WVPASSEQ "$(bup ls -l src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
157 "-rwx------ $user/$group 0 1969-07-20 20:18 executable
158 prw------- $user/$group 0 1969-07-20 20:18 fifo
159 -rw------- $user/$group 1024 1969-07-20 20:18 file
160 srwx------ $user/$group 0 1969-07-20 20:18 socket
161 $symlink_mode $user/$group $symlink_size $symlink_date symlink -> file"
162
163 WVPASSEQ "$(bup ls -la src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
164 "drwx------ $user/$group 0 1969-07-20 20:18 .
165 drwx------ $user/$group 0 1969-07-20 20:18 ..
166 -rw------- $user/$group 0 1969-07-20 20:18 .dotfile
167 -rwx------ $user/$group 0 1969-07-20 20:18 executable
168 prw------- $user/$group 0 1969-07-20 20:18 fifo
169 -rw------- $user/$group 1024 1969-07-20 20:18 file
170 srwx------ $user/$group 0 1969-07-20 20:18 socket
171 $symlink_mode $user/$group $symlink_size $symlink_date symlink -> file"
172
173 WVPASSEQ "$(bup ls -lA src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
174 "-rw------- $user/$group 0 1969-07-20 20:18 .dotfile
175 -rwx------ $user/$group 0 1969-07-20 20:18 executable
176 prw------- $user/$group 0 1969-07-20 20:18 fifo
177 -rw------- $user/$group 1024 1969-07-20 20:18 file
178 srwx------ $user/$group 0 1969-07-20 20:18 socket
179 $symlink_mode $user/$group $symlink_size $symlink_date symlink -> file"
180
181 WVPASSEQ "$(bup ls -lF src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
182 "-rwx------ $user/$group 0 1969-07-20 20:18 executable*
183 prw------- $user/$group 0 1969-07-20 20:18 fifo|
184 -rw------- $user/$group 1024 1969-07-20 20:18 file
185 srwx------ $user/$group 0 1969-07-20 20:18 socket=
186 $symlink_mode $user/$group $symlink_size $symlink_date symlink@ -> file"
187
188 WVPASSEQ "$(bup ls -l --file-type src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
189 "-rwx------ $user/$group 0 1969-07-20 20:18 executable
190 prw------- $user/$group 0 1969-07-20 20:18 fifo|
191 -rw------- $user/$group 1024 1969-07-20 20:18 file
192 srwx------ $user/$group 0 1969-07-20 20:18 socket=
193 $symlink_mode $user/$group $symlink_size $symlink_date symlink@ -> file"
194
195 WVPASSEQ "$(bup ls -ln src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
196 "-rwx------ $uid/$gid 0 1969-07-20 20:18 executable
197 prw------- $uid/$gid 0 1969-07-20 20:18 fifo
198 -rw------- $uid/$gid 1024 1969-07-20 20:18 file
199 srwx------ $uid/$gid 0 1969-07-20 20:18 socket
200 $symlink_mode $uid/$gid $symlink_size $symlink_date symlink -> file"
201
202 WVPASSEQ "$(bup ls -ld "src/latest$tmpdir/src" | tr -s ' ' ' ')" \
203 "drwx------ $user/$group 0 1969-07-20 20:18 src/latest$tmpdir/src"
204
205
206 WVSTART "ls (backup set - long)"
207 WVPASSEQ "$(bup ls -l src | cut -d' ' -f 1-2)" \
208 "l--------- ?/?
209 l--------- ?/?
210 l--------- ?/?"
211
212
213 WVSTART "ls (dates TZ != UTC)"
214 export TZ=America/Chicago
215 symlink_date_central="$(bup ls -l src/latest"$tmpdir"/src | grep symlink)"
216 symlink_date_central="$(echo "$symlink_date_central" \
217   | perl -ne 'm/.*? (\d+) (\d\d\d\d-\d\d-\d\d \d\d:\d\d)/ and print $2')"
218 WVPASSEQ "$(bup ls -ln src/latest"$tmpdir"/src | tr -s ' ' ' ')" \
219 "-rwx------ $uid/$gid 0 1969-07-20 15:18 executable
220 prw------- $uid/$gid 0 1969-07-20 15:18 fifo
221 -rw------- $uid/$gid 1024 1969-07-20 15:18 file
222 srwx------ $uid/$gid 0 1969-07-20 15:18 socket
223 $symlink_mode $uid/$gid $symlink_size $symlink_date_central symlink -> file"
224 unset TZ
225
226
227 WVPASS rm -rf "$tmpdir"