tags 882872 patch
thanks
Greetings!
Thanks for maintaining moreutils! It's one of the packages I love most
in Debian!
I'm attaching a first stab a patch to add copying file support to
vidir (i.e., #882872) which is something I've wanted for a very long
time and just broke down and did today.
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).
The way it works is much simpler than the model suggested in #568834,
(which, BTW, sounds very nice): If a line number shows up twice in the
vidir output—and if the two filenames associated with the lines
numbers—are different, the file gets copied. That's it. :)
Regards,
Mako
--
Benjamin Mako Hill
https://mako.cc/
--- /home/mako/bin/vidir 2021-04-02 16:48:20.646390946 -0700
+++ /usr/bin/vidir 2019-08-18 06:27:38.0 -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 () {
chomp;
@@ -152,24 +150,7 @@
my $num=int($1);
my $name=$2;
if (! exists $item{$num}) {
- # copy files if a dupliate 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";
- delete $item{$num};
-} elsif (-e $name || -l $name) {
- print STDERR "$0: cannot copy because destination ($name) already exists\n";
- delete $item{$num};
-} elsif (! (-e $finished_item{$num} || -l $finished_item{$num})) {
- print STDERR "$0: cannot copy because $finished_item{$num} does not exist\n";
- delete $item{$num};
-} elsif (! copy($finished_item{$num}, $name)) {
- print STDERR "$0: failed to copy $finished_item{$num} to $name: $!\n";
- $error=1;
-}
- } else {
-die "$0: unknown item number $num\n";
- }
+ die "$0: unknown item number $num\n";
}
elsif ($name ne $item{$num}) {
next unless length $name;
@@ -225,7 +206,6 @@
}
}
}
- $finished_item{$num} = $name;
delete $item{$num};
}
elsif (/^\s*$/) {
signature.asc
Description: PGP signature