File: updatedb.at

package info (click to toggle)
mlocate 0.26-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,116 kB
  • sloc: ansic: 10,201; sh: 9,895; makefile: 80; sed: 16
file content (325 lines) | stat: -rw-r--r-- 6,092 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# Copyright (C) 2006 Red Hat, Inc. All rights reserved.
# This copyrighted material is made available to anyone wishing to use, modify,
# copy, or redistribute it subject to the terms and conditions of the GNU
# General Public License v.2.

# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.

# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

# Author: Miloslav Trmac <mitr@redhat.com>

AT_SETUP([updatedb: File types])
AT_KEYWORDS([updatedb])

mkdir d
touch d/file
mkdir d/dir
touch d/dir/subfile
mkfifo d/fifo
ln -s file d/symlink
ln -s nonexistent d/danglink
touch d/hardlink1
ln d/hardlink1 d/hardlink2
echo | dd > d/largefile bs=1024 seek=5000000

AT_CHECK([updatedb -U "$(pwd)/d" -o db -l 0])

AT_CHECK([locate -d db / | sed "s,^$(pwd)/,,"], ,
[d
d/danglink
d/dir
d/fifo
d/file
d/hardlink1
d/hardlink2
d/largefile
d/symlink
d/dir/subfile
])

AT_CLEANUP


AT_SETUP([updatedb: Output sorting])
AT_KEYWORDS([updatedb])

# '.', '/' left out
[
  allchars='! " # $ % & '\'' ( ) * + , - 0 9 : ; < = > ?'	     # emacs: "
  allchars="$allchars"' @ A Z [ \ ] ^ _ ` a z { | } ~'
]

mkdir d
echo 'd' > subdirs
> subdir_files
set -f
for dir in $allchars; do
  mkdir "d/$dir"
  echo "d/$dir" >> subdirs
  for file in $allchars; do
    touch "d/$dir/$file"
    echo "d/$dir/$file" >> subdir_files
  done
done
set +f

AT_CHECK([updatedb -U "$(pwd)/d" -o db -l 0])

AT_CHECK([updatedb -U "$(pwd)/d" -o db -l 0])

cat subdirs subdir_files > expout
AT_CHECK([locate -d db / | sed "s,^$(pwd)/,,"], , [expout])

AT_CLEANUP


AT_SETUP([updatedb: Permissions])
AT_KEYWORDS([updatedb])

AT_XFAIL_IF([test "x`id -u`" = x0])

perms='000 100 200 300 400 500 600 700'

mkdir d
for perm in $perms; do
  mkdir -p "d/d$perm" "d/d$perm/d"
  touch "d/f$perm" "d/d$perm/d/f"
  chmod "$perm" "d/f$perm" "d/d$perm"
done

AT_CHECK([updatedb -U "$(pwd)/d" -o db -l 0])

AT_CHECK([locate -d db / | sed "s,^$(pwd)/,,"], ,
[d
d/d000
d/d100
d/d200
d/d300
d/d400
d/d500
d/d600
d/d700
d/f000
d/f100
d/f200
d/f300
d/f400
d/f500
d/f600
d/f700
d/d500/d
d/d500/d/f
d/d700/d
d/d700/d/f
])

# Allow cleaning up
chmod -R u+rwx d
rm -rf d

AT_CLEANUP


AT_SETUP([updatedb: Invalid source database])
AT_KEYWORDS([updatedb])

mkdir d
touch d/f

AT_DATA([expout],
[d
d/f
])


> db
AT_CHECK([updatedb -U "$(pwd)/d" -o db -l 0])
AT_CHECK([locate -d db / | sed "s,^$(pwd)/,,"], , [expout])

echo '0123456789abcdef-' > db
AT_CHECK([updatedb -U "$(pwd)/d" -o db -l 0])
AT_CHECK([locate -d db / | sed "s,^$(pwd)/,,"], , [expout])

printf '\000mlocate\000\000\000\000\377\000xx-' > db
AT_CHECK([updatedb -U "$(pwd)/d" -o db -l 0])
AT_CHECK([locate -d db / | sed "s,^$(pwd)/,,"], , [expout])

printf '\000mlocate\000\000\000\000\000\377xx-' > db
AT_CHECK([updatedb -U "$(pwd)/d" -o db -l 0])
AT_CHECK([locate -d db / | sed "s,^$(pwd)/,,"], , [expout])

AT_CLEANUP


AT_SETUP([updatedb: Change detection])
AT_KEYWORDS([updatedb])

mkdir -p d/d0
touch d/f0 d/d0/f

AT_CHECK([updatedb -U "$(pwd)/d" -o db -l 0])
AT_CHECK([locate -d db / | sed "s,^$(pwd)/,,"], ,
[d
d/d0
d/f0
d/d0/f
])

mv d/d0 d/d1

AT_CHECK([updatedb -U "$(pwd)/d" -o db -l 0])
AT_CHECK([locate -d db / | sed "s,^$(pwd)/,,"], ,
[d
d/d1
d/f0
d/d1/f
])

mv d/f0 d/f1

AT_CHECK([updatedb -U "$(pwd)/d" -o db -l 0])
AT_CHECK([locate -d db / | sed "s,^$(pwd)/,,"], ,
[d
d/d1
d/f1
d/d1/f
])

touch d/f2
mkdir d/d2

AT_CHECK([updatedb -U "$(pwd)/d" -o db -l 0])
AT_CHECK([locate -d db / | sed "s,^$(pwd)/,,"], ,
[d
d/d1
d/d2
d/f1
d/f2
d/d1/f
])

rm -r d/d1 d/f1

AT_CHECK([updatedb -U "$(pwd)/d" -o db -l 0])
AT_CHECK([locate -d db / | sed "s,^$(pwd)/,,"], ,
[d
d/d2
d/f2
])

AT_CLEANUP


AT_SETUP([updatedb: Concurrent modification])
AT_KEYWORDS([updatedb])

mkdir d
touch d/f1

(cd d; while :; do mv f1 f2; mv f2 f1; done) &
bgpid=$!

AT_CHECK([updatedb -U "$(pwd)/d" -o db -l 0])

kill -KILL $bgpid
wait $bgpid

AT_CHECK([updatedb -U "$(pwd)/d" -o db -l 0])
AT_CHECK([locate -d db / -c], ,
[2
])

AT_CLEANUP


AT_SETUP([updatedb: Very deep hierarchy])
AT_KEYWORDS([updatedb])

# updatedb has two limits:
# - path name length of OBSTACK_SIZE_MAX, currently limiting the depth to
#   roughly 29000
# - resource limit on file descriptors, one per directory; site-dependent,
#   let's assume roughly 1024 are available
mkdir d
(
  cd d
  for depth in $(seq 1 950); do
    # $PSW and $OLDPWD eventually become larger than ARG_MAX
    PWD= OLDPWD= mkdir "depth$depth-abcdefghijklmnopqrstuvwxyz"
    # bash's cd complains if the path is too long
    cd "depth$depth-abcdefghijklmnopqrstuvwxyz" 2>/dev/null
  done
)

AT_CHECK([updatedb -U "$(pwd)/d" -o db -l 0])
AT_CHECK([locate -d db / -c], ,
[951
])

AT_CLEANUP


AT_SETUP([updatedb: Output creation])

AT_XFAIL_IF([test "x`id -u`" = x0])

mkdir d out
chmod 500 out

echo "updatedb: can not open a temporary file for \`$(pwd)/out/db'" > experr
AT_CHECK([updatedb -U "$(pwd)/d" -o out/db -l 0], 1, , [experr])

mkdir d2
chmod 600 d2

AT_CHECK([updatedb -U "$(pwd)/d2" -o db -l 0 2> error], 1)
AT_CHECK([sed "s,$(pwd)/,DIR/,; s/': .*$/': /" < error], ,
[updatedb: can not change directory to `DIR/d2': @&t@
])

(
  umask 000
  AT_CHECK([updatedb -U "$(pwd)/d" -o db -l 0])
  AT_CHECK([ls -l db | cut -c 1-10], ,
[-rw-rw-rw-
])
)

(
  umask 777
  AT_CHECK([updatedb -U "$(pwd)/d" -o db -l 0])
  AT_CHECK([ls -l db | cut -c 1-10], ,
[----------
])
)

chmod 700 out d2

AT_CLEANUP


AT_SETUP([updatedb: Path sorting])

mkdir -p d/a/z d/a.b d/a.c
touch d/a/z/x d/a.b/x d/a.c/x
# The correct sort order of conf_prunepaths is d/a/z d/a.b.  An incorrect sort
# order, e.g. d/a.b d/a/z, would prune only d/a/z.

AT_CHECK([updatedb --prunepaths "$(pwd)/d/a.b $(pwd)/d/a/z" -U "$(pwd)/d" \
	 -o db -l 0])
AT_CHECK([locate -d db / | sed "s,^$(pwd)/,,"], ,
[d
d/a
d/a.b
d/a.c
d/a/z
d/a.c/x
])

AT_CLEANUP