Skip to content

Commit 59ac9fe

Browse files
committed
(PUP-4884) Clean forge cache base directory
On Windows the default forge cache base directory is created from Dir.mktmpdir and contains forward slashes: "C:/Users/josh/AppData/Local/Temp/...". When unpacking a tarball we check that the entry to be unpacked has the same prefix. The prefix is the result of File.expand_path, which also returns a path with forward slashes. When the cache base directory is changed to a Windows native path, e.g. C:\Temp, to work around long file path issues, the check will fail. This commit cleans the base_dir and the tar entry, so that the comparison is always done using forward slashes.
1 parent 2b0a129 commit 59ac9fe

File tree

3 files changed

+3
-4
lines changed

3 files changed

+3
-4
lines changed

lib/puppet/forge/cache.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def path
4747

4848
# Return the base Pathname for all the caches.
4949
def self.base_path
50-
(Pathname(Puppet.settings[:module_working_dir]) + 'cache').tap do |o|
50+
(Pathname(Puppet.settings[:module_working_dir]) + 'cache').cleanpath.tap do |o|
5151
o.mkpath unless o.exist?
5252
end
5353
end

lib/puppet/module_tool/tar/mini.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def validate_entry(destdir, path)
107107
raise Puppet::ModuleTool::Errors::InvalidPathInPackageError, :entry_path => path, :directory => destdir
108108
end
109109

110-
path = File.expand_path File.join(destdir, path)
110+
path = Pathname.new(File.join(destdir, path)).cleanpath.to_path
111111

112112
if path !~ /\A#{Regexp.escape destdir}/
113113
raise Puppet::ModuleTool::Errors::InvalidPathInPackageError, :entry_path => path, :directory => destdir

spec/unit/module_tool/applications/installer_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434

3535
if Puppet::Util::Platform.windows?
3636
before :each do
37-
allow(Puppet.settings).to receive(:[])
38-
allow(Puppet.settings).to receive(:[]).with(:module_working_dir).and_return(Dir.mktmpdir('installertmp'))
37+
Puppet[:module_working_dir] = tmpdir('module_tool_install').gsub('/', '\\')
3938
end
4039
end
4140

0 commit comments

Comments
 (0)