in case of doubles, show which files are the culprits
This commit is contained in:
parent
f5edf6e384
commit
dbe4afb325
1 changed files with 19 additions and 1 deletions
|
|
@ -150,12 +150,13 @@ sub run_checks {
|
|||
}
|
||||
|
||||
if ( &check_unique(@target) ) {
|
||||
&which_doubles(@source, @target);
|
||||
&cdie("Aborting. You're trying to move multiple files to the same name.\n");
|
||||
}
|
||||
}
|
||||
|
||||
# returns 0 if all entries in @target_list are unique. 1 if not.
|
||||
sub check_unique (@){
|
||||
sub check_unique (@) {
|
||||
my @uniqu;
|
||||
my @target_list = @_;
|
||||
my %seen = ();
|
||||
|
|
@ -163,6 +164,23 @@ sub check_unique (@){
|
|||
return (scalar(@uniqu) != scalar(@target))
|
||||
}
|
||||
|
||||
sub which_doubles () {
|
||||
my %selector = ();
|
||||
foreach $i (0 .. $#target) {
|
||||
if ( exists $selector{$target[$i]} ) {
|
||||
push @{$selector{$target[$i]}}, $i;
|
||||
} else {
|
||||
$selector{$target[$i]} = [$i];
|
||||
}
|
||||
}
|
||||
foreach (keys %selector) {
|
||||
if ( scalar(@{$selector{$_}}) > 1 ) {
|
||||
print "Doubles detected:\n";
|
||||
map {print "$source[$_] -> $target[$_]\n";} @{$selector{$_}};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Compares one array of file names to another, making sure files
|
||||
# can be moved safely without overwriting each other
|
||||
# Must be called like:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue