- writefile($file, $config{destdir}, $content, 1);
- $oldpagemtime{$file}=time;
+
+ if ($config{hardlink}) {
+ prep_writefile($file, $config{destdir});
+ unlink($config{destdir}."/".$file);
+ if (link($srcfile, $config{destdir}."/".$file)) {
+ return;
+ }
+ # if hardlink fails, fall back top copying
+ }
+
+ my $srcfd=readfile($srcfile, 1, 1);
+ writefile($file, $config{destdir}, undef, 1, sub {
+ my $destfd=shift;
+ my $cleanup=shift;
+
+ my $blksize = 16384;
+ my ($len, $buf, $written);
+ while ($len = sysread $srcfd, $buf, $blksize) {
+ if (! defined $len) {
+ next if $! =~ /^Interrupted/;
+ error("failed to read $srcfile: $!", $cleanup);
+ }
+ my $offset = 0;
+ while ($len) {
+ defined($written = syswrite $destfd, $buf, $len, $offset)
+ or error("failed to write $file: $!", $cleanup);
+ $len -= $written;
+ $offset += $written;
+ }
+ }
+ });