From bb559d588fe22214c1fef1bea359328cf2fe7c7f Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Wed, 18 Apr 2007 23:34:54 +0000 Subject: [PATCH] Don't flush files opened for reading only --- postfix/postfix-lib.pl | 2 +- web-lib-funcs.pl | 23 ++++++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/postfix/postfix-lib.pl b/postfix/postfix-lib.pl index 0dc512143..ac5abe9a4 100644 --- a/postfix/postfix-lib.pl +++ b/postfix/postfix-lib.pl @@ -114,7 +114,7 @@ sub get_current_value { # First try to get the value from main.cf directly my ($name,$key)=split /:/,$_[0]; -my $lref = &read_file_lines($config{'postfix_config_file'}); +my $lref = &read_file_lines($config{'postfix_config_file'}, 1); my $out; foreach my $l (@$lref) { if ($l =~ /^\s*([a-z0-9\_]+)\s*=\s*(.*)/ && diff --git a/web-lib-funcs.pl b/web-lib-funcs.pl index f31d4724a..aa7ac7d67 100755 --- a/web-lib-funcs.pl +++ b/web-lib-funcs.pl @@ -1874,7 +1874,7 @@ else { splice(@lines, $_[1], 1); } &close_tempfile(FILE); } -# read_file_lines(file) +# read_file_lines(file, [readonly]) # Returns a reference to an array containing the lines from some file. This # array can be modified, and will be written out when flush_file_lines() # is called. @@ -1894,12 +1894,14 @@ if (!$main::file_cache{$realfile}) { } close(READFILE); $main::file_cache{$realfile} = \@lines; + $main::file_cache_noflush{$realfile} = $_[1]; } return $main::file_cache{$realfile}; } # flush_file_lines([file], [eol]) -# Write out to a file previously read by read_file_lines to disk +# Write out to a file previously read by read_file_lines to disk (except +# for those marked readonly). sub flush_file_lines { local $f; @@ -1915,14 +1917,17 @@ else { } local $eol = $_[1] || "\n"; foreach $f (@files) { - &open_tempfile(FLUSHFILE, ">$f"); - local $line; - foreach $line (@{$main::file_cache{$f}}) { - (print FLUSHFILE $line,$eol) || - &error(&text("efilewrite", $f, $!)); - } - &close_tempfile(FLUSHFILE); + if (!$main::file_cache_noflush{$f}) { + &open_tempfile(FLUSHFILE, ">$f"); + local $line; + foreach $line (@{$main::file_cache{$f}}) { + (print FLUSHFILE $line,$eol) || + &error(&text("efilewrite", $f, $!)); + } + &close_tempfile(FLUSHFILE); + } delete($main::file_cache{$f}); + delete($main::file_cache_noflush{$f}); } }