From fdc7371f0e9b53720a01efbd40de83d1f4d530b0 Mon Sep 17 00:00:00 2001 From: Ward Wouts Date: Thu, 12 Dec 2002 10:05:00 +0000 Subject: [PATCH] fail more flexibly --- mvwrap/mvwrap | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/mvwrap/mvwrap b/mvwrap/mvwrap index f088051..151c6ea 100755 --- a/mvwrap/mvwrap +++ b/mvwrap/mvwrap @@ -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,8 +258,12 @@ 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;