+ if ($writer) {
+ $writer->(\*OUT, $cleanup);
+ }
+ else {
+ print OUT $content || error("failed writing to $newfile: $!", $cleanup);
+ }
+ close OUT || error("failed saving $newfile: $!", $cleanup);
+ rename($newfile, "$destdir/$file") ||
+ error("failed renaming $newfile to $destdir/$file: $!", $cleanup);