Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close file handle after uploading #351

Merged
merged 2 commits into from
Jul 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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