mirror of
https://github.com/webmin/webmin.git
synced 2026-09-18 19:40:41 +01:00
Fix Nginx cache handling for caller-owned locks
This commit is contained in:
@@ -562,13 +562,14 @@ while (1) {
|
||||
}
|
||||
elsif (&lock_file($f)) {
|
||||
push(@lock_all_config_files_cache, $f);
|
||||
# Drop stale lines only after acquiring this lock ourselves.
|
||||
&unflush_file_lines($f);
|
||||
}
|
||||
else {
|
||||
&error("Failed to lock Nginx config file $f");
|
||||
}
|
||||
$locked{$f} = 1;
|
||||
$new_files++;
|
||||
&unflush_file_lines($f);
|
||||
}
|
||||
last if (!$new_files);
|
||||
|
||||
|
||||
@@ -142,8 +142,32 @@ subtest 'locks acquired by a caller remain owned by it' => sub {
|
||||
main::unlock_file($conf);
|
||||
};
|
||||
|
||||
subtest 'pending edits under a caller lock are retained' => sub {
|
||||
write_text($conf, "http {\n}\n");
|
||||
main::flush_config_cache();
|
||||
main::unflush_file_lines($conf);
|
||||
main::lock_file($conf);
|
||||
my $lines = main::read_file_lines($conf);
|
||||
splice(@$lines, 1, 0, ' # pending edit');
|
||||
main::lock_all_config_files();
|
||||
is(main::read_file_lines($conf), $lines,
|
||||
'pre-existing writable cache is retained');
|
||||
main::flush_file_lines($conf);
|
||||
main::unlock_all_config_files();
|
||||
main::unlock_file($conf);
|
||||
open(my $fh, '<', $conf) or die "$conf: $!";
|
||||
my $saved = do { local $/; <$fh> };
|
||||
close($fh) or die "$conf: $!";
|
||||
like($saved, qr/^ # pending edit$/m, 'pending edit is saved');
|
||||
};
|
||||
|
||||
subtest 'included files are refreshed after waiting for their locks' => sub {
|
||||
my $extra = "$tmp/extra.conf";
|
||||
write_text($conf, "http {\n include $included;\n}\n");
|
||||
write_text($included, servers());
|
||||
main::flush_config_cache();
|
||||
main::unflush_file_lines($conf);
|
||||
main::unflush_file_lines($included);
|
||||
write_text($extra, "server {\n server_name gamma.invalid;\n}\n");
|
||||
my $lock = \&main::lock_file;
|
||||
my $changed = 0;
|
||||
|
||||
Reference in New Issue
Block a user