9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/cifrado/cli/download.rb', line 9
def download(container, object = nil)
client = client_instance
downloaded = []
files = []
if object
files << object
else
Log.info "Downloading files from container #{container}"
dir = client.service.directories.get(container)
files = dir.files if dir
end
pb = Progressbar.new 1, 1, :style => options[:progressbar]
files.each do |f|
obj = f.is_a?(String) ? f : f.key
if !f.is_a?(String) and f.metadata[:encrypted_name]
fname = decrypt_filename f.metadata[:encrypted_name],
@config[:password] + @config[:secure_random]
Log.info "Downloading file #{fname}"
else
Log.info "Downloading file #{obj}"
end
if client.file_available?(container, obj)
r = client.download container, obj,
:decrypt => options[:decrypt],
:passphrase => options[:passphrase],
:output => options[:output],
:progress_callback => pb.block,
:bwlimit => bwlimit
downloaded << obj
else
Log.debug 'Trying to find hashed object name'
file_hash = (Digest::SHA2.new << obj).to_s
r = client.download container, file_hash,
:decrypt => options[:decrypt],
:passphrase => options[:passphrase],
:output => options[:output],
:progress_callback => pb.block,
:bwlimit => bwlimit
downloaded << file_hash if r.status == 200
end
end
Log.warn "No files were downloaded." if downloaded.empty?
downloaded
end
|