]>
Commit | Line | Data |
---|---|---|
1 | --- findutils-4.2.4/locate/updatedb.sh.orig 2004-11-08 01:41:48.000000000 +0100 | |
2 | +++ findutils-4.2.4/locate/updatedb.sh 2004-11-09 00:00:15.469313808 +0100 | |
3 | @@ -118,6 +118,12 @@ | |
4 | fi | |
5 | export TMPDIR | |
6 | ||
7 | +if test -x /bin/mktemp; then | |
8 | + : ${MKTEMP=/bin/mktemp} | |
9 | +else | |
10 | + : ${MKTEMP=/bin/touch} | |
11 | +fi | |
12 | + | |
13 | # The user to search network directories as. | |
14 | : ${NETUSER=daemon} | |
15 | ||
16 | @@ -161,6 +167,11 @@ | |
17 | ||
18 | if test $old = no; then | |
19 | ||
20 | +NEW_LOCATE_DB=`$MKTEMP $LOCATE_DB.n.XXXXXX` || { | |
21 | + echo "could not create temporary locate db" >&2 | |
22 | + exit 1 | |
23 | +} | |
24 | + | |
25 | # FIXME figure out how to sort null-terminated strings, and use -print0. | |
26 | if { | |
27 | cd "$changeto" | |
28 | @@ -192,7 +203,7 @@ | |
29 | exit $? | |
30 | fi | |
31 | fi | |
32 | -} | $sort -f | $frcode $frcode_options > $LOCATE_DB.n | |
33 | +} | $sort -f | $frcode $frcode_options > $NEW_LOCATE_DB | |
34 | then | |
35 | # OK so far | |
36 | true | |
37 | @@ -205,29 +216,29 @@ | |
38 | ||
39 | # To avoid breaking locate while this script is running, put the | |
40 | # results in a temp file, then rename it atomically. | |
41 | -if test -s $LOCATE_DB.n; then | |
42 | +if test -s $NEW_LOCATE_DB; then | |
43 | rm -f $LOCATE_DB | |
44 | - mv $LOCATE_DB.n $LOCATE_DB | |
45 | + mv $NEW_LOCATE_DB $LOCATE_DB | |
46 | chmod 644 $LOCATE_DB | |
47 | else | |
48 | echo "updatedb: new database would be empty" >&2 | |
49 | - rm -f $LOCATE_DB.n | |
50 | + rm -f $NEW_LOCATE_DB | |
51 | fi | |
52 | ||
53 | else # old | |
54 | ||
55 | -if ! bigrams=`tempfile -p updatedb`; then | |
56 | +if ! bigrams=`$MKTEMP $TMPDIR/f.bigrams$$XXXXXX`; then | |
57 | echo tempfile failed | |
58 | exit 1 | |
59 | fi | |
60 | ||
61 | -if ! filelist=`tempfile -p updatedb`; then | |
62 | +if ! filelist=`$MKTEMP $TMPDIR/f.list$$XXXXXX`; then | |
63 | echo tempfile failed | |
64 | exit 1 | |
65 | fi | |
66 | ||
67 | -rm -f $LOCATE_DB.n | |
68 | -trap 'rm -f $bigrams $filelist $LOCATE_DB.n; exit' HUP TERM | |
69 | +rm -f $NEW_LOCATE_DB | |
70 | +trap 'rm -f $bigrams $filelist $NEW_LOCATE_DB; exit' HUP TERM | |
71 | ||
72 | # Alphabetize subdirectories before file entries using tr. James Woods says: | |
73 | # "to get everything in monotonic collating sequence, to avoid some | |
74 | @@ -269,19 +280,19 @@ | |
75 | awk '{ if (NR <= 128) print $2 }' | tr -d '\012' > $bigrams | |
76 | ||
77 | # Code the file list. | |
78 | -$code $bigrams < $filelist > $LOCATE_DB.n | |
79 | +$code $bigrams < $filelist > $NEW_LOCATE_DB | |
80 | ||
81 | rm -f $bigrams $filelist | |
82 | ||
83 | # To reduce the chances of breaking locate while this script is running, | |
84 | # put the results in a temp file, then rename it atomically. | |
85 | -if test -s $LOCATE_DB.n; then | |
86 | +if test -s $NEW_LOCATE_DB; then | |
87 | rm -f $LOCATE_DB | |
88 | - mv $LOCATE_DB.n $LOCATE_DB | |
89 | + mv $NEW_LOCATE_DB $LOCATE_DB | |
90 | chmod 644 $LOCATE_DB | |
91 | else | |
92 | echo "updatedb: new database would be empty" >&2 | |
93 | - rm -f $LOCATE_DB.n | |
94 | + rm -f $NEW_LOCATE_DB | |
95 | fi | |
96 | ||
97 | fi |