From c7ec7a982d2dda98fb5318d126e9d83c4354a656 Mon Sep 17 00:00:00 2001 From: cristian Date: Thu, 6 Jul 2017 16:53:06 +0300 Subject: [PATCH 1/2] Close file after uploading --- lib/asset_sync/storage.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index 772f252b..23ebfb73 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -121,9 +121,10 @@ def upload_file(f) one_year = 31557600 ext = File.extname(f)[1..-1] mime = MultiMime.lookup(ext) + file_handle = File.open("#{path}/#{f}") file = { :key => f, - :body => File.open("#{path}/#{f}"), + :body => file_handle, :public => true, :content_type => mime } @@ -199,7 +200,8 @@ def upload_file(f) }) end - file = bucket.files.create( file ) unless ignore + bucket.files.create( file ) unless ignore + file_handle.close end def upload_files From 78200a8fd52eb6eb39c51ee264edce717bdbcade Mon Sep 17 00:00:00 2001 From: cristian Date: Mon, 10 Jul 2017 15:26:19 +0200 Subject: [PATCH 2/2] Close gzipped file handle --- lib/asset_sync/storage.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/asset_sync/storage.rb b/lib/asset_sync/storage.rb index 23ebfb73..ddff402b 100644 --- a/lib/asset_sync/storage.rb +++ b/lib/asset_sync/storage.rb @@ -121,6 +121,7 @@ def upload_file(f) one_year = 31557600 ext = File.extname(f)[1..-1] mime = MultiMime.lookup(ext) + gzip_file_handle = nil file_handle = File.open("#{path}/#{f}") file = { :key => f, @@ -169,9 +170,10 @@ def upload_file(f) if gzipped_size < original_size percentage = ((gzipped_size.to_f/original_size.to_f)*100).round(2) + gzip_file_handle = File.open(gzipped) file.merge!({ :key => f, - :body => File.open(gzipped), + :body => gzip_file_handle, :content_encoding => 'gzip' }) log "Uploading: #{gzipped} in place of #{f} saving #{percentage}%" @@ -202,6 +204,7 @@ def upload_file(f) bucket.files.create( file ) unless ignore file_handle.close + gzip_file_handle.close if gzip_file_handle end def upload_files