Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'develop'

  • Loading branch information...
commit 1df829a1f196f1272a138e47d6c5494df729f0b3 2 parents 6f90c1a + 950314d
@meskyanichi meskyanichi authored
View
2  Gemfile
@@ -3,7 +3,7 @@
source 'http://rubygems.org'
##
-# Bundle gems definde inside the gemspec file
+# Bundle gems defined inside the gemspec file
gemspec
##
View
2  Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- backup (3.0.4)
+ backup (3.0.5)
dropbox (~> 1.2.3)
fog (~> 0.5.3)
mail (~> 2.2.15)
View
21 lib/backup/archive.rb
@@ -13,6 +13,10 @@ class Archive
attr_accessor :paths
##
+ # Stores an array of different paths/files to exclude
+ attr_accessor :excludes
+
+ ##
# Stores the path to the archive directory
attr_accessor :archive_path
@@ -21,6 +25,7 @@ class Archive
def initialize(name, &block)
@name = name.to_sym
@paths = Array.new
+ @excludes = Array.new
@archive_path = File.join(TMP_PATH, TRIGGER, 'archive')
instance_eval(&block)
@@ -33,12 +38,18 @@ def add(path)
end
##
+ # Adds new paths to the @excludes instance variable array
+ def exclude(path)
+ @excludes << path
+ end
+
+ ##
# Archives all the provided paths in to a single .tar file
# and places that .tar file in the folder which later will be packaged
def perform!
mkdir(archive_path)
Logger.message("#{ self.class } started packaging and archiving #{ paths.map { |path| "\"#{path}\""}.join(", ") }.")
- run("#{ utility(:tar) } -c #{ paths_to_package } 1> '#{ File.join(archive_path, "#{name}.tar") }' 2> /dev/null")
+ run("#{ utility(:tar) } -c #{ paths_to_exclude } #{ paths_to_package } 1> '#{ File.join(archive_path, "#{name}.tar") }' 2> /dev/null")
end
private
@@ -50,5 +61,13 @@ def paths_to_package
"'#{path}'"
end.join("\s")
end
+
+ ##
+ # Returns a "tar-ready" string of all the specified excludes combined
+ def paths_to_exclude
+ if excludes.any?
+ "--exclude={" + excludes.map{ |e| "'#{e}'" }.join(",") + "}"
+ end
+ end
end
end
View
2  lib/backup/version.rb
@@ -13,7 +13,7 @@ class Version
# Defines the minor version
# PATCH:
# Defines the patch version
- MAJOR, MINOR, PATCH = 3, 0, 4
+ MAJOR, MINOR, PATCH = 3, 0, 5
##
# Returns the major version ( big release based off of multiple minor releases )
View
47 spec/archive_spec.rb
@@ -9,6 +9,8 @@
a.add '/home/rspecuser/somefile'
a.add '/home/rspecuser/logs/'
a.add '/home/rspecuser/dotfiles/'
+ a.exclude '/home/rspecuser/excludefile'
+ a.exclude '/home/rspecuser/excludedir/'
end
end
@@ -17,10 +19,19 @@
archive.paths.count.should == 0
end
+ it 'should have no excludes' do
+ archive = Backup::Archive.new(:dummy_archive) { |a| }
+ archive.excludes.count.should == 0
+ end
+
it 'should have 3 paths' do
archive.paths.count.should == 3
end
+ it 'should have 2 excludes' do
+ archive.excludes.count.should == 2
+ end
+
it do
archive.name.should == :dummy_archive
end
@@ -32,17 +43,43 @@
end
end
+ describe '#paths_to_exclude' do
+ it 'should be empty' do
+ archive = Backup::Archive.new(:dummy_archive) { |a| }
+ archive.send(:paths_to_exclude).should be_nil
+ end
+
+ it 'should return a tar -c friendly string' do
+ archive.send(:paths_to_exclude).should ==
+ "--exclude={'/home/rspecuser/excludefile','/home/rspecuser/excludedir/'}"
+ end
+ end
+
describe '#perform!' do
before do
[:mkdir, :run, :utility].each { |method| archive.stubs(method) }
Backup::Logger.stubs(:message)
end
- it 'should tar all the specified paths' do
- archive.expects(:mkdir).with(File.join(Backup::TMP_PATH, Backup::TRIGGER, 'archive'))
- archive.expects(:run).with("tar -c '/home/rspecuser/somefile' '/home/rspecuser/logs/' '/home/rspecuser/dotfiles/' 1> '#{File.join(Backup::TMP_PATH, Backup::TRIGGER, 'archive', "#{:dummy_archive}.tar")}' 2> /dev/null")
- archive.expects(:utility).with(:tar).returns(:tar)
- archive.perform!
+ context 'when both paths were added and paths that should be excluded were added' do
+ it 'should render both the syntax for the paths that be included as well as excluded' do
+ archive.expects(:mkdir).with(File.join(Backup::TMP_PATH, Backup::TRIGGER, 'archive'))
+ archive.expects(:run).with("tar -c --exclude={'/home/rspecuser/excludefile','/home/rspecuser/excludedir/'} '/home/rspecuser/somefile' '/home/rspecuser/logs/' '/home/rspecuser/dotfiles/' 1> '#{File.join(Backup::TMP_PATH, Backup::TRIGGER, 'archive', "#{:dummy_archive}.tar")}' 2> /dev/null")
+ archive.expects(:utility).with(:tar).returns(:tar)
+ archive.perform!
+ end
+ end
+
+ context 'when there are paths to add, and no exclude patterns were defined' do
+ it 'should only render syntax for the defined paths' do
+ archive = Backup::Archive.new(:dummy_archive) do |a|
+ a.add '/path/to/archive'
+ end
+
+ archive.stubs(:utility).returns(:tar)
+ archive.expects(:run).with("tar -c '/path/to/archive' 1> '#{File.join(Backup::TMP_PATH, Backup::TRIGGER, 'archive', "#{:dummy_archive}.tar")}' 2> /dev/null")
+ archive.perform!
+ end
end
it 'should log the status' do
Please sign in to comment.
Something went wrong with that request. Please try again.