From 566c4c39e58e001015d263df124ea88d06ba5940 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Tue, 31 Jan 2017 11:03:27 +0000 Subject: Make sure that we accept any old snapshot name when restoring. Also expand the tests to check that the correct ownership etc is being returned. --- lib/byteback/restore.rb | 3 +-- lib/byteback/restore_file.rb | 9 ++++++--- test/tc_restore.rb | 30 +++++++++++++++++++++++------- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/lib/byteback/restore.rb b/lib/byteback/restore.rb index d313209..7055be3 100644 --- a/lib/byteback/restore.rb +++ b/lib/byteback/restore.rb @@ -65,11 +65,10 @@ module Byteback @results = paths.collect do |path| Dir.glob(File.expand_path(File.join(@byteback_root, @snapshot, path))).collect do |f| - restore_file = Byteback::RestoreFile.new(f, @byteback_root, @now) + Byteback::RestoreFile.new(f, @byteback_root, @now) end end.flatten - # # If we want an unpruned list, return it now. # diff --git a/lib/byteback/restore_file.rb b/lib/byteback/restore_file.rb index 5811b0f..daceb83 100644 --- a/lib/byteback/restore_file.rb +++ b/lib/byteback/restore_file.rb @@ -45,10 +45,13 @@ module Byteback # @snapshot = full_path.sub(%r(^#{Regexp.escape @byteback_root}),'').split("/")[1] - if @snapshot == "current" - @snapshot_time = @now - else + # + # If we can parse the time, use it, otherwise assume "now". + # + begin @snapshot_time = Time.parse(@snapshot) + rescue ArgumentError + @snapshot_time = @now end # diff --git a/test/tc_restore.rb b/test/tc_restore.rb index 364c7f1..03e98ad 100644 --- a/test/tc_restore.rb +++ b/test/tc_restore.rb @@ -8,8 +8,6 @@ class RestoreTest < Test::Unit::TestCase def setup @byteback_root = Dir.mktmpdir - @snapshot = Time.now.iso8601 - FileUtils.mkdir_p(File.join(@byteback_root, @snapshot)) end def teardown @@ -17,18 +15,36 @@ class RestoreTest < Test::Unit::TestCase end def test_find + create_snapshot_and_check_results(Time.now.iso8601.to_s) + end + + def test_no_barf_on_non_timestamp_snapshot_name + create_snapshot_and_check_results("saved-hacked-do-not-delete") + end + + def create_snapshot_and_check_results(snapshot) + FileUtils.mkdir_p(File.join(@byteback_root, snapshot)) files = %w(/srv/foo.com/public/htdocs/index.html /srv/foo.com/public/htdocs/app.php) files.each do |f| - FileUtils.mkdir_p(File.join(@byteback_root, @snapshot, File.dirname(f))) - FileUtils.touch(File.join(@byteback_root, @snapshot, f)) - system("setfattr --name user.rsync.%stat -v \"41755 12,34 56:78\" #{File.join(@byteback_root, @snapshot, f)}") + FileUtils.mkdir_p(File.join(@byteback_root, snapshot, File.dirname(f))) + FileUtils.touch(File.join(@byteback_root, snapshot, f)) + system("setfattr --name user.rsync.%stat -v \"41755 12,34 56:78\" #{File.join(@byteback_root, snapshot, f)}") + assert_equal(0, $?.exitstatus) end r = Byteback::Restore.find(@byteback_root, "*", "/srv/foo.com/public/htdocs/*.html") - - r.list + assert(r.results.all?{|f| f.path =~ %r{/srv/foo.com/public/htdocs/.*.html}}, "Results returned did not match requested pattern") + assert(r.results.all?{|f| f.snapshot == snapshot}, "Results returned were not from the correct snapshot") + + # Now check that we're getting the correct stuff from the rsync attr. + f = r.results.first + assert_equal(041755, f.mode, "Incorrect mode returned") + assert_equal(12, f.dev_major, "Incorrect dev_major returned") + assert_equal(34, f.dev_minor, "Incorrect dev_minor returned") + assert_equal(56, f.uid, "Incorrect UID returned") + assert_equal(78, f.gid, "Inocrrect GID returned") end end -- cgit v1.2.1