diff options
-rw-r--r-- | lib/App/BorgRestore.pm | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/lib/App/BorgRestore.pm b/lib/App/BorgRestore.pm index 24e9d9c..a8d3d5d 100644 --- a/lib/App/BorgRestore.pm +++ b/lib/App/BorgRestore.pm @@ -96,8 +96,8 @@ method new($class: $deps = {}) { my $db_path = App::BorgRestore::Settings::get_db_path(); my $cache_size = $App::BorgRestore::Settings::sqlite_cache_size; - $self->{borg} = $deps->{borg} // App::BorgRestore::Borg->new($App::BorgRestore::Settings::borg_repo); - $self->{db} = $deps->{db} // App::BorgRestore::DB->new($db_path, $cache_size); + $self->{deps}->{borg} = $deps->{borg} // App::BorgRestore::Borg->new($App::BorgRestore::Settings::borg_repo); + $self->{deps}->{db} = $deps->{db} // App::BorgRestore::DB->new($db_path, $cache_size); return $self; } @@ -113,8 +113,8 @@ method new_no_defaults($class: $deps) { my $self = {}; bless $self, $class; - $self->{borg} = $deps->{borg}; - $self->{db} = $deps->{db}; + $self->{deps}->{borg} = $deps->{borg}; + $self->{deps}->{db} = $deps->{db}; return $self; } @@ -184,7 +184,7 @@ method find_archives($path) { $log->debugf("Searching for archives containing '%s'", $path); - my $archives = $self->{db}->get_archives_for_path($path); + my $archives = $self->{deps}->{db}->get_archives_for_path($path); for my $archive (@$archives) { my $modtime = $archive->{modification_time}; @@ -220,7 +220,7 @@ method get_all_archives() { $log->debugf("Fetching list of all archives"); - my $archives = $self->{borg}->borg_list_time(); + my $archives = $self->{deps}->{borg}->borg_list_time(); for my $archive (@$archives) { push @ret, $archive; @@ -244,7 +244,7 @@ Returns 1 if the cache contains any archive data, 0 otherwise. =cut method cache_contains_data() { - my $existing_archives = $self->{db}->get_archive_names(); + my $existing_archives = $self->{deps}->{db}->get_archive_names(); return @{$existing_archives}+0 > 0 ? 1 : 0; } @@ -349,7 +349,7 @@ method restore($path, $archive, $destination) { $final_destination = App::BorgRestore::Helper::untaint($final_destination, qr(.*)); $log->debugf("Removing %s", $final_destination); File::Path::remove_tree($final_destination); - $self->{borg}->restore($components_to_strip, $archive_name, $path); + $self->{deps}->{borg}->restore($components_to_strip, $archive_name, $path); } $log->debugf("CWD is %s", getcwd()); } @@ -390,7 +390,7 @@ automatically wrapped between two % so it may match anywhere in the path. method search_path($pattern) { $pattern = '%'.$pattern.'%' if $pattern !~ m/%/; - return $self->{db}->search_path($pattern); + return $self->{deps}->{db}->search_path($pattern); } =head3 get_missing_items @@ -415,7 +415,7 @@ method get_missing_items($have, $want) { method _handle_removed_archives($borg_archives) { my $start = Time::HiRes::gettimeofday(); - my $existing_archives = $self->{db}->get_archive_names(); + my $existing_archives = $self->{deps}->{db}->get_archive_names(); # TODO this name is slightly confusing, but it works as expected and # returns elements that are in the previous list, but missing in the new @@ -425,11 +425,11 @@ method _handle_removed_archives($borg_archives) { if (@$remove_archives) { for my $archive (@$remove_archives) { $log->infof("Removing archive %s", $archive); - $self->{db}->begin_work; - $self->{db}->remove_archive($archive); - $self->{db}->commit; - $self->{db}->vacuum; - $self->{db}->verify_cache_fill_rate_ok(); + $self->{deps}->{db}->begin_work; + $self->{deps}->{db}->remove_archive($archive); + $self->{deps}->{db}->commit; + $self->{deps}->{db}->vacuum; + $self->{deps}->{db}->verify_cache_fill_rate_ok(); } my $end = Time::HiRes::gettimeofday(); @@ -438,22 +438,22 @@ method _handle_removed_archives($borg_archives) { } method _handle_added_archives($borg_archives) { - my $archives = $self->{db}->get_archive_names(); + my $archives = $self->{deps}->{db}->get_archive_names(); my $add_archives = $self->get_missing_items($archives, $borg_archives); for my $archive (@$add_archives) { my $start = Time::HiRes::gettimeofday(); my $lookuptable_class = $App::BorgRestore::Settings::prepare_data_in_memory == 1 ? "Memory" : "DB"; $log->debugf("Using '%s' class for PathTimeTable", $lookuptable_class); - my $lookuptable = "App::BorgRestore::PathTimeTable::$lookuptable_class"->new({db => $self->{db}}); + my $lookuptable = "App::BorgRestore::PathTimeTable::$lookuptable_class"->new({db => $self->{deps}->{db}}); $log->infof("Adding archive %s", $archive); - $self->{db}->begin_work; - $self->{db}->add_archive_name($archive); - my $archive_id = $self->{db}->get_archive_id($archive); + $self->{deps}->{db}->begin_work; + $self->{deps}->{db}->add_archive_name($archive); + my $archive_id = $self->{deps}->{db}->get_archive_id($archive); $lookuptable->set_archive_id($archive_id); - $self->{borg}->list_archive($archive, sub { + $self->{deps}->{borg}->list_archive($archive, sub { my $line = shift; # roll our own parsing of timestamps for speed since we will be parsing # a huge number of lines here @@ -469,9 +469,9 @@ method _handle_added_archives($borg_archives) { my $borg_time = Time::HiRes::gettimeofday; $lookuptable->save_nodes(); - $self->{db}->commit; - $self->{db}->vacuum; - $self->{db}->verify_cache_fill_rate_ok(); + $self->{deps}->{db}->commit; + $self->{deps}->{db}->vacuum; + $self->{deps}->{db}->verify_cache_fill_rate_ok(); my $end = Time::HiRes::gettimeofday(); $log->debugf("Adding archive finished after: %.5fs (parsing borg output took %.5fs)", $end - $start, $borg_time - $start); @@ -495,15 +495,15 @@ method update_cache() { $log->debug("Updating cache if required"); - my $borg_archives = $self->{borg}->borg_list(); + my $borg_archives = $self->{deps}->{borg}->borg_list(); # write operations benefit from the large cache so set the cache size here - $self->{db}->set_cache_size(); + $self->{deps}->{db}->set_cache_size(); $self->_handle_removed_archives($borg_archives); $self->_handle_added_archives($borg_archives); - $log->debugf("DB contains information for %d archives in %d rows", scalar(@{$self->{db}->get_archive_names()}), $self->{db}->get_archive_row_count()); - $self->{db}->verify_cache_fill_rate_ok(); + $log->debugf("DB contains information for %d archives in %d rows", scalar(@{$self->{deps}->{db}->get_archive_names()}), $self->{deps}->{db}->get_archive_row_count()); + $self->{deps}->{db}->verify_cache_fill_rate_ok(); } |