Skip to content

Commit

Permalink
Remove uses of File.exists?
Browse files Browse the repository at this point in the history
Replace calls to `File.exists?` with `File.exist?` for compatibility with Ruby 3

Closes #97
  • Loading branch information
silug committed Oct 18, 2023
1 parent 19c3b83 commit a7b1c1b
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Wed Oct 18 2023 Steven Pritchard <[email protected]> - 3.5.1
- Replace calls to `File.exists?` with `File.exist?` for compatibility with
Ruby 3

* Wed Oct 11 2023 Steven Pritchard <[email protected]> - 3.5.0
- [puppetsync] Updates for Puppet 8
- These updates may include the following:
Expand Down
2 changes: 1 addition & 1 deletion lib/facter/has_tpm.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Detects whether or not the machine has a TPM
Facter.add('has_tpm') do
setcode do
File.exists?('/dev/tpm0')
File.exist?('/dev/tpm0')
end
end
2 changes: 1 addition & 1 deletion lib/facter/tpm/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def pubek(status)
raw = get_pubek_unowned
out['_status'] = 'success: tpm unowned'
else
if File.exists?(pass_file)
if File.exist?(pass_file)
owner_pass = Facter::Core::Execution.execute("cat #{pass_file} 2> /dev/null")
if owner_pass.eql? ""
out['_status'] = 'error: the password file is empty'
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/tpmtoken/pkcsconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def self.prefetch(resources)
def flush
if @property_flush[:ensure] == :absent
f = File.expand_path('/var/lib/opencryptoki/tpm/root')
FileUtils.rm_rf(f) if File.exists?(f)
FileUtils.rm_rf(f) if File.exist?(f)
debug("Deleted interface #{resource[:name]} folder at #{f}")
@property_hash[:ensure] = :absent
end
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simp-tpm",
"version": "3.5.0",
"version": "3.5.1",
"author": "SIMP Team",
"summary": "Manages TPM 1.2 and TBOOT",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
end

# before(:each) do
# File.stubs(:exists?).with('/dev/tpm0').returns(true)
# File.stubs(:exist?).with('/dev/tpm0').returns(true)
# end

context 'with default parameters and no physical TPM' do
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/facter/has_tpm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

context 'the required file is not present' do
it 'should return nil' do
File.stubs(:exists?).with('/dev/tpm0').returns false
File.stubs(:exist?).with('/dev/tpm0').returns false
expect(Facter.fact(:has_tpm).value).to eq false
end
end

context 'the required file is present' do
it 'should return true' do
File.stubs(:exists?).with('/dev/tpm0').returns true
File.stubs(:exist?).with('/dev/tpm0').returns true
expect(Facter.fact(:has_tpm).value).to eq true
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/facter/tpm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
context 'tpm is owned' do
before(:each) do
@tpm_fact.stubs(:get_pubek_owned).returns File.read('spec/files/tpm/tpm_getpubek.txt')
File.stubs(:exists?).with('/dev/null/simp/tpm_ownership_owner_pass').returns true
File.stubs(:exist?).with('/dev/null/simp/tpm_ownership_owner_pass').returns true
Facter::Core::Execution.stubs(:execute).with('cat /dev/null/simp/tpm_ownership_owner_pass 2> /dev/null').returns 'twentycharacters0000'
end
let(:params) {{ 'enabled' => 1, 'owned' => 1 }}
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/puppet/provider/tpm_ownership/trousers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@
let(:loc) { '/tmp' }
after :each do
file = "#{loc}/simp/tpm_ownership_owner_pass"
FileUtils.rm(file) if File.exists? file
FileUtils.rm(file) if File.exist? file
end

context 'with advanced_facts => false' do
it 'should not do a thing' do
expect(File.exists?("#{loc}/simp/tpm_ownership_owner_pass")).to be_falsey
expect(File.exist?("#{loc}/simp/tpm_ownership_owner_pass")).to be_falsey
end
end
context 'with advanced_facts => true' do
it 'should drop off the password file' do
expect(provider.dump_owner_pass(loc)).to match(/twentycharacters0000/)
expect(File.exists?("#{loc}/simp/tpm_ownership_owner_pass")).to be_truthy
expect(File.exist?("#{loc}/simp/tpm_ownership_owner_pass")).to be_truthy
end
end
end
Expand Down

0 comments on commit a7b1c1b

Please sign in to comment.