Skip to content

Commit 46818f6

Browse files
Replace Dir for Find
The Dir fails to respect the LongPath, which is enabled on the underlying windows system. This Find equivalent logic, however, does work and is respected. Signed-off-by: Gavin Didrichsen <gavin.didrichsen@gmail.com>
1 parent 185912a commit 46818f6

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lib/puppet_forge/unpacker.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,23 @@ def move_into(dir)
5555
def root_dir
5656
return @root_dir if @root_dir
5757

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

6176
if metadata_file
6277
@root_dir = Pathname.new(metadata_file).dirname

0 commit comments

Comments
 (0)