From: Zygo Blaxell Date: Tue, 18 May 2010 12:30:08 +0000 (-0400) Subject: dm6: Detect when rename fails to clean up $tmp_to X-Git-Tag: dm6-0.20100518~1 X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=dupemerge;a=commitdiff_plain;h=d4d387b85ba81deb83ec60a8e41f546f58136b20 dm6: Detect when rename fails to clean up $tmp_to (cherry picked from commit 03d938d317f1660e7c4f1f228768733c98dff1bf) --- diff --git a/dm6 b/dm6 index 4cd11b0..8638e28 100755 --- a/dm6 +++ b/dm6 @@ -58,12 +58,15 @@ sub link_files { print STDERR "\bL"; link($from, $tmp_to) or die "link: $from -> $tmp_to: $!"; print STDERR "\bR"; - unless (rename($tmp_to, $to)) { - my $saved_bang = $!; - print STDERR "\bU"; - unlink($tmp_to) or warn "unlink: $tmp_to: $!"; # Try, possibly in vain, to clean up - die "rename: $tmp_to -> $from: $saved_bang"; - } + my $saved_bang; + $saved_bang = $! unless rename($tmp_to, $to); + + # If $to exists and is a hardlink to $tmp_to (or $from), + # rename returns success but $tmp_to still exists. + print STDERR "\bU"; + unlink($tmp_to) or warn "unlink: $tmp_to: $!" if -e $tmp_to; + + die "rename: $tmp_to -> $from: $saved_bang" if $saved_bang; print STDERR "\b"; }