Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
*put_data = \&_write_file; sub _write_file { my $fmgr = shift; my($from, $to, $type) = @_; local *FH; my($umask, $perms); my $cfg = MT->config; if ($type && $type eq 'upload') { $umask = $cfg->UploadUmask; $perms = $cfg->UploadPerms; } else { $umask = $cfg->HTMLUmask; $perms = $cfg->HTMLPerms; } my $old = umask(oct $umask); sysopen FH, $to, O_RDWR|O_CREAT|O_TRUNC, oct $perms or return $fmgr->error(MT->translate( "Opening local file '[_1]' failed: [_2]", $to, "$!")); if ($type && $type eq 'upload') { binmode(FH); binmode($from) if $fmgr->is_handle($from); } ## Lock file unless NoLocking specified. flock FH, LOCK_EX unless $cfg->NoLocking; seek FH, 0, 0; truncate FH, 0; my $bytes = 0; if ($fmgr->is_handle($from)) { while (my $len = read $from, my($block), 8192) { print FH $block; $bytes += $len; } } else { print FH $from; $bytes = length($from); } close FH; umask($old); $bytes; }
This paste will be private.
From the Design Piracy series on my blog: