Skip to content

Commit

Permalink
Use File::Stat.executable? instead of File.executable?
Browse files Browse the repository at this point in the history
  • Loading branch information
nabertrand committed Aug 6, 2024
1 parent 1df196d commit 8472752
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/pdk/module/convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def stage_changes!(context = PDK.context)
when :manage
if PDK::Util::Filesystem.exist?(absolute_file_path)
update_manager.modify_file(absolute_file_path, file_content)
update_manager.make_file_executable(absolute_file_path) if file_executable && !PDK::Util::Filesystem.executable?(absolute_file_path)
update_manager.make_file_executable(absolute_file_path) if file_executable && !PDK::Util::Filesystem.stat(absolute_file_path).executable?
else
update_manager.add_file(absolute_file_path, file_content)
update_manager.make_file_executable(absolute_file_path) if file_executable
Expand Down
2 changes: 1 addition & 1 deletion lib/pdk/template/renderer/v1/renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def render_module(options = {})
end
end

dest_executable = config['manage_execute_permissions'] && PDK::Util::Filesystem.executable?(File.join(template_loc, template_file))
dest_executable = config['manage_execute_permissions'] && PDK::Util::Filesystem.stat(File.join(template_loc, template_file)).executable?

yield dest_path, dest_content, dest_status, dest_executable
end
Expand Down
11 changes: 6 additions & 5 deletions spec/unit/pdk/module/convert_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ def module_path(relative_path)
include_context 'completes a convert'

before do
stat_double = instance_double("File::Stat", executable?: false)

Check failure on line 188 in spec/unit/pdk/module/convert_spec.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 3.2) / spec

RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.

Check failure on line 188 in spec/unit/pdk/module/convert_spec.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 3.2) / spec

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

Check failure on line 188 in spec/unit/pdk/module/convert_spec.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 2.7) / spec

RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.

Check failure on line 188 in spec/unit/pdk/module/convert_spec.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 2.7) / spec

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
allow(PDK::Util::Filesystem).to receive(:stat).with(module_path('/a/path/to/file')).and_return(stat_double)
allow(PDK::Util::Filesystem).to receive(:exist?).with(module_path('/a/path/to/file')).and_return(true)
allow(update_manager).to receive(:modify_file).with(any_args)
allow(update_manager).to receive(:changes?).and_return(true)
Expand Down Expand Up @@ -227,6 +229,8 @@ def module_path(relative_path)
include_context 'completes a convert'

before do
stat_double = instance_double("File::Stat", executable?: false)

Check failure on line 232 in spec/unit/pdk/module/convert_spec.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 3.2) / spec

RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.

Check failure on line 232 in spec/unit/pdk/module/convert_spec.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 3.2) / spec

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

Check failure on line 232 in spec/unit/pdk/module/convert_spec.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 2.7) / spec

RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.

Check failure on line 232 in spec/unit/pdk/module/convert_spec.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 2.7) / spec

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
allow(PDK::Util::Filesystem).to receive(:stat).with(module_path('/a/path/to/file')).and_return(stat_double)
allow(PDK::Util::Filesystem).to receive(:exist?).with(module_path('/a/path/to/file')).and_return(true)
allow(update_manager).to receive(:modify_file).with(any_args)
allow(update_manager).to receive(:changes?).and_return(true)
Expand Down Expand Up @@ -284,7 +288,8 @@ def module_path(relative_path)
context 'when managing file execute bits' do
context 'when file exists and has correct execute bits' do
before do
allow(PDK::Util::Filesystem).to receive(:executable?).with(module_path('/a/path/to/file')).and_return(true)
stat_double = instance_double("File::Stat", executable?: true)

Check failure on line 291 in spec/unit/pdk/module/convert_spec.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 3.2) / spec

RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.

Check failure on line 291 in spec/unit/pdk/module/convert_spec.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 3.2) / spec

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

Check failure on line 291 in spec/unit/pdk/module/convert_spec.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 2.7) / spec

RSpec/VerifiedDoubleReference: Use a constant class reference for verified doubles.

Check failure on line 291 in spec/unit/pdk/module/convert_spec.rb

View workflow job for this annotation

GitHub Actions / spec (ruby 2.7) / spec

Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
allow(PDK::Util::Filesystem).to receive(:stat).with(module_path('/a/path/to/file')).and_return(stat_double)
end

it 'does not stage the file for making executable' do
Expand All @@ -293,10 +298,6 @@ def module_path(relative_path)
end

context 'when file exists but has incorrect execute bits' do
before do
allow(PDK::Util::Filesystem).to receive(:executable?).with(module_path('/a/path/to/file')).and_return(false)
end

it 'stages the file for making executable' do
expect(update_manager).to receive(:make_file_executable).with(module_path('/a/path/to/file'))
end
Expand Down

0 comments on commit 8472752

Please sign in to comment.