fail more flexibly
This commit is contained in:
parent
445c789564
commit
fdc7371f0e
1 changed files with 15 additions and 6 deletions
|
|
@ -28,7 +28,9 @@ if (@pattern) {
|
|||
&read_temp($temp_file);
|
||||
}
|
||||
|
||||
&run_checks;
|
||||
if ( &run_checks ) {
|
||||
&cdie("Aborting\n");
|
||||
}
|
||||
|
||||
# if it's unsafe to move files directly, move the unsafe ones to a
|
||||
# temporary file first
|
||||
|
|
@ -136,22 +138,25 @@ sub run_checks {
|
|||
my $line;
|
||||
|
||||
unless ( scalar(@source) == scalar(@target) ) {
|
||||
&cdie("Aborting. Source and target list don't have the same number of lines.\n");
|
||||
print "ERROR: Source and target list don't have the same number of lines.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
foreach $line (@target) {
|
||||
if ( $line =~ m/^$/ ) {
|
||||
&cdie("Aborting. You can't move to empty names.\n");
|
||||
print "ERROR: You can't move to empty names.\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ( &check_unique(@target) ) {
|
||||
&which_doubles(@source, @target);
|
||||
&cdie("Aborting. You're trying to move multiple files to the same name.\n");
|
||||
print "ERROR: You're trying to move multiple files to the same name.\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($paranoia) { # extra checks for a specified list of files
|
||||
¶noia(\@source, \@target);
|
||||
if ( ¶noia(\@source, \@target) ) { return 1; }
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -253,9 +258,13 @@ sub paranoia($$) {
|
|||
foreach $csource (@$source) {
|
||||
if ($ctarget eq $csource) { $safe = 1; }
|
||||
}
|
||||
if (! $safe && -e $ctarget) { &cdie("That would overwrite files\n"); }
|
||||
if (! $safe && -e $ctarget) {
|
||||
print "ERROR: That would overwrite files\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
# lock, unlock and cdie are the only subs that should use die;
|
||||
# all others should use &cdie. A handler for this would probably
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue