-
- my $fh=$q->upload('attachment');
- if (! defined $fh || ! ref $fh) {
- error("failed to get filehandle");
- }
- binmode($fh);
- while (<$fh>) {
- print STDERR $_."\n";
+
+ # Move the attachment into place.
+ # Try to use a fast rename; fall back to copying.
+ prep_writefile($filename, $config{srcdir});
+ unlink($config{srcdir}."/".$filename);
+ if (! rename($tempfile, $config{srcdir}."/".$filename)) {
+ my $fh=$q->upload('attachment');
+ if (! defined $fh || ! ref $fh) {
+ error("failed to get filehandle");
+ }
+ binmode($fh);
+ writefile($filename, $config{srcdir}, undef, 1, sub {
+ IkiWiki::fast_file_copy($tempfile, $filename, $fh, @_);
+ });