don't delete if source and target are the same file (inode/filesystem)
This commit is contained in:
parent
692ec451fe
commit
23e4c0e01b
1 changed files with 18 additions and 10 deletions
|
|
@ -44,9 +44,16 @@ sub help {
|
||||||
|
|
||||||
sub compare($source, $target) {
|
sub compare($source, $target) {
|
||||||
my ($source_size, $target_size);
|
my ($source_size, $target_size);
|
||||||
|
my (@source_stat, @target_stat);
|
||||||
print "Comparing... ";
|
print "Comparing... ";
|
||||||
# First compare size. If this differs, we're done quickly.
|
# First compare size. If this differs, we're done quickly.
|
||||||
if ( (-s $source) == (-s $target) ) {
|
if ( (-s $source) == (-s $target) ) {
|
||||||
|
@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 {
|
||||||
if ( $DEBUG ) { print "$source and $target are the same size\n"; }
|
if ( $DEBUG ) { print "$source and $target are the same size\n"; }
|
||||||
$source_digest = &calc_md5($source);
|
$source_digest = &calc_md5($source);
|
||||||
if ( $DEBUG ) { print "source digest $source_digest\n"; }
|
if ( $DEBUG ) { print "source digest $source_digest\n"; }
|
||||||
|
|
@ -59,6 +66,7 @@ sub compare($source, $target) {
|
||||||
} else {
|
} else {
|
||||||
print "Skipped mv $source -> $target files differ\n"
|
print "Skipped mv $source -> $target files differ\n"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
print "Skipped mv $source -> $target files differ\n";
|
print "Skipped mv $source -> $target files differ\n";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue