diff --git a/safe_mv/safe_mv b/safe_mv/safe_mv index 21ed553..06a2c67 100755 --- a/safe_mv/safe_mv +++ b/safe_mv/safe_mv @@ -44,20 +44,28 @@ sub help { sub compare($source, $target) { my ($source_size, $target_size); + my (@source_stat, @target_stat); print "Comparing... "; # First compare size. If this differs, we're done quickly. if ( (-s $source) == (-s $target) ) { - if ( $DEBUG ) { print "$source and $target are the same size\n"; } - $source_digest = &calc_md5($source); - if ( $DEBUG ) { print "source digest $source_digest\n"; } - $target_digest = &calc_md5($target); - if ( $DEBUG ) { print "source digest $target_digest\n"; } - if ( $source_digest eq $target_digest ) { - print "Files are the same. Deleting $source.\n"; - unlink($source) - or die "Can't delete $source: $!\n"; + @source_stat = stat $source; + @target_stat = stat $target; + if (( $source_stat[1] == $target_stat[1] ) && + ( $source_stat[0] == $target_stat[0] )) { + print "Skipped $source & $target are one and the same!\n" } else { - print "Skipped mv $source -> $target files differ\n" + if ( $DEBUG ) { print "$source and $target are the same size\n"; } + $source_digest = &calc_md5($source); + if ( $DEBUG ) { print "source digest $source_digest\n"; } + $target_digest = &calc_md5($target); + if ( $DEBUG ) { print "source digest $target_digest\n"; } + if ( $source_digest eq $target_digest ) { + print "Files are the same. Deleting $source.\n"; + unlink($source) + or die "Can't delete $source: $!\n"; + } else { + print "Skipped mv $source -> $target files differ\n" + } } } else { print "Skipped mv $source -> $target files differ\n";