ok, specifying files should be safe now

This commit is contained in:
Ward Wouts 2001-08-30 12:52:02 +00:00
parent 5c90dfb045
commit ca5438d012

View file

@ -29,12 +29,17 @@ if (@pattern) {
&run_checks;
if ($paranoia) { # extra checks for a specified list of files
&paranoia(\@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 <pattern> use a pattern to edit; ignored if -f is given
-f <file> 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;
}