Class: Rock::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/proutils/rtar/rtar.rb

Instance Method Summary collapse

Constructor Details

#initializePackage

Returns a new instance of Package.



53
54
# File 'lib/proutils/rtar/rtar.rb', line 53

def initialize()
end

Instance Method Details

#extract(file) ⇒ Object

Extract a particular file from the archive.



134
135
136
137
138
# File 'lib/proutils/rtar/rtar.rb', line 134

def extract(file)
  puts "NOT WORKING YET"
  return
  # TODO
end

#list(file) ⇒ Object

List contents of rock archive.



142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/proutils/rtar/rtar.rb', line 142

def list(file)
  puts "NOT WORKING YET"
  return
  name = File.basename(file)
  temp_folder = Dir.tmpdir
  FileUtils.cp_r(file,temp_folder)
  Dir.chdir(temp_folder) do
    unpack_rec(name)
  end
  folder = name.chomp('.tar')
  Dir.glob(File.join(temp_folder,folder,'**/*'))
end

#pack(folder) ⇒ Object

Pack rock archive.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/proutils/rtar/rtar.rb', line 58

def pack(folder)
  basename = File.basename(folder)
  return unless write_okay?(basename + ".rock")
  temp_folder = tmpdir()
  temp_locale = File.join(temp_folder,basename)
  #FileUtils.rm_r( temp_locale ) if File.exist?( temp_locale )
  FileUtils.cp_r(folder,temp_folder)
  file = nil
  Dir.chdir(temp_folder) do
    file = pack_rec(basename)
  end
  raise "unexpect compression error" unless file
  FileUtils.cp(File.join(temp_folder, file), "./#{basename}.rock")
end

#pack_rec(folder) ⇒ Object

Recursive packing.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/proutils/rtar/rtar.rb', line 75

def pack_rec(folder)
  puts "<< #{folder}" if $VERBOSE
  Dir.chdir(folder) do
    files = Dir.entries('.') - ['.', '..']
    files.each do |f|
      if File.directory?(f)
        pack_rec(f)
      else
        gzip(f)
      end
    end
  end
  seal(folder) #gzip(tar(folder),'.rock')
end

#unpack(file) ⇒ Object

Unpack rock archive.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/proutils/rtar/rtar.rb', line 92

def unpack(file)
  return unless gzip?(file)
  basename = File.basename(file)
  barename = basename.chomp('.rock')
  rock_ext = (basename != barename)
  rockname = barename + '.rock'
  unless rock_ext or $FORCE
    return nil.status(:no_rock_ext)
  end
  temp_folder = tmpdir()
  to_file = File.join(temp_folder, rockname)
  if rock_ext
    return unless write_okay?(barename)
    FileUtils.cp_r(file, to_file)
  elsif $FORCE
    FileUtils.mv(file, to_file)
  end
  Dir.chdir(temp_folder) do
    unpack_rec(rockname)
  end
  FileUtils.mv(File.join(temp_folder,barename), '.')
end

#unpack_rec(file) ⇒ Object

Recursive unpacking.



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/proutils/rtar/rtar.rb', line 117

def unpack_rec(file)
  puts ">> #{file}" if $VERBOSE
  folder = unseal(file) #untar(gunzip(file))
  Dir.chdir( folder ) do
    files = Dir.entries('.') - ['.','..']
    files.each do |f|
      if f =~ /\.rock$/
        unpack_rec(f)
      else
        gunzip(f)
      end
    end
  end
end