Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/puppet/module_tool/applications/unpacker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def self.unpack(filename, target)
end

def self.harmonize_ownership(source, target)
return unless Puppet[:manage_internal_file_permissions]

unless Puppet::Util::Platform.windows?
source = Pathname.new(source) unless source.respond_to?(:stat)
target = Pathname.new(target) unless target.respond_to?(:stat)
Expand Down
26 changes: 26 additions & 0 deletions spec/unit/module_tool/applications/unpacker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,30 @@
Puppet::ModuleTool::Applications::Unpacker.run(filename, :target_dir => target)
expect(File).to be_directory(File.join(target, 'mytarball'))
end

describe '.harmonize_ownership' do
let(:source_stat) { instance_double(File::Stat, uid: 1010, gid: 2020) }
let(:source) { instance_double(Pathname, stat: source_stat) }
let(:target) { instance_double(Pathname, stat: source_stat) }

before :each do
allow(Puppet::Util::Platform).to receive(:windows?).and_return(false)
end

it 'does not call chown_R when internal file permission management is disabled' do
allow(Puppet).to receive(:[]).with(:manage_internal_file_permissions).and_return(false)

expect(FileUtils).not_to receive(:chown_R)

described_class.harmonize_ownership(source, target)
end

it 'calls chown_R when internal file permission management is enabled' do
allow(Puppet).to receive(:[]).with(:manage_internal_file_permissions).and_return(true)

expect(FileUtils).to receive(:chown_R).with(1010, 2020, target)

described_class.harmonize_ownership(source, target)
end
end
end