#!/usr/bin/perl -d # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # # cpnew dir file... # # # # This compares the files with those of the same name in dir, and if any # # $file is newer than $dir/$file, it is copied. The intended use is to # # "download" local files to a remote directory, but only for those that have # # been edited and are newer than their version in the remote directory. # # # # Note that the copying is done via Lc so the old versions will be backed up. # # This can cause problems for multiply-linked file schemes. # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # $dir = shift; die "Usage: $0 dir file...\n" if (! -d $dir); foreach $f1 (@ARGV) { $t1 = -M "$f1"; $ff = $f1; $ff =~ s'.*/''g; $f2 = "$dir/$ff"; $t2 = -M "$f2"; if (-f "$f1") { if (-f "$f2") { if (-M "$f1" < -M "$f2") { print "Lc $f1 $f2\n"; system "Lc $f1 $f2"; } # if (-M "$f1" > -M "$f2") { # print STDERR "$f1 older than $f2\n"; # } } else { # print STDERR "Create \"$f1\"\n"; print "Lc $f1 $f2\n"; system "Lc $f1 $f2"; } } else { print STDERR "No file \"$f1\"\n"; } }