From 63feb84a2db5246fb71df45884589b914679110c Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Wed, 19 Mar 2008 13:37:04 +0100 Subject: mv: never unlink a destination file before calling rename While cp --preserve=links must unlink certain destination files, mv must never do that. * src/copy.c (copy_internal): Pull the '! x->move_mode' test "up", so it affects the entire condition, and not just DEREF_NEVER mode. Reported by James Ralston in . * tests/mv/atomic2: New file. Test for the above fix. * tests/mv/Makefile.am (TESTS): Add atomic2. * NEWS: Mention the bug-fix. [Bug introduced in 367719ba5f1dbd5e2f7fa2466c441f23f66a7c9e] --- src/copy.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/copy.c b/src/copy.c index fd31b5c91..208a67413 100644 --- a/src/copy.c +++ b/src/copy.c @@ -1339,10 +1339,11 @@ copy_internal (char const *src_name, char const *dst_name, new_dst = true; } else if (! S_ISDIR (dst_sb.st_mode) + /* Never unlink dst_name when in move mode. */ + && ! x->move_mode && (x->unlink_dest_before_opening || (x->preserve_links && 1 < dst_sb.st_nlink) - || (!x->move_mode - && x->dereference == DEREF_NEVER + || (x->dereference == DEREF_NEVER && S_ISLNK (src_sb.st_mode)) )) { -- cgit v1.2.3-70-g09d2