Skip to content

Commit

Permalink
ensure files are closed (closes #279 #280)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian D. Burns committed Feb 21, 2012
1 parent 1d923a9 commit 8366d7e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
10 changes: 6 additions & 4 deletions lib/backup/syncer/cloud.rb
Expand Up @@ -150,10 +150,12 @@ def sync_file(relative_path, mirror)
if local_file && File.exist?(local_file.path) if local_file && File.exist?(local_file.path)
unless remote_file && remote_file.etag == local_file.md5 unless remote_file && remote_file.etag == local_file.md5
MUTEX.synchronize { Logger.message("\s\s[transferring] #{relative_path}") } MUTEX.synchronize { Logger.message("\s\s[transferring] #{relative_path}") }
bucket.files.create( File.open(local_file.path, 'r') do |file|
:key => "#{path}/#{relative_path}".gsub(/^\//, ''), bucket.files.create(
:body => File.open(local_file.path) :key => "#{path}/#{relative_path}".gsub(/^\//, ''),
) :body => file
)
end
else else
MUTEX.synchronize { Logger.message("\s\s[skipping] #{relative_path}") } MUTEX.synchronize { Logger.message("\s\s[skipping] #{relative_path}") }
end end
Expand Down
4 changes: 2 additions & 2 deletions spec/syncer/cloud_files_spec.rb
Expand Up @@ -14,7 +14,7 @@ class Parallel; end


before :each do before :each do
Fog::Storage.stubs(:new).returns connection Fog::Storage.stubs(:new).returns connection
File.stubs(:open).returns content File.stubs(:open).yields content
File.stubs(:exist?).returns true File.stubs(:exist?).returns true
files.stubs(:create).returns true files.stubs(:create).returns true


Expand Down Expand Up @@ -98,7 +98,7 @@ class Parallel; end
end end


it "uploads the content of the local file" do 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! syncer.perform!
end end
Expand Down
4 changes: 2 additions & 2 deletions spec/syncer/s3_spec.rb
Expand Up @@ -14,7 +14,7 @@ class Parallel; end


before :each do before :each do
Fog::Storage.stubs(:new).returns connection Fog::Storage.stubs(:new).returns connection
File.stubs(:open).returns content File.stubs(:open).yields content
File.stubs(:exist?).returns true File.stubs(:exist?).returns true
files.stubs(:create).returns true files.stubs(:create).returns true


Expand Down Expand Up @@ -99,7 +99,7 @@ class Parallel; end
end end


it "uploads the content of the local file" do 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! syncer.perform!
end end
Expand Down

0 comments on commit 8366d7e

Please sign in to comment.