Skip to content

Commit

Permalink
allow Package to be flagged so Cycler won't remove
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian D. Burns committed Jul 20, 2013
1 parent c8a4329 commit 496e36f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/backup/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class Package
# Set by the Splitter if the final archive was "chunked"
attr_accessor :chunk_suffixes

##
# If true, the Cycler will not attempt to remove the package when Cycling.
attr_accessor :no_cycle

##
# The version of Backup used to create the package
attr_reader :version
Expand All @@ -27,6 +31,7 @@ def initialize(model)
@trigger = model.trigger
@extension = 'tar'
@chunk_suffixes = Array.new
@no_cycle = false
@version = VERSION
end

Expand Down
2 changes: 1 addition & 1 deletion lib/backup/storage/cycler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def update_storage_file!
def remove_packages!
@packages_to_remove.each do |pkg|
begin
@storage.send(:remove!, pkg)
@storage.send(:remove!, pkg) unless pkg.no_cycle
rescue => err
Logger.warn Errors::Storage::CyclerError.wrap(err, <<-EOS)
There was a problem removing the following package:
Expand Down
6 changes: 6 additions & 0 deletions spec/package_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Backup
expect( package.trigger ).to eq 'test_trigger'
expect( package.extension ).to eq 'tar'
expect( package.chunk_suffixes ).to eq []
expect( package.no_cycle ).to be(false)
expect( package.version ).to eq VERSION
end
end
Expand All @@ -35,6 +36,11 @@ module Backup
expect( package.extension ).to eq 'foo'
end

it 'allows no_cycle to be set' do
package.no_cycle = true
expect( package.no_cycle ).to be(true)
end

describe '#filenames' do
context 'when the package files were not split' do
it 'returns an array with the single package filename' do
Expand Down
14 changes: 14 additions & 0 deletions spec/storage/cycler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
before do
cycler.instance_variable_set(:@storage, storage)
cycler.instance_variable_set(:@packages_to_remove, [pkg_a, pkg_b, pkg_c])
pkg_a.stubs(:no_cycle)
pkg_b.stubs(:no_cycle)
pkg_c.stubs(:no_cycle)
end

it 'should call the @storage to remove the old packages' do
Expand All @@ -65,6 +68,17 @@
cycler.send(:remove_packages!)
end

it 'should skip packages marked as no_cycle' do
pkg_a.stubs(:no_cycle).returns(nil)
pkg_b.stubs(:no_cycle).returns(true)
pkg_c.stubs(:no_cycle).returns(false)

storage.expects(:remove!).with(pkg_a)
storage.expects(:remove!).with(pkg_b).never
storage.expects(:remove!).with(pkg_c)
cycler.send(:remove_packages!)
end

context 'when errors occur removing packages' do
before do
pkg_b.stubs(:trigger).returns('pkg_trigger')
Expand Down

0 comments on commit 496e36f

Please sign in to comment.