use strict; use warnings; use Smart::Comments; use lib 'tools'; require 'utils.pl'; use File::Spec; use File::Compare qw(compare); use File::Copy qw(copy); use File::Path qw(mkpath); sub main { while (defined(my $arg = <>)) { chomp $arg; my $rel = File::Spec->file_name_is_absolute($arg) ? File::Spec->abs2rel($arg, $ENV{HOME}) : $arg; my $abs = File::Spec->rel2abs($rel, $ENV{HOME}); my $saved = rel2saved($rel); if (!-e $saved) { print "SKIP: $rel is not in the repository.\n"; next; } elsif (-e $abs) { if (compare($abs, $saved) == 0) { print "SKIP: $rel is identical to the copy in the repository.\n"; } else { print "SKIP: $rel is different from the copy in the repository.\n"; } } else { print "Copying $saved to $abs...\n"; my @path = File::Spec->splitdir($abs); pop @path; mkpath(File::Spec->catdir(@path)); copy($saved, $abs) or die $!; } } } main();