Bug#568834: First stab at functionality for copying files

2023-06-09 Thread Benj. Mako Hill
Greetings!

This is just a followup to say that I've been using the patch for
about two years now and have not noticed any trouble. I use the
copying files functionality in vidir nearly every day!

If someone wants to take a more active role in maintaince and needs a
hand, let me know.

Regards,
Mako



> 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
> https://mako.cc/





-- 
Benjamin Mako Hill
https://mako.cc/


signature.asc
Description: PGP signature


Bug#568834: First stab at functionality for copying files

2021-04-02 Thread Benj. Mako Hill
Greetings!


> 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.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,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