fail more flexibly

This commit is contained in:
Ward Wouts 2002-12-12 10:05:00 +00:00
parent 445c789564
commit fdc7371f0e

View file

@ -28,7 +28,9 @@ if (@pattern) {
&read_temp($temp_file); &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 # if it's unsafe to move files directly, move the unsafe ones to a
# temporary file first # temporary file first
@ -136,22 +138,25 @@ sub run_checks {
my $line; my $line;
unless ( scalar(@source) == scalar(@target) ) { 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) { foreach $line (@target) {
if ( $line =~ m/^$/ ) { 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) ) { if ( &check_unique(@target) ) {
&which_doubles(@source, @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 if ($paranoia) { # extra checks for a specified list of files
&paranoia(\@source, \@target); if ( &paranoia(\@source, \@target) ) { return 1; }
} }
return 0; return 0;
} }
@ -253,8 +258,12 @@ sub paranoia($$) {
foreach $csource (@$source) { foreach $csource (@$source) {
if ($ctarget eq $csource) { $safe = 1; } 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; # lock, unlock and cdie are the only subs that should use die;