[EMAIL PROTECTED] (Eric Blake) wrote:
>> Once it knows the target (b) is a directory, if you're using -T, mv knows
>> that it must fail -- rename ("anything", "directory") will always fail.
>
> Only if "directory" is not empty.
or if the "old argument" is a non-directory.
> POSIX requires "If the old argument
> points to the pathname of a directory, the new argument shall not
> point to the pathname of a file that is not a directory. If the directory
> named by the new argument exists, it shall be removed and old
> renamed to new. In this case, a link named new shall exist throughout
> the renaming operation and shall refer either to the directory referred
> to by new or old before the operation began. If new names an existing
> directory, it shall be required to be an empty directory."
>
> Therefore, we have found another 'mv -f -T' bug:
>
> $ mkdir dir other
> $ mv -fT other dir
>
> should succeed, not fail.
Yes. Thanks.
Before
$ rm -rf e d; mkdir d e; ./mv -T d e
./mv: cannot overwrite directory `e'
After:
$ rm -rf e d; mkdir d e; ./mv -T d e
$
Here's the patch:
2006-05-11 Jim Meyering <[EMAIL PROTECTED]>
* Version 6.0-cvs.
mv -T DIR EMPTY_DIR no longer fails unconditionally
* src/copy.c (copy_internal): Don't manually prohibit a move where
the destination is an existing directory. Sometimes doing that is
valid. Let the rename system call enforce the rules. That is
allowed only when the source is a directory and the destination
directory (to be replaced) is empty. Reported by Eric Blake.
* tests/mv/no-target-dir: New file/test for this.
* tests/mv/Makefile.am (TESTS): Add no-target-dir.
* NEWS: Mention this.
Index: src/copy.c
===================================================================
RCS file: /fetish/cu/src/copy.c,v
retrieving revision 1.198
retrieving revision 1.199
diff -u -p -u -r1.198 -r1.199
--- src/copy.c 11 May 2006 07:33:00 -0000 1.198
+++ src/copy.c 11 May 2006 08:55:04 -0000 1.199
@@ -1157,14 +1157,6 @@ copy_internal (char const *src_name, cha
if (x->move_mode)
{
- /* In move_mode, DEST may not be an existing directory. */
- if (S_ISDIR (dst_sb.st_mode) && x->backup_type == no_backups)
- {
- error (0, 0, _("cannot overwrite directory %s"),
- quote (dst_name));
- return false;
- }
-
/* Don't allow user to move a directory onto a non-directory. */
if (S_ISDIR (src_sb.st_mode) && !S_ISDIR (dst_sb.st_mode)
&& x->backup_type == no_backups)
_______________________________________________
Bug-coreutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-coreutils