Skip to content

Commit b4432ce

Browse files
authored
Merge pull request #134 from puppetlabs/bolt_109_fix_windows_longpath
(BOLT-109) Fix Windows long path support by replacing Dir[] with Find.find
2 parents 185912a + f800902 commit b4432ce

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lib/puppet_forge/unpacker.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'pathname'
2+
require 'find'
23
require 'puppet_forge/error'
34
require 'puppet_forge/tar'
45

@@ -55,8 +56,23 @@ def move_into(dir)
5556
def root_dir
5657
return @root_dir if @root_dir
5758

58-
# Grab the first directory containing a metadata.json file
59-
metadata_file = Dir["#{@tmpdir}/**/metadata.json"].sort_by(&:length)[0]
59+
# Use Find.find instead of Dir[] for Windows long path support
60+
metadata_file = nil
61+
shortest_length = Float::INFINITY
62+
63+
begin
64+
Find.find(@tmpdir) do |path|
65+
if File.basename(path) == 'metadata.json'
66+
if path.length < shortest_length
67+
metadata_file = path
68+
shortest_length = path.length
69+
end
70+
end
71+
end
72+
rescue Errno::ENAMETOOLONG => e
73+
# Even Find.find might fail, need to use Dir.each with manual recursion
74+
raise "Cannot traverse directory due to long paths: #{e.message}"
75+
end
6076

6177
if metadata_file
6278
@root_dir = Pathname.new(metadata_file).dirname

0 commit comments

Comments
 (0)