diff options
author | Ken Booth <ken@booths.org.uk> | 2013-07-02 01:06:32 +0100 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2013-07-25 16:45:02 +0100 |
commit | 2bdb74ec1a453f6c6084d042e573de436ec205f3 (patch) | |
tree | 08f8c9fdc929321f414b8e1355643e13a78271ea /src/copy.c | |
parent | 68e5e8886170a3c2af88f830f2ac36100a9a610b (diff) | |
download | coreutils-2bdb74ec1a453f6c6084d042e573de436ec205f3.tar.xz |
mv: replace empty directories in cross file system move
src/copy.c (copy_internal): Use rmdir() rather than unlink()
when the source is a directory, so that empty directories
are replaced in the destination as per POSIX.
* tests/mv/part-rename.sh: Augment with various combinations.
* NEWS: Mention the bug fix.
Fixes http://bugs.gnu.org/14763
Diffstat (limited to 'src/copy.c')
-rw-r--r-- | src/copy.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/copy.c b/src/copy.c index c1c82730d..f0cebb1b1 100644 --- a/src/copy.c +++ b/src/copy.c @@ -2172,8 +2172,12 @@ copy_internal (char const *src_name, char const *dst_name, /* 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_name) != 0 && errno != ENOENT) + the rename syscall. Note both src and dst must both be directories + or not, and this is enforced above. Therefore we check the src_mode + and operate on dst_name here as a tighter constraint and also because + src_mode is readily available here. */ + if ((S_ISDIR (src_mode) ? rmdir (dst_name) : unlink (dst_name)) != 0 + && errno != ENOENT) { error (0, errno, _("inter-device move failed: %s to %s; unable to remove target"), |