Skip to content

Commit

Permalink
Merge pull request #351 from AutoUncle/bugfix/close-file-handles
Browse files Browse the repository at this point in the history
Close file handle after uploading
  • Loading branch information
PikachuEXE authored Jul 12, 2017
2 parents a4aaf59 + 78200a8 commit 5ffcea6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/asset_sync/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ 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,
:body => File.open("#{path}/#{f}"),
:body => file_handle,
:public => true,
:content_type => mime
}
Expand Down Expand Up @@ -168,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}%"
Expand Down Expand Up @@ -199,7 +202,9 @@ def upload_file(f)
})
end

file = bucket.files.create( file ) unless ignore
bucket.files.create( file ) unless ignore
file_handle.close
gzip_file_handle.close if gzip_file_handle
end

def upload_files
Expand Down

0 comments on commit 5ffcea6

Please sign in to comment.