summaryrefslogtreecommitdiffstats
path: root/lib/App
diff options
context:
space:
mode:
Diffstat (limited to 'lib/App')
-rw-r--r--lib/App/BorgRestore.pm8
-rw-r--r--lib/App/BorgRestore/Borg.pm12
2 files changed, 17 insertions, 3 deletions
diff --git a/lib/App/BorgRestore.pm b/lib/App/BorgRestore.pm
index d66b7a4..400c2fd 100644
--- a/lib/App/BorgRestore.pm
+++ b/lib/App/BorgRestore.pm
@@ -60,11 +60,13 @@ Florian Pritz E<lt>bluewind@xinu.atE<gt>
sub new {
my $class = shift;
my $opts = shift;
+ my $deps = shift;
my $self = {};
bless $self, $class;
$self->{opts} = $opts;
+ $self->{borg} = $deps->{borg} // App::BorgRestore::Borg->new();
return $self;
}
@@ -199,7 +201,7 @@ sub restore {
$final_destination = App::BorgRestore::Helper::untaint($final_destination, qr(.*));
$self->debug("Removing ".$final_destination);
File::Path::remove_tree($final_destination);
- App::BorgRestore::Borg::restore($components_to_strip, $archive_name, $path);
+ $self->{borg}->restore($components_to_strip, $archive_name, $path);
}
sub get_cache_dir {
@@ -312,7 +314,7 @@ sub handle_added_archives {
$self->debug(sprintf("Adding archive %s", $archive));
- my $proc = App::BorgRestore::Borg::list_archive($archive, \*OUT);
+ my $proc = $self->{borg}->list_archive($archive, \*OUT);
while (<OUT>) {
# roll our own parsing of timestamps for speed since we will be parsing
# a huge number of lines here
@@ -341,7 +343,7 @@ sub handle_added_archives {
sub build_archive_cache {
my $self = shift;
- my $borg_archives = App::BorgRestore::Borg::borg_list();
+ my $borg_archives = $self->{borg}->borg_list();
my $db_path = $self->get_cache_path('archives.db');
# ensure the cache directory exists
diff --git a/lib/App/BorgRestore/Borg.pm b/lib/App/BorgRestore/Borg.pm
index 426f809..ebedb7d 100644
--- a/lib/App/BorgRestore/Borg.pm
+++ b/lib/App/BorgRestore/Borg.pm
@@ -5,7 +5,17 @@ use strict;
use IPC::Run qw(run start);
+sub new {
+ my $class = shift;
+
+ my $self = {};
+ bless $self, $class;
+
+ return $self;
+}
+
sub borg_list {
+ my $self = shift;
my @archives;
run [qw(borg list)], '>', \my $output or die "borg list returned $?";
@@ -20,6 +30,7 @@ sub borg_list {
}
sub restore {
+ my $self = shift;
my $components_to_strip = shift;
my $archive_name = shift;
my $path = shift;
@@ -28,6 +39,7 @@ sub restore {
}
sub list_archive {
+ my $self = shift;
my $archive = shift;
my $fh = shift;