@ -4,14 +4,30 @@ use warnings;
use strict;
use 5.10.0;
use App::MarkFiles qw(each_path remove);
use App::MarkFiles qw(each_path remove check_collisions );
use File::Basename;
use File::Copy;
use File::Spec;
use Getopt::Long;
use Pod::Usage;
my @unmark;
my $dry_run;
GetOptions(
'no-action|dry-run|n' => \$dry_run,
help => sub { pod2usage(0) },
) or pod2usage(2);
my (@collisions) = check_collisions();
if (scalar @collisions) {
# We got something. Alert the user and bail.
say "Multiple marked paths would move to the following filenames:";
say join "\n", @collisions;
say "";
say "No action taken, since this probably isn't what you want.";
exit(1);
}
my @unmark;
each_path(sub {
my ($path) = @_;
@ -25,27 +41,12 @@ each_path(sub {
if (-e $target) {
say "Warning: $path will overwrite $target";
}
# So here's the question. What do we do if the target exists?
#
# There are a couple of cases here:
#
# 1. Our mark list contains a file of the same name as something already in
# the destination directory.
#
# 2. Our mark list contains the same filename more than once.
#
# These seem like distinct problems, to a degree. #1 is effectively
# standard unix behavior, and I'm not sure we need to protect the user from
# it unless they ask us to with a -i option or something. #2 is more
# problematic. No matter what you do, you're likely to wind up with
# unexpected outcomes.
#
# We could refuse to operate unless a "rename duplicates" option is
# invoked, or just interactively solve each collision. This seems most
# pressing for mark-mv, since it could easily result in data loss by
# cascading a set of moves where you wind up with just one source file
# left anywhere.
if ($dry_run) {
say "Would move: $path";
push @unmark, $path;
return;
}
if (move($path, $target)) {
@ -56,4 +57,8 @@ each_path(sub {
}
});
remove(@unmark);
if ($dry_run) {
say "Would remove marks from: " . join ', ', @unmark;
} else {
remove(@unmark);
}