#!/usr/bin/perl use File::Find; use File::stat; use Fcntl ':mode'; find sub { if ($_ eq '.svn') { $File::Find::prune = 1; return; } my $target = $ENV{HOME} . "/" . $File::Find::name; my $st_source = lstat($_); my $st_target = stat($target); if (S_ISDIR($st_source->mode)) { if (!$st_target) { print STDERR "mkdir $target\n"; mkdir $target or die "cannot make dir $target: $!"; } } elsif (S_ISREG($st_source->mode)) { if (!$st_target || $st_source->mtime > $st_target->mtime) { print STDERR "copy $File::Find::name to $target\n"; open(my $in, '<', $_) or die "cannot open $_: $!"; open(my $out, '>', "$target.$$") or die "cannot open $target.$$: $!"; while (<$in>) { print $out $_; } close($out) or die "cannot close $target.$$: $!"; rename("$target.$$", $target) or die "cannot rename $target.$$ to $target: $!"; } } else { die "cannot handle $File::Find::name\n"; } }, ".";