42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/doc/configurator/ruby/source.rb', line 42
def from_archive(path)
path = FSPath(path)
if path.file?
if path.basename.to_s =~ /^(.*)(?i:\.(tar\.(?:gz|bz2)|tgz|tbz|zip))$/
dir, extension = sources_dir / $1, $2.downcase
unless dir.exist?
FSPath.temp_dir 'ruby', sources_dir do |d|
begin
case extension
when 'tbz', 'tar.bz2'
Command.run('tar', '-xjf', path, '-C', d)
when 'tgz', 'tar.gz'
Command.run('tar', '-xzf', path, '-C', d)
when 'zip'
Command.run('unzip', '-q', path, '-d', d)
end
children = d.children
if children.length == 1
children.first.rename(dir)
else
dir.mkpath
FileUtils.mv children, dir
end
rescue SystemExit => e
raise "got #{e} trying to extract archive"
end
end
end
from_dir(dir)
else
raise "#{path} doesn't seem to be archive of known type"
end
else
raise "#{path} is not a file"
end
end
|