summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess <joey@kodama.kitenet.net>2008-07-01 00:42:23 -0400
committerJoey Hess <joey@kodama.kitenet.net>2008-07-01 00:42:23 -0400
commit0f8ea7ecca27a9e73af5c515f637f543912c7076 (patch)
treef524b9b06cf95e508a7061de35fbe8595956f51a
parent2ca1e12c5f8d74d0604150f25955e0d32529e5b8 (diff)
break out fast_file_copy
-rw-r--r--IkiWiki/Render.pm43
1 files changed, 25 insertions, 18 deletions
diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm
index 272eb239a..2cdec421f 100644
--- a/IkiWiki/Render.pm
+++ b/IkiWiki/Render.pm
@@ -180,6 +180,30 @@ sub scan ($) { #{{{
}
} #}}}
+sub fast_file_copy ($$$$$) { #{{{
+ my $srcfile=shift;
+ my $destfile=shift;
+ my $srcfd=shift;
+ 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 $destfile: $!", $cleanup);
+ $len -= $written;
+ $offset += $written;
+ }
+ }
+}
+
sub render ($) { #{{{
my $file=shift;
@@ -215,24 +239,7 @@ sub render ($) { #{{{
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;
- }
- }
+ fast_file_copy($srcfile, $file, $srcfd, @_);
});
}
} #}}}