Skip to content
Merged
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
20 changes: 18 additions & 2 deletions lib/puppet_forge/unpacker.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'pathname'
require 'find'
require 'puppet_forge/error'
require 'puppet_forge/tar'

Expand Down Expand Up @@ -55,8 +56,23 @@ def move_into(dir)
def root_dir
return @root_dir if @root_dir

# Grab the first directory containing a metadata.json file
metadata_file = Dir["#{@tmpdir}/**/metadata.json"].sort_by(&:length)[0]
# Use Find.find instead of Dir[] for Windows long path support
metadata_file = nil
shortest_length = Float::INFINITY

begin
Find.find(@tmpdir) do |path|
if File.basename(path) == 'metadata.json'
if path.length < shortest_length
metadata_file = path
shortest_length = path.length
end
end
end
rescue Errno::ENAMETOOLONG => e
# Even Find.find might fail, need to use Dir.each with manual recursion
raise "Cannot traverse directory due to long paths: #{e.message}"
end

if metadata_file
@root_dir = Pathname.new(metadata_file).dirname
Expand Down
Loading