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
|
# File 'lib/backy/s3_load.rb', line 10
def call
return file_name if File.exist?(file_name)
print "Loading #{key} from S3 ... "
Tempfile.create(file_name) do |tempfile|
response_target = tempfile.path
begin
s3.get_object(response_target: response_target, key: key, bucket: bucket)
FileUtils.mkdir_p(File.dirname(file_name))
FileUtils.mv(response_target, file_name)
rescue Aws::S3::Errors::NoSuchKey
puts "error. No such key #{key}"
ensure
if File.exist?(tempfile.path)
tempfile.close
File.delete(tempfile.path)
end
end
end
puts "done"
file_name
end
|