|
47 | 47 | require 'open-uri'
|
48 | 48 | require 'uri'
|
49 | 49 | require 'getoptlong'
|
| 50 | + require 'tempfile' |
50 | 51 |
|
51 | 52 | def usage
|
52 | 53 | print <<EOF
|
|
221 | 222 |
|
222 | 223 | # stream package file to disk
|
223 | 224 | begin
|
224 |
| - File.open(package_file, 'w+b') do |file| |
225 |
| - uri.open(:ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER, :redirect => true, :read_timeout => 120) do |s3| |
226 |
| - file.write(s3.read) |
227 |
| - end |
| 225 | + uri.open(:ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER, :redirect => true, :read_timeout => 120) do |s3| |
| 226 | + package_file.write(s3.read) |
228 | 227 | end
|
229 | 228 | rescue OpenURI::HTTPError => e
|
230 | 229 | @log.error("Could not find package to download at '#{uri.to_s}'")
|
@@ -252,20 +251,24 @@ EOF
|
252 | 251 | version_data = get_version_file_from_s3(region, bucket, version_file_key)
|
253 | 252 |
|
254 | 253 | package_key = version_data[type]
|
255 |
| - package_base_name = package_key.split('/')[-1] # base name for the key in S3 |
256 |
| - package_file = "/tmp/#{package_base_name}" |
| 254 | + package_base_name = File.basename(package_key) |
| 255 | + package_extension = File.extname(package_base_name) |
| 256 | + package_name = File.basename(package_base_name, package_extension) |
| 257 | + package_file = Tempfile.new(["#{package_name}.tmp-", package_extension]) # unique file with 0600 permissions |
257 | 258 |
|
258 | 259 | get_package_from_s3(region, bucket, package_key, package_file)
|
259 |
| - install_cmd << package_file |
| 260 | + package_file.close |
| 261 | + |
| 262 | + install_cmd << package_file.path |
260 | 263 | @log.info("Executing `#{install_cmd.join(" ")}`...")
|
261 | 264 |
|
262 | 265 | if (!run_command(*install_cmd))
|
263 |
| - @log.error("Error installing #{package_file}.") |
264 |
| - FileUtils.rm(package_file) |
| 266 | + @log.error("Error installing #{package_file.path}.") |
| 267 | + package_file.unlink |
265 | 268 | exit(1)
|
266 | 269 | end
|
267 | 270 |
|
268 |
| - FileUtils.rm(package_file) |
| 271 | + package_file.unlink |
269 | 272 | end
|
270 | 273 |
|
271 | 274 | def do_sanity_check(cmd)
|
|
0 commit comments