Skip to content

Commit f800902

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 <[email protected]>
1 parent 185912a commit f800902

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)