diff --git a/mvwrap/mvwrap b/mvwrap/mvwrap index f85e6e0..6f02718 100755 --- a/mvwrap/mvwrap +++ b/mvwrap/mvwrap @@ -29,12 +29,17 @@ if (@pattern) { &run_checks; +if ($paranoia) { # extra checks for a specified list of files + ¶noia(\@source, \@target); +} + # if it's unsafe to move files directly, move the unsafe ones to a # temporary file first if (@unsafe = &check_safety(\@source, \@target)) { &safety_belt(\@unsafe, \@source); } + &move_files(\@source, \@target); if ( -e ".mv_wrap" ) { unlink (".mv_wrap"); } @@ -191,6 +196,22 @@ sub safety_belt { } } +# Extra safety checks when one's useing a specified list of files +# Must be called like: +# paranoia(\@unsafe, \@source) +sub paranoia { + my ($source, $target) =@_; + my $safe; + foreach $ctarget (@$target) { + $safe = 0; + foreach $csource (@$source) { + if ($ctarget eq $csource) { $safe = 1; } + } + chomp $ctarget; + if (! $safe && -e $ctarget) { die "That would overwrite files\n"; } + } +} + sub lock { if ( -e ".mv_wrap") { die "Another mv_wrap process is active in this direcory\n" @@ -217,6 +238,7 @@ sub cmdline { foreach (@ARGV) { push @source, "$_\n"; } + $paranoia = 1; } } @@ -237,6 +259,9 @@ At the moment it takes the following options: -p use a pattern to edit; ignored if -f is given -f use a pattern file to edit +Specifying fiels on the command line is still unsafe! There are no checks +to prevent overwriting non-specified files! + EOT exit; }