Compare commits

...

47 Commits

Author SHA1 Message Date
Jim Meyering
3abc240e82 *** empty log message *** 1999-12-05 15:14:18 +00:00
Jim Meyering
ff8f4dde22 *** empty log message *** 1999-12-05 15:13:40 +00:00
Jim Meyering
f880990daf Revert the previous change.
(copy_internal): In move mode, if the rename attempt
fails, then unlink any existing destination file.  This makes a
cross-device `mv' more consistent with the intra-device behavior.
This change is required by POSIX to make a cross-device move act with
semantics similar to those of the rename syscall.  For example now
`mv' can move a file onto a symlink to itself when that symlink
is on a separate partition.  With fileutils-4.0j, it would fail with
a diagnostic saying they were the same file.
Reported by Bruno Haible.
1999-12-05 15:13:21 +00:00
Jim Meyering
7306126ef0 *** empty log message *** 1999-12-04 17:46:39 +00:00
Jim Meyering
305e2306be . 1999-12-04 17:46:06 +00:00
Jim Meyering
2b10e67d59 (TESTS): Add to-symlink. 1999-12-04 17:45:45 +00:00
Jim Meyering
dc74b3a1e7 Make sure that the copying code used in an inter-partition
move unlinks a destination symlink before opening it.
1999-12-04 17:44:59 +00:00
Jim Meyering
2f21a269fe *** empty log message *** 1999-12-04 17:34:39 +00:00
Jim Meyering
69408d229e *** empty log message *** 1999-12-04 17:34:05 +00:00
Jim Meyering
f05badd230 (trap): Be careful to close $actual before
removing the containing directory.  Otherwise, on some systems rmdir
fails to remove the containing directory.
1999-12-04 17:33:49 +00:00
Jim Meyering
6763fa97d2 *** empty log message *** 1999-12-04 17:31:29 +00:00
Jim Meyering
b1b10e1e40 List --full-time dates upon failure. 1999-12-04 17:31:23 +00:00
Jim Meyering
5810f4bee5 . 1999-12-04 17:30:24 +00:00
Jim Meyering
91b5e686d5 Adapt to reflect this change in behavior.
Make sure the VERSION_CONTROL envvar is not set.
Run diff if comparison fails.
1999-12-04 17:30:16 +00:00
Jim Meyering
8c096b86ef Use mv, ls, rm, not $MV, $LS, $RM. 1999-12-04 17:24:19 +00:00
Jim Meyering
698fd02798 (copy_internal): Be consistent with intra-device behavior
and *do* allow `mv' to move a file onto a symlink to itself when that
symlink is on a separate partition.  With fileutils-4.0j, it would
fail with a diagnostic saying they were the same file.
Reported by Bruno Haible.
1999-12-04 17:21:47 +00:00
Jim Meyering
28bac510d9 *** empty log message *** 1999-12-04 17:21:06 +00:00
Jim Meyering
2413369d22 *** empty log message *** 1999-12-04 17:05:27 +00:00
Jim Meyering
091109470c Give the right diagnostic when failing to create a file in an
unwritable directory.

(touch): Record errno upon failed errno and use that
saved value if a subsequent fstat, stat or utime call fails.
Reported by Wichert Akkerman via Michael Stone.
1999-12-04 17:03:43 +00:00
Jim Meyering
9481a7bd36 *** empty log message *** 1999-12-04 16:56:07 +00:00
Jim Meyering
2be3dc067a (check_symlink_color): New variable.
(main): Set it if we need to check for dangling symlinks when
displaying colors.
(gobble_file): Check check_symlink_color instead of print_with_color.
1999-12-04 16:55:27 +00:00
Jim Meyering
c4542a7e8c (usage): Shorten help for --show-control-chars. 1999-11-30 21:09:35 +00:00
Jim Meyering
6c9e0d702a *** empty log message *** 1999-11-30 16:09:58 +00:00
Jim Meyering
062906c83a Don't include math.h or float.h.
Don't use DBL_MAX.
Use TIME_T_MAX instead.
1999-11-28 19:59:18 +00:00
Jim Meyering
2c3fa56cef *** empty log message *** 1999-11-28 19:57:54 +00:00
Jim Meyering
346edb7361 *** empty log message *** 1999-11-28 19:56:38 +00:00
Jim Meyering
b9c91d0570 don't include assert.h 1999-11-28 14:04:12 +00:00
Jim Meyering
e20a9b89d2 Round more carefully so we never call nanosleep with more than 999,999,999
nanoseconds.
Comment out assertion because it uses on EINTR.
1999-11-28 14:03:43 +00:00
Jim Meyering
0baa523154 Rewrite to use nanosleep (hence, timer stops when sleep is suspended)
and to remove gettimeofday/signal cruft.
Improve overflow checking.
1999-11-28 13:35:00 +00:00
Jim Meyering
d5f7b2a2db *** empty log message *** 1999-11-28 08:08:51 +00:00
Jim Meyering
4c05896b20 better error checking
add FIXME comments for non-portable constructs
1999-11-28 08:00:58 +00:00
Jim Meyering
ec974f5c39 remove another printf stmt 1999-11-27 20:03:05 +00:00
Jim Meyering
15d2e7a86b remove printf stmts 1999-11-27 20:02:38 +00:00
Jim Meyering
069610a0f0 fix typos 1999-11-27 20:01:22 +00:00
Jim Meyering
5617251659 Rewrite to allow fractional seconds and to handle SIGCONT.
(main): Rewrite.
(sighandler): New function.
(apply_suffix): New function.
(timeval_subtract): New function.
1999-11-27 20:00:54 +00:00
Jim Meyering
398516f242 (usage): Add elipses to show that sleep allows more than one argument. 1999-11-27 17:10:15 +00:00
Jim Meyering
8e1452ffea remove brackets around required sleep argument 1999-11-27 17:04:29 +00:00
Jim Meyering
6b36a017db (argdecode): Move definition to precede use.
Remove prototype.
1999-11-27 15:02:27 +00:00
Jim Meyering
30d2b031ab *** empty log message *** 1999-11-27 10:15:46 +00:00
Jim Meyering
f72f631fa0 Don't set/use MV, etc. 1999-11-27 10:14:53 +00:00
Jim Meyering
d10b18f2b9 *** empty log message *** 1999-11-27 10:14:24 +00:00
Jim Meyering
511cd5b6ae Don't set/use MV, etc. 1999-11-27 10:14:04 +00:00
Jim Meyering
09282a24f6 Don't set/use RM and MV. 1999-11-27 10:11:25 +00:00
Jim Meyering
f36a801a9a Don't set/use LS MV MKDIR MKNOD RM TOUCH 1999-11-27 10:10:02 +00:00
Jim Meyering
1e219d6b71 Don't set/use DF or MKDIR. 1999-11-27 10:08:55 +00:00
Jim Meyering
2e0f5a2bac *** empty log message *** 1999-11-27 10:05:25 +00:00
Jim Meyering
9234f12d32 (TESTS): Add partition-perm. 1999-11-27 10:05:11 +00:00
23 changed files with 372 additions and 123 deletions

3
THANKS
View File

@@ -8,7 +8,7 @@ Akim Demaille: demaille@inf.enst.fr
Alain Magloire: alain@qnx.com
Alexey Solovyov: alekso@math.uu.se
Andreas Jaeger: jaeger@gnu.org
Andreas Schwab: schwab@issan.informatik.uni-dortmund.de
Andreas Schwab: schwab@suse.de
Andres Soolo: andres@soolo.matti.ee
Andrew Dalke: dalke@bioreason.com
Andrew Tridgell: tridge@samba.org
@@ -98,4 +98,5 @@ Ulrich Drepper: drepper@cygnus.com
Vin Shelton: acs@alumni.princeton.edu
Volker Borchert: bt@teknon.de
Wayne Stewart: wstewa@atl.com
Wichert Akkerman: wichert@cistron.nl
William Bader: william@nscs.fast.net

View File

@@ -3041,7 +3041,7 @@ the values of the command line arguments.
Synopsis:
@example
sleep [@var{number}[smhd]]@dots{}
sleep @var{number}[smhd]@dots{}
@end example
@cindex time units

View File

@@ -1,5 +1,63 @@
1999-12-04 Jim Meyering <meyering@ascend.com>
* Version 4.0k.
* tests/mv/into-self-2: Adapt to reflect this change in behavior.
Make sure the VERSION_CONTROL envvar is not set.
Run diff if comparison fails.
* src/copy.c (copy_internal): In move mode, if the rename attempt
fails, then unlink any existing destination file. This makes a
cross-device `mv' more consistent with the intra-device behavior.
This change is required by POSIX to make a cross-device move act with
semantics similar to those of the rename syscall. For example now
`mv' can move a file onto a symlink to itself when that symlink
is on a separate partition. With fileutils-4.0j, it would fail with
a diagnostic saying they were the same file.
Reported by Bruno Haible.
* tests/mv/to-symlink: New file. Adds test for the above.
* tests/mv/Makefile.am (TESTS): Add to-symlink.
* tests/cp/cp-mv-backup (trap): Be careful to close $actual before
removing the containing directory. Otherwise, on some systems rmdir
fails to remove the containing directory.
* tests/ls/time-1: List --full-time dates upon failure.
1999-12-02 Andreas Schwab <schwab@suse.de>
* src/ls.c (check_symlink_color): New variable.
(main): Set it if we need to check for dangling symlinks when
displaying colors.
(gobble_file): Check check_symlink_color instead of print_with_color.
1999-11-30 Paul Eggert <eggert@twinsun.com>
* src/ls.c (usage): Shorten help for --show-control-chars.
1999-11-30 Jim Meyering <meyering@ascend.com>
Give the right diagnostic when failing to create a file in an
unwritable directory.
* src/touch.c (touch): Record errno upon failed errno and use that
saved value if a subsequent fstat, stat or utime call fails.
Reported by Wichert Akkerman via Michael Stone.
1999-11-27 Jim Meyering <meyering@ascend.com>
Clean up test scripts.
* tests/mv/setup: Don't set/use DF or MKDIR. Use df and mkdir instead.
* tests/mv/mv-special-1: Likewise for these: LS MV MKDIR MKNOD RM TOUCH
* tests/mv/backup-is-src: Likewise for RM and MV.
* tests/mv/hard-link-1: Likewise.
* tests/mv/into-self: Likewise.
* tests/mv/into-self-3: Likewise.
Add test for 1999-05-23 change to src/copy.c (copy_internal).
* tests/mv/partition-perm: New file.
* tests/mv/Makefile.am (TESTS): Add partition-perm.
* Version 4.0j.
1999-11-22 Paul Eggert <eggert@twinsun.com>
@@ -591,7 +649,6 @@
1999-05-23 Jim Meyering <meyering@ascend.com>
FIXME: add a test for this
* src/copy.c (copy_internal): Don't apply the umask in move_mode.
Otherwise, `mv' would not preserve the permissions when copying
between partitions. Reported by David Godfrey

View File

@@ -1,4 +1,11 @@
Changes in release 4.1:
[4.0k]
* mv may now be used to move a file onto a symlink to itself when that
symlink is on a separate partition. With fileutils-4.0j, it would
fail with a diagnostic saying they were the same file.
* touch would fail with the misleading diagnostic `no such file' when asked
to create a file in an unwritable directory. Now it says something like
`permission denied' or `read-only file system'.
[4.0j]
* mkdir may now be used to set special bits e.g., `mkdir -m o+t dir' works
* touch can now change the time(s) of a file you own even if you don't have

View File

@@ -1,3 +1,16 @@
1999-11-27 Jim Meyering <meyering@ascend.com>
Rewrite to allow fractional seconds and to handle SIGCONT.
* src/sleep.c (main): Rewrite.
(sighandler): New function.
(apply_suffix): New function.
(timeval_subtract): New function.
Reported by Raul Miller.
* src/sleep.c (argdecode): Move definition to precede use.
Remove prototype.
(usage): Add elipses to show that sleep allows more than one argument.
1999-11-22 Jim Meyering <meyering@ascend.com>
* lib/Makefile.am (DISTCLEANFILES): Add lstat.c and stat.c.

View File

@@ -1,4 +1,6 @@
Changes in release 2.1
[2.0a]
* sleep continues sleeping after being suspended and continued
Changes in release 2.0
* disable stty tests (otherwise they fail) when `make check' is run via rsh
[1.16m]

View File

@@ -371,6 +371,7 @@ copy_internal (const char *src_path, const char *dst_path,
char *earlier_file;
char *dst_backup = NULL;
int fix_mode = 0;
int rename_errno;
if (move_mode && rename_succeeded)
*rename_succeeded = 0;
@@ -428,12 +429,13 @@ copy_internal (const char *src_path, const char *dst_path,
/* If we'll remove DST_PATH first, then this doesn't matter. */
&& ! x->force
/* Allow them to be the same (and don't set `same') if
we're in move mode and the target is a symlink
on the same partition. */
/* Allow them to be the same (and don't set `same') if we're
in move mode and the target is a symlink. That is ok, since
we remove any existing destination file before opening it --
via `rename' if they're on the same file system,
via `unlink(DST_PATH)' otherwise. */
&& !(move_mode
&& S_ISLNK (dst_sb.st_mode)
&& src_sb.st_dev == dst_sb.st_dev)
&& S_ISLNK (dst_sb.st_mode))
/* If we're making a backup, we'll detect the problem case in
copy_reg because SRC_PATH will no longer exist. Allowing
@@ -656,6 +658,20 @@ copy_internal (const char *src_path, const char *dst_path,
/* Ignore other types of failure (e.g. EXDEV), since the following
code will try to perform a copy, then remove. */
/* Save this value of errno to use in case the unlink fails. */
rename_errno = errno;
/* The rename attempt has failed. Remove any existing destination
file so that a cross-device `mv' acts as if it were really using
the rename syscall. */
if (unlink (dst_path) && errno != ENOENT)
{
/* Use the value of errno from the failed rename. */
error (0, rename_errno, _("cannot move `%s' to `%s'"),
src_path, dst_path);
return 1;
}
}
if (S_ISDIR (src_type))

View File

@@ -478,6 +478,11 @@ static struct color_ext_type *color_ext_list = NULL;
/* Buffer for color sequences */
static char *color_buf;
/* Nonzero means to check for orphaned symbolic link, for displaying
colors. */
static int check_symlink_color;
/* Nonzero means mention the inode number of each file. -i */
static int print_inode;
@@ -763,6 +768,11 @@ main (int argc, char **argv)
{
parse_ls_color ();
prep_non_filename_text ();
/* Avoid following symbolic links when possible. */
if (color_indicator[C_ORPHAN].string != NULL
|| (color_indicator[C_MISSING].string != NULL
&& format == long_format))
check_symlink_color = 1;
}
format_needs_stat = sort_type == sort_time || sort_type == sort_size
@@ -1764,7 +1774,7 @@ gobble_file (const char *name, int explicit_arg, const char *dirname)
}
if (S_ISLNK (files[files_index].stat.st_mode)
&& (explicit_arg || format == long_format || print_with_color))
&& (explicit_arg || format == long_format || check_symlink_color))
{
char *linkpath;
struct stat linkstats;
@@ -1777,7 +1787,7 @@ gobble_file (const char *name, int explicit_arg, const char *dirname)
if (linkpath
&& ((explicit_arg && format != long_format)
|| indicator_style != none
|| print_with_color)
|| check_symlink_color)
&& stat (linkpath, &linkstats) == 0)
{
files[files_index].linkok = 1;
@@ -2905,10 +2915,8 @@ Sort entries alphabetically if none of -cftuSUX nor --sort.\n\
-o use long listing format without group info\n\
-p, --file-type append indicator (one of /=@|) to entries\n\
-q, --hide-control-chars print ? instead of non graphic characters\n\
(This is the default unless the output is a\n\
terminal and the program is `ls'; otherwise,\n\
the default is --show-control-chars)\n\
--show-control-chars show non graphic characters as-is (default)\n\
--show-control-chars show non graphic characters as-is (default\n\
unless program is `ls' and output is a terminal)\n\
-Q, --quote-name enclose entry names in double quotes\n\
--quoting-style=WORD use quoting style WORD for entry names:\n\
literal, locale, shell, shell-always, c, escape\n\

View File

@@ -17,19 +17,24 @@
#include <config.h>
#include <stdio.h>
#include <assert.h>
#include <sys/types.h>
#include <time.h>
#include <getopt.h>
#ifndef TIME_T_MAX
# define TIME_T_MAX TYPE_MAXIMUM (time_t)
#endif
#include "system.h"
#include "error.h"
#include "long-options.h"
#include "xstrtod.h"
/* The official name of this program (e.g., no `g' prefix). */
#define PROGRAM_NAME "sleep"
#define AUTHORS "FIXME: unknown"
static long argdecode PARAMS ((const char *s));
#define AUTHORS "Jim Meyering"
/* The name by which this program was run. */
char *program_name;
@@ -48,7 +53,7 @@ usage (int status)
else
{
printf (_("\
Usage: %s NUMBER[SUFFIX]\n\
Usage: %s NUMBER[SUFFIX]...\n\
or: %s OPTION\n\
Pause for NUMBER seconds.\n\
SUFFIX may be s for seconds (the default), m for minutes,\n\
@@ -63,12 +68,51 @@ h for hours or d for days.\n\
exit (status);
}
/* FIXME: describe */
static int
apply_suffix (double *s, char suffix_char)
{
unsigned int multiplier;
assert (*s <= TIME_T_MAX);
switch (suffix_char)
{
case 0:
case 's':
multiplier = 1;
break;
case 'm':
multiplier = 60;
break;
case 'h':
multiplier = 60 * 60;
break;
case 'd':
multiplier = 60 * 60 * 24;
break;
default:
multiplier = 0;
}
if (multiplier == 0)
return 1;
*s *= multiplier;
return 0;
}
int
main (int argc, char **argv)
{
int i;
unsigned seconds = 0;
double seconds = 0.0;
int c;
int fail = 0;
int interrupted;
struct timespec ts;
program_name = argv[0];
setlocale (LC_ALL, "");
@@ -96,43 +140,48 @@ main (int argc, char **argv)
usage (1);
}
for (i = 1; i < argc; i++)
seconds += argdecode (argv[i]);
for (i = optind; i < argc; i++)
{
double s;
const char *p;
if (xstrtod (argv[i], &p, &s)
/* No negative intervals. */
|| s < 0
/* S must fit in a time_t. */
|| s > TIME_T_MAX
/* No extra chars after the number and an optional s,m,h,d char. */
|| (*p && *(p+1))
/* Check any suffix char and update S based on the suffix. */
|| apply_suffix (&s, *p)
/* Make sure the sum fits in a time_t. */
|| (seconds += s) > TIME_T_MAX
)
{
error (0, 0, _("invalid time interval `%s'"), argv[i]);
fail = 1;
}
}
sleep (seconds);
if (fail)
usage (1);
/* Round to the nearest nanosecond here so that tv_nsec will be
no larger than 999,999,999. */
seconds += .0000000005;
/* Separate whole seconds from nanoseconds. */
ts.tv_sec = seconds;
ts.tv_nsec = (seconds - ts.tv_sec) * 1000000000;
while (1)
{
struct timespec remaining;
interrupted = nanosleep (&ts, &remaining);
/* assert (!interrupted || errno == EINTR); */
if (!interrupted)
break;
ts = remaining;
}
exit (0);
}
static long
argdecode (const char *s)
{
long value;
register const char *p = s;
register char c;
value = 0;
while ((c = *p++) >= '0' && c <= '9')
value = value * 10 + c - '0';
switch (c)
{
case 's':
break;
case 'm':
value *= 60;
break;
case 'h':
value *= 60 * 60;
break;
case 'd':
value *= 60 * 60 * 24;
break;
default:
p--;
}
if (*p)
error (1, 0, _("invalid time interval `%s'"), s);
return value;
}

View File

@@ -111,12 +111,15 @@ touch (const char *file)
int status;
struct stat sbuf;
int fd = -1;
int open_errno = 0;
if (! no_create)
{
/* Try to open FILE, creating it if necessary. */
fd = open (file, O_WRONLY | O_CREAT,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
if (fd == -1)
open_errno = errno;
}
if (! amtime_now)
@@ -127,7 +130,7 @@ touch (const char *file)
or FILE is inaccessible or a directory, so we have to use stat. */
if (fd != -1 ? fstat (fd, &sbuf) : stat (file, &sbuf))
{
error (0, errno, "%s", file);
error (0, open_errno ? open_errno : errno, "%s", file);
close (fd);
return 1;
}
@@ -172,7 +175,7 @@ touch (const char *file)
if (status)
{
error (0, errno, "%s", file);
error (0, open_errno ? open_errno : errno, "%s", file);
return 1;
}

View File

@@ -15,7 +15,9 @@ pwd=`pwd`
dir=cpmvbak-$$
actual=$dir/actual
expected=$dir/expected
trap "cd $pwd; rm -rf $dir" 0 1 2 3 15
# Be careful to close $actual before removing the containing directory.
trap "cd $pwd; exec 1<&-; rm -rf $dir" 0 1 2 3 15
mkdir $dir
unset VERSION_CONTROL SIMPLE_BACKUP_SUFFIX

View File

@@ -52,9 +52,11 @@ fi
set `ls -u a b c`
test "$*" = 'c b a' && : || fail=1
test $fail = 1 && ls -l --full-time --time=access a b c
set `ls -t a b c`
test "$*" = 'a b c' && : || fail=1
test $fail = 1 && ls -l --full-time a b c
# Now, C should have ctime more recent than A.
set `ls -c a c`

View File

@@ -2,7 +2,7 @@
AUTOMAKE_OPTIONS = 1.3 gnits
TESTS = mv-special-1 into-self into-self-2 into-self-3 backup-is-src \
i-1 hard-link-1 force
i-1 hard-link-1 force partition-perm to-symlink
EXTRA_DIST = $(TESTS) setup
TESTS_ENVIRONMENT = \

View File

@@ -104,7 +104,7 @@ l = @l@
AUTOMAKE_OPTIONS = 1.3 gnits
TESTS = mv-special-1 into-self into-self-2 into-self-3 backup-is-src \
i-1 hard-link-1 force
i-1 hard-link-1 force partition-perm to-symlink
EXTRA_DIST = $(TESTS) setup

View File

@@ -1,12 +1,9 @@
#!/bin/sh
# Force mv to use the copying code.
: ${MV=mv}
: ${RM=rm}
if test "$VERBOSE" = yes; then
set -x
$MV --version
mv --version
fi
. $srcdir/setup
@@ -19,7 +16,7 @@ a="$other_partition_tmpdir/a"
a2="$other_partition_tmpdir/a~"
framework_failure=0
$RM -f $a $a2 || framework_failure=1
rm -f $a $a2 || framework_failure=1
echo a > $a || framework_failure=1
echo a2 > $a2 || framework_failure=1
@@ -37,10 +34,10 @@ LANG=C
export LANG
# This mv command should exit nonzero.
$MV --b=simple $a2 $a > out 2>&1 && fail=1
mv --b=simple $a2 $a > out 2>&1 && fail=1
sed \
-e "s,$MV:,XXX:," \
-e "s,mv:,XXX:," \
-e "s,$a,YYY," \
-e "s,$a2,ZZZ," \
out > out2
@@ -51,6 +48,6 @@ EOF
cmp out2 exp || fail=1
$RM -fr out out2 exp $a $a2 $other_partition_tmpdir
rm -fr out out2 exp $a $a2 $other_partition_tmpdir
exit $fail

View File

@@ -2,15 +2,9 @@
# move a directory containing hard-linked files and
# make sure the links are preserved
: ${MV=mv}
: ${RM=rm}
: ${MKDIR=mkdir}
: ${LN=ln}
: ${LS=ls}
if test "$VERBOSE" = yes; then
set -x
$MV --version
mv --version
fi
. $srcdir/setup
@@ -22,9 +16,9 @@ fi
dir=hlink
framework_failure=0
$MKDIR $dir || framework_failure=1
mkdir $dir || framework_failure=1
> $dir/a || framework_failure=1
$LN $dir/a $dir/b || framework_failure=1
ln $dir/a $dir/b || framework_failure=1
if test $framework_failure = 1; then
echo 'failure in testing framework'
@@ -39,16 +33,16 @@ export LC_ALL
LANG=C
export LANG
$MV $dir $other_partition_tmpdir || fail=1
mv $dir $other_partition_tmpdir || fail=1
# Display inode numbers, one per line.
$LS -1i $other_partition_tmpdir/$dir > out || fail=1
ls -1i $other_partition_tmpdir/$dir > out || fail=1
# Make sure the inode numbers are the same.
a=`sed -n 's/ a$//p' out`
b=`sed -n 's/ b$//p' out`
test "$a" = "$b" || fail=1
$RM -fr out $dir $other_partition_tmpdir
rm -fr out $dir $other_partition_tmpdir
exit $fail

View File

@@ -1,14 +1,9 @@
#! /bin/sh
# Demonstrate how mv fails when it tries to move a directory into itself.
: ${MV=mv}
: ${MKDIR=mkdir}
: ${RM=rm}
: ${TOUCH=touch}
if test "$VERBOSE" = yes; then
set -x
$MV --version
mv --version
fi
dir=into-self-dir
@@ -16,9 +11,9 @@ file=into-self-file
test_failure=0
$RM -rf $dir $file || test_failure=1
$MKDIR -p $dir/a/b || test_failure=1
$TOUCH $file || test_failure=1
rm -rf $dir $file || test_failure=1
mkdir -p $dir/a/b || test_failure=1
touch $file || test_failure=1
if test $test_failure = 1; then
echo 'failure in testing framework'
@@ -36,10 +31,10 @@ LANG=C
export LANG
# This mv command should fail.
$MV $dir $file $dir > out 2>&1 && fail=1
mv $dir $file $dir > out 2>&1 && fail=1
sed \
-e "s,$MV:,XXX:," \
-e "s,mv:,XXX:," \
-e "s,$dir,SRC," \
-e "s,$dir/$dir,DEST," \
out > out2
@@ -57,6 +52,6 @@ test -d $dir || fail=1
test -d $dir/$dir && fail=1
# Make sure the file has been moved to the right place.
test -f $dir/$file || fail=1
$RM -rf $dir $file out out2 exp
rm -rf $dir $file out out2 exp
exit $fail

View File

@@ -17,6 +17,11 @@ fi
file="$other_partition_tmpdir/file"
symlink=symlink
fail=0
trap 'rm -fr out out2 exp $file $symlink $other_partition_tmpdir; exit $fail' \
0 1 2 3 15
framework_failure=0
rm -f $file $symlink || framework_failure=1
echo whatever > $file || framework_failure=1
@@ -35,11 +40,19 @@ export LC_ALL
LANG=C
export LANG
unset VERSION_CONTROL
if test "${VERSION_CONTROL+set}" = set; then
echo '$0: the VERSION_CONTROL envvar is set --' \
' unset it and rerun this test' >&2
exit 1
fi
# This mv command should exit nonzero.
mv $symlink $file > out 2>&1 && fail=1
# And so should this one.
mv $file $symlink >> out 2>&1 && fail=1
# This should succeed.
mv $file $symlink || fail=1
sed \
-e "s,mv:,XXX:," \
@@ -49,12 +62,10 @@ sed \
cat > exp <<\EOF
XXX: `ZZZ' and `YYY' are the same file
XXX: `YYY' and `ZZZ' are the same file
EOF
#'
cmp out2 exp || fail=1
rm -fr out out2 exp $file $symlink $other_partition_tmpdir
test $fail = 1 && diff out2 exp 2> /dev/null
exit $fail

View File

@@ -6,14 +6,14 @@
if test "$VERBOSE" = yes; then
set -x
$MV --version
mv --version
fi
dir1=is3-dir1
dir2=is3-dir2
framework_failure=0
$RM -rf $dir1 $dir2 || framework_failure=1
rm -rf $dir1 $dir2 || framework_failure=1
mkdir $dir1 $dir2 || framework_failure=1
if test $framework_failure = 1; then
@@ -30,10 +30,10 @@ LANG=C
export LANG
# This mv command should exit nonzero.
$MV $dir1 $dir2 $dir2 > out 2>&1 && fail=1
mv $dir1 $dir2 $dir2 > out 2>&1 && fail=1
sed \
-e "s,$MV:,XXX:,g" \
-e "s,mv:,XXX:,g" \
-e "s,$dir2,ZZZ,g" \
out > out2
@@ -43,6 +43,6 @@ EOF
cmp out2 exp || fail=1
$RM -fr out out2 exp $dir1 $dir2
rm -fr out out2 exp $dir1 $dir2
exit $fail

View File

@@ -1,12 +1,5 @@
#! /bin/sh
: ${LS=ls}
: ${MV=mv}
: ${MKDIR=mkdir}
: ${MKNOD=mknod}
: ${RM=rm}
: ${TOUCH=touch}
. $srcdir/setup
if test -z "$other_partition_tmpdir"; then
@@ -18,10 +11,10 @@ dir=.mv-dir
framework_failure=0
$RM -f $null || framework_failure=1
$MKNOD $null p || framework_failure=1
$MKDIR -p $dir/a/b/c $dir/d/e/f || framework_failure=1
$TOUCH $dir/a/b/c/file1 $dir/d/e/f/file2 || framework_failure=1
rm -f $null || framework_failure=1
mknod $null p || framework_failure=1
mkdir -p $dir/a/b/c $dir/d/e/f || framework_failure=1
touch $dir/a/b/c/file1 $dir/d/e/f/file2 || framework_failure=1
if test $framework_failure = 1; then
echo 'failure in testing framework'
@@ -37,13 +30,13 @@ LANG=C
export LANG
fail=0
$MV --verbose $null $dir $other_partition_tmpdir > out || fail=1
mv --verbose $null $dir $other_partition_tmpdir > out || fail=1
# Make sure the files are gone.
test -f $null && fail=1
test -d $dir && fail=1
# Make sure they were moved.
# Since `test -e' is not portable, use `ls'.
$LS $other_partition_tmpdir/$null > /dev/null || fail=1
ls $other_partition_tmpdir/$null > /dev/null || fail=1
test -d $other_partition_tmpdir/$dir/a/b/c || fail=1
sed "s,$other_partition_tmpdir,XXX," out > out2
@@ -81,8 +74,8 @@ EOF
cmp out2 exp || fail=1
# cd $other_partition_tmpdir
# $LS -l -A -R $other_partition_tmpdir
# ls -l -A -R $other_partition_tmpdir
$RM -rf $null $dir $other_partition_tmpdir out out2 exp
rm -rf $null $dir $other_partition_tmpdir out out2 exp
exit $fail

52
tests/mv/partition-perm Executable file
View File

@@ -0,0 +1,52 @@
#!/bin/sh
# Make sure permissions are preserved when moving from one partition to another.
if test "$VERBOSE" = yes; then
set -x
mv --version
fi
. $srcdir/setup
if test -z "$other_partition_tmpdir"; then
exit 77
fi
LANGUAGE=C; export LANGUAGE
LANG=C; export LANG
pwd=`pwd`
dir=p-perm-$$
trap "cd $pwd; rm -rf $dir $other_partition_tmpdir" 0 1 2 3 15
mkdir $dir
unset VERSION_CONTROL SIMPLE_BACKUP_SUFFIX
if test "${VERSION_CONTROL+set}" = set; then
echo '$0: the VERSION_CONTROL envvar is set --' \
' unset it and rerun this test' >&2
exit 1
fi
if test "${SIMPLE_BACKUP_SUFFIX+set}" = set; then
echo '$0: the SIMPLE_BACKUP_SUFFIX envvar is set --' \
' unset it and rerun this test' >&2
>&2
exit 1
fi
cd $dir
: > file
chmod a=rwx file
umask 777
mv file $other_partition_tmpdir
fail=0
test -f file && fail=1
test -f $other_partition_tmpdir/file || fail=1
# This would have failed with the mv from fileutils-4.0i.
test -r $other_partition_tmpdir/file || fail=1
exit $fail

View File

@@ -4,9 +4,6 @@
# of the current directory. If one is found, create a temporary directory
# inside it.
: ${DF=df}
: ${MKDIR=mkdir}
: ${CANDIDATE_TMP_DIRS=not_set}
# Work around a bug in the way Ultrix4.3a's /bin/sh handles multi-word
@@ -18,15 +15,15 @@ other_partition_tmpdir=
# WARNING: using sed like this to extract the mount point will fail
# if the mount point name contains `% '.
dot_mount_point=`$DF --no-sync -P . | sed -n '2s/.*% *//p'`
dot_mount_point=`df --no-sync -P . | sed -n '2s/.*% *//p'`
for d in $CANDIDATE_TMP_DIRS; do
d_mount_point=`$DF --no-sync -P $d | sed -n '2s/.*% *//p'`
d_mount_point=`df --no-sync -P $d | sed -n '2s/.*% *//p'`
# Same partition? Skip it.
test x$d_mount_point = x$dot_mount_point && continue
# See if we can create a directory in it.
if $MKDIR "$d/df-$$" > /dev/null 2>&1; then
if mkdir "$d/df-$$" > /dev/null 2>&1; then
other_partition_tmpdir="$d/df-$$"
break
fi

50
tests/mv/to-symlink Executable file
View File

@@ -0,0 +1,50 @@
#!/bin/sh
# Make sure that the copying code used in an inter-partition
# move unlinks a destination symlink before opening it.
if test "$VERBOSE" = yes; then
set -x
mv --version
fi
. $srcdir/setup
if test -z "$other_partition_tmpdir"; then
exit 77
fi
rem_file="$other_partition_tmpdir/file"
rem_symlink="$other_partition_tmpdir/symlink"
file=to-sym-$$
fail=0
trap 'rm -fr $file $other_partition_tmpdir; exit $fail' 0 1 2 3 15
framework_failure=0
rm -f $file || framework_failure=1
echo local > $file || framework_failure=1
echo remote > $rem_file || framework_failure=1
ln -s $rem_file $rem_symlink || framework_failure=1
if test $framework_failure = 1; then
echo 'failure in testing framework'
exit 1
fi
unset VERSION_CONTROL
if test "${VERSION_CONTROL+set}" = set; then
echo '$0: the VERSION_CONTROL envvar is set --' \
' unset it and rerun this test' >&2
exit 1
fi
# This mv command should succeed, unlinking the symlink
# before copying.
mv $file $rem_symlink || fail=1
# Make sure $rem_file is unmodified.
test `cat $rem_file` = remote || fail=1
exit $fail