Skip to content

Commit

Permalink
Relocate packages with versioned folders at extraction
Browse files Browse the repository at this point in the history
One problem with packages like Ruby is they include all the source
files into a versioned folder instead of root.

These changes relocate those folders when found.
  • Loading branch information
luislavena committed Feb 7, 2009
1 parent 3c82151 commit 9008922
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions recipes/tools/seven_zip.rb
Expand Up @@ -21,17 +21,38 @@ def self.extract(file, destination)
tar_file = File.join(tmpdir, File.basename($1))
seven_zip file, tmpdir
seven_zip tar_file, destination
FileUtils.rm(tar_file)
FileUtils.rm tar_file
when /(^.+)\.tgz$/
tar_file = File.join(tmpdir, "#{File.basename($1)}.tar")
seven_zip file, tmpdir
seven_zip tar_file, destination
FileUtils.rm(tar_file)
FileUtils.rm tar_file
when /(^.+\.zip$)/
seven_zip file, destination
else
raise UnknownFormatError.new("Unsupported file format for #{file}")
end

# Relocate extracted contents if those are inside a versioned folder
# (msys and ruby packages suffer from this, ruby-1.8.6-p287)
Dir.glob("#{destination}/*").each do |dir|
next unless File.directory?(dir) and File.basename(dir) =~ /.*-\d+.*/i

# ensure relocate normal and dot files
Dir.glob("#{dir}/**/{*,.*}").each do |entry|
target = entry.sub(dir, destination)

# ensure path exists
File.mkpath File.dirname(target)

# do not try to relocate directories
next if File.directory?(entry)
FileUtils.mv entry, target
end

# Remove empty folder
FileUtils.rm_rf dir
end
end

private
Expand Down

0 comments on commit 9008922

Please sign in to comment.