summaryrefslogtreecommitdiffstats
path: root/lib/App/BorgRestore/DB.pm
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2017-03-13 11:38:27 +0100
committerFlorian Pritz <bluewind@xinu.at>2017-03-13 11:38:27 +0100
commit00c779c39d99bc046998866de83370f3c75b56d3 (patch)
tree70ef11ff5318ffc4c3ec9a90c099c9922fbd2f39 /lib/App/BorgRestore/DB.pm
parentfb15de83cf35d11f657ebb1ad3aa01b334651264 (diff)
downloadApp-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/DB.pm')
-rw-r--r--lib/App/BorgRestore/DB.pm10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/App/BorgRestore/DB.pm b/lib/App/BorgRestore/DB.pm
index feebd4c..a7c5916 100644
--- a/lib/App/BorgRestore/DB.pm
+++ b/lib/App/BorgRestore/DB.pm
@@ -7,6 +7,7 @@ use App::BorgRestore::Helper;
use Data::Dumper;
use DBI;
+use Log::Any qw($log);
sub new {
my $class = shift;
@@ -15,7 +16,12 @@ sub new {
my $self = {};
bless $self, $class;
- $self->_open_db($db_path);
+ if (! -f $db_path) {
+ my $db = $self->open_db($db_path);
+ $self->{db}->initialize_db();
+ } else {
+ $self->_open_db($db_path);
+ }
return $self;
}
@@ -24,6 +30,7 @@ sub _open_db {
my $self = shift;
my $dbfile = shift;
+ $log->debugf("Opening database at %s", $dbfile);
$self->{dbh} = DBI->connect("dbi:SQLite:dbname=$dbfile","","", {RaiseError => 1, Taint => 1});
$self->{dbh}->do("PRAGMA cache_size=-1024000");
$self->{dbh}->do("PRAGMA strict=ON");
@@ -32,6 +39,7 @@ sub _open_db {
sub initialize_db {
my $self = shift;
+ $log->debug("Creating initial database");
$self->{dbh}->do('create table `files` (`path` text, primary key (`path`)) without rowid;');
$self->{dbh}->do('create table `archives` (`archive_name` text unique);');
}