diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2015-12-02 12:58:51 +0000 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2015-12-02 12:58:51 +0000 |
commit | d056150967401a6c69637eaf3aaa07abdc927574 (patch) | |
tree | f287a3edf26cbadd4da82ec0a4ee73b21ccd4e28 | |
parent | 7e967dbd82172d349160ebc5e612f834f11bced1 (diff) |
Updated Byteback::Restore#find to sort files in chronological order
Also only the latest copy is returned by default, unless :verbose or
:all are set in the options, in which case all the copies, or just the
unique copies are returned.
-rw-r--r-- | lib/byteback/restore.rb | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/byteback/restore.rb b/lib/byteback/restore.rb index 82fab82..d313209 100644 --- a/lib/byteback/restore.rb +++ b/lib/byteback/restore.rb @@ -55,7 +55,7 @@ module Byteback @results end - def find(paths, full = false) + def find(paths, opts = {}) results = [] # # Make sure we've an array, and that we get rid of any ".." nonsense. @@ -67,17 +67,26 @@ module Byteback Dir.glob(File.expand_path(File.join(@byteback_root, @snapshot, path))).collect do |f| restore_file = Byteback::RestoreFile.new(f, @byteback_root, @now) end - end.flatten.sort{|a,b| [a.path, a.snapshot_time] <=> [b.path, b.snapshot_time]} + end.flatten + # # If we want an unpruned list, return it now. # - return @results if full + if opts == true or (opts.is_a?(Hash) and opts[:verbose]) + @results = @results.sort{|a,b| [a.path, a.snapshot_time] <=> [b.path, b.snapshot_time]} + return @results + end + @results = @results.sort{|a,b| [a.path, b.snapshot_time] <=> [b.path, a.snapshot_time]} pruned_results = [] @results.each do |r| - pruned_results << r unless pruned_results.include?(r) + if (opts.is_a?(Hash) and opts[:all]) + pruned_results << r unless pruned_results.include?(r) + else + pruned_results << r unless pruned_results.any?{|pr| pr.path == r.path} + end end @results = pruned_results |