Add/fix copyright notices and adjust to latest GNU FDL.
[platform/upstream/coreutils.git] / tests / touch / empty-file
1 #!/bin/sh
2 # Make sure touch can set the mtime on an empty file.
3
4 # Copyright (C) 1998, 1999, 2000, 2005 Free Software Foundation, Inc.
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
20
21
22 # Volker Borchert reported that touch 3.16r (and presumably all before that)
23 # fails to work on SunOS 4.1.3 with `most of the recommended patches' when
24 # the empty file is on an NFS-mounted 4.2 volume.
25
26 if test "$VERBOSE" = yes; then
27   set -x
28   touch --version
29 fi
30
31 DEFAULT_SLEEP_SECONDS=2
32 SLEEP_SECONDS=${SLEEP_SECONDS=$DEFAULT_SLEEP_SECONDS}
33
34 fail=0
35
36 # FIXME: find writable directories on other partitions
37 # and run the test in those directories, too.
38
39 : ${TOUCH_DIR_LIST=.}
40
41 framework_failure=0
42
43 for d in $TOUCH_DIR_LIST; do
44   rm -rf $d/a $d/b $d/c
45   > $d/a || framework_failure=1
46   test -f $d/a || framework_failure=1
47   > $d/b || framework_failure=1
48   test -f $d/b || framework_failure=1
49   > $d/c || framework_failure=1
50   test -f $d/c || framework_failure=1
51 done
52
53 if test $framework_failure = 1; then
54   echo 'failure in testing framework'
55   exit 1
56 fi
57
58 echo sleeping for $SLEEP_SECONDS seconds...
59 sleep $SLEEP_SECONDS
60 for d in $TOUCH_DIR_LIST; do
61   touch $d/a || fail=1
62   set x `ls -t $d/a $d/b`
63   test "$*" = "x $d/a $d/b" || fail=1
64 done
65
66 echo sleeping for $SLEEP_SECONDS seconds...
67 sleep $SLEEP_SECONDS
68 for d in $TOUCH_DIR_LIST; do
69   touch $d/b
70   set x `ls -t $d/a $d/b`
71   test "$*" = "x $d/b $d/a" || fail=1
72
73   if touch - 1< $d/c 2> /dev/null; then
74     set x `ls -t $d/a $d/c`
75     test "$*" = "x $d/c $d/a" || fail=1
76   fi
77
78   rm -rf $d/a $d/b $d/c
79 done
80
81 if test $fail != 0; then
82   cat 1>&2 <<EOF
83 *** This test has just failed.  That can happen when the test is run in an
84 *** NFS-mounted directory on a system whose clock is not well synchronized
85 *** with that of the NFS server.  If you think that is the reason, set the
86 *** environment variable SLEEP_SECONDS to some number of seconds larger than
87 *** the default of $DEFAULT_SLEEP_SECONDS and rerun the test.
88 EOF
89 fi
90
91 exit $fail