|
rdobuilder |
ea962c |
From 66f688f2b3ddc795a087c81746da57190675e624 Mon Sep 17 00:00:00 2001
|
|
rdobuilder |
ea962c |
From: Takashi Kajinami <tkajinam@redhat.com>
|
|
rdobuilder |
ea962c |
Date: Wed, 27 Apr 2022 15:33:16 +0900
|
|
rdobuilder |
ea962c |
Subject: [PATCH] (FACT-3116) Ignore EROFS when deleting fact cache
|
|
rdobuilder |
ea962c |
|
|
rdobuilder |
ea962c |
When fact cache is placed in read only file system, deleting a file
|
|
rdobuilder |
ea962c |
fails with EROFS instead of EACCES .
|
|
rdobuilder |
ea962c |
---
|
|
rdobuilder |
ea962c |
lib/facter/framework/core/cache_manager.rb | 2 +-
|
|
rdobuilder |
ea962c |
spec/facter/cache_manager_spec.rb | 20 +++++++++++++++++++-
|
|
rdobuilder |
ea962c |
2 files changed, 20 insertions(+), 2 deletions(-)
|
|
rdobuilder |
ea962c |
|
|
rdobuilder |
ea962c |
diff --git a/lib/facter/framework/core/cache_manager.rb b/lib/facter/framework/core/cache_manager.rb
|
|
rdobuilder |
ea962c |
index 100a7656a..d93020264 100644
|
|
rdobuilder |
ea962c |
--- a/lib/facter/framework/core/cache_manager.rb
|
|
rdobuilder |
ea962c |
+++ b/lib/facter/framework/core/cache_manager.rb
|
|
rdobuilder |
ea962c |
@@ -227,7 +227,7 @@ cache_format_version is incorrect!")
|
|
rdobuilder |
ea962c |
|
|
rdobuilder |
ea962c |
begin
|
|
rdobuilder |
ea962c |
File.delete(cache_file_name) if File.readable?(cache_file_name)
|
|
rdobuilder |
ea962c |
- rescue Errno::EACCES => e
|
|
rdobuilder |
ea962c |
+ rescue Errno::EACCES, Errno::EROFS => e
|
|
rdobuilder |
ea962c |
@log.warn("Could not delete cache: #{e.message}")
|
|
rdobuilder |
ea962c |
end
|
|
rdobuilder |
ea962c |
end
|
|
rdobuilder |
ea962c |
diff --git a/spec/facter/cache_manager_spec.rb b/spec/facter/cache_manager_spec.rb
|
|
rdobuilder |
ea962c |
index 8b3194340..324964bd5 100644
|
|
rdobuilder |
ea962c |
--- a/spec/facter/cache_manager_spec.rb
|
|
rdobuilder |
ea962c |
+++ b/spec/facter/cache_manager_spec.rb
|
|
rdobuilder |
ea962c |
@@ -132,7 +132,7 @@ describe Facter::CacheManager do
|
|
rdobuilder |
ea962c |
)
|
|
rdobuilder |
ea962c |
end
|
|
rdobuilder |
ea962c |
|
|
rdobuilder |
ea962c |
- context 'when file cannot be deleted' do
|
|
rdobuilder |
ea962c |
+ context 'when file cannot be deleted because of access denied' do
|
|
rdobuilder |
ea962c |
let(:cache_file) { File.join(cache_dir, 'ext_file.txt') }
|
|
rdobuilder |
ea962c |
|
|
rdobuilder |
ea962c |
it 'logs warn if it cannot delete' do
|
|
rdobuilder |
ea962c |
@@ -149,6 +149,24 @@ describe Facter::CacheManager do
|
|
rdobuilder |
ea962c |
expect(logger).to have_received(:warn)
|
|
rdobuilder |
ea962c |
end
|
|
rdobuilder |
ea962c |
end
|
|
rdobuilder |
ea962c |
+
|
|
rdobuilder |
ea962c |
+ context 'when file cannot be deleted because of read-only filesystem' do
|
|
rdobuilder |
ea962c |
+ let(:cache_file) { File.join(cache_dir, 'ext_file.txt') }
|
|
rdobuilder |
ea962c |
+
|
|
rdobuilder |
ea962c |
+ it 'logs warn if it cannot delete' do
|
|
rdobuilder |
ea962c |
+ allow(fact_groups).to receive(:get_fact).with('ext_file.txt').and_return(external_fact)
|
|
rdobuilder |
ea962c |
+ allow(File).to receive(:readable?).with(cache_file_name).and_return(false)
|
|
rdobuilder |
ea962c |
+ allow(Facter::Util::FileHelper).to receive(:safe_read).with(cache_file)
|
|
rdobuilder |
ea962c |
+ .and_return(cached_external_fact)
|
|
rdobuilder |
ea962c |
+ allow(JSON).to receive(:parse).with(cached_external_fact).and_raise(JSON::ParserError)
|
|
rdobuilder |
ea962c |
+ allow(File).to receive(:readable?).with(cache_file).and_return(true)
|
|
rdobuilder |
ea962c |
+ allow(File).to receive(:mtime).with(File.join(cache_dir, 'ext_file.txt')).and_return(Time.now)
|
|
rdobuilder |
ea962c |
+ allow(File).to receive(:delete).with(cache_file).and_raise(Errno::EROFS)
|
|
rdobuilder |
ea962c |
+
|
|
rdobuilder |
ea962c |
+ cache_manager.resolve_facts([searched_external_fact])
|
|
rdobuilder |
ea962c |
+ expect(logger).to have_received(:warn)
|
|
rdobuilder |
ea962c |
+ end
|
|
rdobuilder |
ea962c |
+ end
|
|
rdobuilder |
ea962c |
end
|
|
rdobuilder |
ea962c |
|
|
rdobuilder |
ea962c |
context 'with timer' do
|
|
rdobuilder |
ea962c |
--
|
|
rdobuilder |
ea962c |
2.35.1
|
|
rdobuilder |
ea962c |
|