diff options
author | Florian Pritz <bluewind@xinu.at> | 2018-09-06 16:02:04 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2018-09-06 18:12:31 +0200 |
commit | 892db03a49333daf7d808395a0a25e81ec2a76ab (patch) | |
tree | 5eff23956ca91d49b3652a3f454f3471e171bc47 /lib/App/BorgRestore.pm | |
parent | a6ef292ee6aca67cef76ebcee0d6bca19698ff39 (diff) | |
download | App-BorgRestore-892db03a49333daf7d808395a0a25e81ec2a76ab.tar.gz App-BorgRestore-892db03a49333daf7d808395a0a25e81ec2a76ab.tar.xz |
Extract lookup table into dedicated package
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'lib/App/BorgRestore.pm')
-rw-r--r-- | lib/App/BorgRestore.pm | 47 |
1 files changed, 4 insertions, 43 deletions
diff --git a/lib/App/BorgRestore.pm b/lib/App/BorgRestore.pm index 5fd36ff..cad8cb1 100644 --- a/lib/App/BorgRestore.pm +++ b/lib/App/BorgRestore.pm @@ -8,6 +8,7 @@ our $VERSION = "3.1.0"; use App::BorgRestore::Borg; use App::BorgRestore::DB; use App::BorgRestore::Helper; +use App::BorgRestore::PathTimeTable::Memory; use App::BorgRestore::Settings; use autodie; @@ -376,32 +377,6 @@ method restore_simple($path, $timespec, $destination) { $self->restore($backup_path, $selected_archive, $destination); } -method _add_path_to_hash($hash, $path, $time) { - my @components = split /\//, $path; - - my $node = $hash; - - if ($path eq ".") { - if ($time > $$node[1]) { - $$node[1] = $time; - } - return; - } - - # each node is an arrayref of the format [$hashref_of_children, $mtime] - # $hashref_of_children is undef if there are no children - for my $component (@components) { - if (!defined($$node[0]->{$component})) { - $$node[0]->{$component} = [undef, $time]; - } - # update mtime per child - if ($time > $$node[1]) { - $$node[1] = $time; - } - $node = $$node[0]->{$component}; - } -} - =head3 search_path my $paths = $app->search_path($pattern) @@ -467,7 +442,7 @@ method _handle_added_archives($borg_archives) { for my $archive (@$add_archives) { my $start = Time::HiRes::gettimeofday(); - my $lookuptable = [{}, 0]; + my $lookuptable = App::BorgRestore::PathTimeTable::Memory->new({db => $self->{db}}); $log->infof("Adding archive %s", $archive); @@ -480,7 +455,7 @@ method _handle_added_archives($borg_archives) { if ($line =~ m/^.{4} (?<year>....)-(?<month>..)-(?<day>..) (?<hour>..):(?<minute>..):(?<second>..) (?<path>.+)$/) { my $time = POSIX::mktime($+{second},$+{minute},$+{hour},$+{day},$+{month}-1,$+{year}-1900); #$log->debugf("Adding path %s with time %s", $+{path}, $time); - $self->_add_path_to_hash($lookuptable, $+{path}, $time); + $lookuptable->add_path($+{path}, $time); } }); @@ -489,7 +464,7 @@ method _handle_added_archives($borg_archives) { $self->{db}->begin_work; $self->{db}->add_archive_name($archive); my $archive_id = $self->{db}->get_archive_id($archive); - $self->_save_node($archive_id, undef, $lookuptable); + $lookuptable->save_nodes($archive_id); $self->{db}->commit; $self->{db}->vacuum; $self->{db}->verify_cache_fill_rate_ok(); @@ -499,20 +474,6 @@ method _handle_added_archives($borg_archives) { } } -method _save_node($archive_id, $prefix, $node) { - for my $child (keys %{$$node[0]}) { - my $path; - $path = $prefix."/" if defined($prefix); - $path .= $child; - - my $time = $$node[0]->{$child}[1]; - $self->{db}->add_path($archive_id, $path, $time); - - $self->_save_node($archive_id, $path, $$node[0]->{$child}); - } -} - - =head3 update_cache $app->update_cache(); |