Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ensure files are closed (closes #279 #280)

  • Loading branch information...
commit 8366d7e4b397d5ffe44e27b9d75dfdfbe74c23d2 1 parent 1d923a9
Brian D. Burns authored
View
10 lib/backup/syncer/cloud.rb
@@ -150,10 +150,12 @@ def sync_file(relative_path, mirror)
if local_file && File.exist?(local_file.path)
unless remote_file && remote_file.etag == local_file.md5
MUTEX.synchronize { Logger.message("\s\s[transferring] #{relative_path}") }
- bucket.files.create(
- :key => "#{path}/#{relative_path}".gsub(/^\//, ''),
- :body => File.open(local_file.path)
- )
+ File.open(local_file.path, 'r') do |file|
+ bucket.files.create(
+ :key => "#{path}/#{relative_path}".gsub(/^\//, ''),
+ :body => file
+ )
+ end
else
MUTEX.synchronize { Logger.message("\s\s[skipping] #{relative_path}") }
end
View
4 spec/syncer/cloud_files_spec.rb
@@ -14,7 +14,7 @@ class Parallel; end
before :each do
Fog::Storage.stubs(:new).returns connection
- File.stubs(:open).returns content
+ File.stubs(:open).yields content
File.stubs(:exist?).returns true
files.stubs(:create).returns true
@@ -98,7 +98,7 @@ class Parallel; end
end
it "uploads the content of the local file" do
- File.expects(:open).with('tmp/foo').returns content
+ files.expects(:create).with(:key => 'storage/tmp/foo', :body => content)
syncer.perform!
end
View
4 spec/syncer/s3_spec.rb
@@ -14,7 +14,7 @@ class Parallel; end
before :each do
Fog::Storage.stubs(:new).returns connection
- File.stubs(:open).returns content
+ File.stubs(:open).yields content
File.stubs(:exist?).returns true
files.stubs(:create).returns true
@@ -99,7 +99,7 @@ class Parallel; end
end
it "uploads the content of the local file" do
- File.expects(:open).with('tmp/foo').returns content
+ files.expects(:create).with(:key => 'storage/tmp/foo', :body => content)
syncer.perform!
end
Please sign in to comment.
Something went wrong with that request. Please try again.