performance_string("> writefile for $caller on $file, data size $exp_len: ", keyspew($args)) if $GLOBAL_OPTIONS->{performance_monitoring};
$PARAMS->{file_access}->{$file}->{write}++;
$PARAMS->{files_written}++;
$PARAMS->{file_access}->{$file}->{read} += 0;
lock($file) if !$args->{no_lock};
$args->{no_backup} = 1 if $GLOBAL_OPTIONS->{quota_check_off};
if (!$args->{no_backup}) {
open (FILE, "> $DCONF->{admin_dir}/backups/$unique_string-$shortfile") || error_message("Open[w] file error", "Couldn't open temporary file backups/$unique_string-$shortfile for [$caller]!");
binmode(FILE);
print FILE $str;
close (FILE);
my $size1 = -s "$DCONF->{admin_dir}/backups/$unique_string-$shortfile";
performance_string(" Backup file write for backups/$unique_string-$shortfile, size $size1 (expected $exp_len)") if $GLOBAL_OPTIONS->{performance_monitoring};
quota_err($shortfile, $exp_len, $size1) if $exp_len > $size1;
}
open (FILE, "> $file") || error_message("Open[w] file error", "Couldn't open file [$shortfile] for update for [$caller]!");
binmode(FILE);
print FILE $str;
close (FILE);
performance_string(" Wrote $file for $caller, size ", -s $file) if $GLOBAL_OPTIONS->{performance_monitoring};
chmod (oct($DCONF->{perms0666}), $file);
unlock($file) if !$args->{no_unlock};
if (!$args->{no_sizecheck} && !$GLOBAL_OPTIONS->{quota_check_off}) {
my $size2 = -s $file;
quota_err($shortfile, $exp_len, $size2) if $exp_len > $size2;