Don't abort if unable to write the cache file
This commit is contained in:
parent
6ae5fe62d7
commit
ee8e1e8844
2 changed files with 8 additions and 2 deletions
|
@ -1011,8 +1011,9 @@ sub write_cache {
|
|||
|
||||
$saved_cache = undef;
|
||||
local *FD;
|
||||
if (!open(FD, "> $file")) {
|
||||
fatal("Cannot create file '%s'. (%s)", $file, $!);
|
||||
if (!open(FD, ">", $file)) {
|
||||
warning("Failed to create cache file %s: %s", $file, $!);
|
||||
return;
|
||||
}
|
||||
printf FD "## %s-%s\n", $program, $version;
|
||||
printf FD "## last updated at %s (%d)\n", prettytime($now), $now;
|
||||
|
|
|
@ -15,6 +15,10 @@ $module->redefine('warning', sub {
|
|||
my $tmpdir = File::Temp->newdir();
|
||||
my $dir = $tmpdir->dirname();
|
||||
diag("temporary directory: $dir");
|
||||
my $ro_tmpdir = File::Temp->newdir();
|
||||
my $ro_dir = $ro_tmpdir->dirname();
|
||||
chmod(0500, $ro_dir) or BAIL_OUT($!);
|
||||
diag("temporary read-only directory: $ro_dir");
|
||||
|
||||
sub tc {
|
||||
return {
|
||||
|
@ -28,6 +32,7 @@ my @test_cases = (
|
|||
tc("create cache file", catfile($dir, 'a', 'b', 'cachefile'), undef),
|
||||
tc("overwrite cache file", catfile($dir, 'a', 'b', 'cachefile'), undef),
|
||||
tc("bad directory", catfile($dir, 'a', 'b', 'cachefile', 'bad'), qr/File exists/),
|
||||
tc("read-only directory", catfile($ro_dir, 'cachefile'), qr/Permission denied/),
|
||||
);
|
||||
|
||||
for my $tc (@test_cases) {
|
||||
|
|
Loading…
Reference in a new issue