diff options
author | Florian Pritz <bluewind@xinu.at> | 2017-03-13 11:38:27 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2017-03-13 11:38:27 +0100 |
commit | 00c779c39d99bc046998866de83370f3c75b56d3 (patch) | |
tree | 70ef11ff5318ffc4c3ec9a90c099c9922fbd2f39 /lib/App/BorgRestore.pm | |
parent | fb15de83cf35d11f657ebb1ad3aa01b334651264 (diff) | |
download | App-BorgRestore-00c779c39d99bc046998866de83370f3c75b56d3.tar.gz App-BorgRestore-00c779c39d99bc046998866de83370f3c75b56d3.tar.xz |
Refactor db creation and cache dir creation
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'lib/App/BorgRestore.pm')
-rw-r--r-- | lib/App/BorgRestore.pm | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/lib/App/BorgRestore.pm b/lib/App/BorgRestore.pm index 8599f6b..bb382e9 100644 --- a/lib/App/BorgRestore.pm +++ b/lib/App/BorgRestore.pm @@ -5,10 +5,14 @@ use warnings; our $VERSION = "2.0.0"; +use App::BorgRestore::Borg; +use App::BorgRestore::DB; +use App::BorgRestore::Helper; +use App::BorgRestore::Settings; + use autodie; use Cwd qw(abs_path getcwd); use File::Basename; -use File::Path qw(mkpath); use File::Slurp; use File::Spec; use File::Temp; @@ -65,9 +69,12 @@ sub new { my $self = {}; bless $self, $class; + my $db_path = App::BorgRestore::Settings::get_cache_path('archives.db'); + # TODO: make db_path configurable, probably settings too + $self->{opts} = $opts; $self->{borg} = $deps->{borg} // App::BorgRestore::Borg->new(); - $self->{db} = $deps->{db} // App::BorgRestore::DB->new(); + $self->{db} = $deps->{db} // App::BorgRestore::DB->new($db_path); return $self; } @@ -214,17 +221,6 @@ sub restore { $self->{borg}->restore($components_to_strip, $archive_name, $path); } -sub get_cache_dir { - my $self = shift; - return "$App::BorgRestore::Settings::cache_path_base/v2"; -} - -sub get_cache_path { - my $self = shift; - my $item = shift; - return $self->get_cache_dir()."/$item"; -} - sub get_temp_path { my $self = shift; my $item = shift; @@ -353,15 +349,6 @@ sub build_archive_cache { my $borg_archives = $self->{borg}->borg_list(); my $db_path = $self->get_cache_path('archives.db'); - # ensure the cache directory exists - mkpath($self->get_cache_dir(), {mode => oct(700)}); - - if (! -f $db_path) { - $self->debug("Creating initial database"); - my $db = $self->open_db($db_path); - $self->{db}->initialize_db(); - } - my $archives = $self->{db}->get_archive_names(); $self->debug(sprintf("Found %d archives in db", scalar(@$archives))); |