Greetings! <quote who="Benj. Mako Hill" date="Fri, Apr 02, 2021 at 04:58:28PM -0700"> > It's been quite a while since I've written Perl and I'm not 100% sure > that I've thought the logic through completely so as to avoid all > possible corner cases (e.g., related to every way one would swap > filenames and/or copy things repeatedly).
I'm attaching an updated and better version of the patch. It's stylistically more consistent and fixes at least one bug/corner case. It's obviously still be good to have someone look at it and think through through this a little before it's applied. In any case, I'm using it now and will try to stress test it and figure out what the corner cases are. Later, Mako -- Benjamin Mako Hill https://mako.cc/
--- /home/mako/bin/vidir 2021-04-02 17:24:01.718977602 -0700 +++ /usr/bin/vidir 2019-08-18 06:27:38.000000000 -0700 @@ -81,7 +81,6 @@ use File::Path qw(make_path); use File::Spec; use File::Temp; -use File::Copy; use Getopt::Long; my $error=0; @@ -144,7 +143,6 @@ die "@editor exited nonzero, aborting\n"; } -my %finished_item; open (IN, $tmp->filename) || die "$0: cannot read ".$tmp->filename.": $!\n"; while (<IN>) { chomp; @@ -152,26 +150,7 @@ my $num=int($1); my $name=$2; if (! exists $item{$num}) { - # attempt to copy files if a duplicate of a number we've already seen before - if (exists $finished_item{$num}) { - if ($name eq $finished_item{$num}) { - print STDERR "$0: cannot copy because source ($finished_item{$num}) and destination ($name) are the same\n"; - } - elsif (-e $name || -l $name) { - print STDERR "$0: cannot copy because destination ($name) already exists\n"; - } - elsif (! (-e $finished_item{$num} || -l $finished_item{$num})) { - print STDERR "$0: cannot copy because source ($finished_item{$num}) does not exist\n"; - } - elsif (! copy($finished_item{$num}, $name)) { - print STDERR "$0: failed to copy $finished_item{$num} to $name: $!\n"; - $error=1; - } - next; - } - else { - die "$0: unknown item number $num\n"; - } + die "$0: unknown item number $num\n"; } elsif ($name ne $item{$num}) { next unless length $name; @@ -227,7 +206,6 @@ } } } - $finished_item{$num} = $name; delete $item{$num}; } elsif (/^\s*$/) {
signature.asc
Description: PGP signature