summaryrefslogtreecommitdiffstats
path: root/lib/App/BorgRestore/PathTimeTable/DB.pm
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2018-09-06 18:19:07 +0200
committerFlorian Pritz <bluewind@xinu.at>2018-09-06 18:19:07 +0200
commitb8d19a541782812a4cd02a408344760d83b7b4e0 (patch)
tree35a76837e3cbb16067438d8d94d2399ee6914224 /lib/App/BorgRestore/PathTimeTable/DB.pm
parent892db03a49333daf7d808395a0a25e81ec2a76ab (diff)
downloadApp-BorgRestore-b8d19a541782812a4cd02a408344760d83b7b4e0.tar.gz
App-BorgRestore-b8d19a541782812a4cd02a408344760d83b7b4e0.tar.xz
Add direct-to-db adding of paths instead of memory only
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'lib/App/BorgRestore/PathTimeTable/DB.pm')
-rw-r--r--lib/App/BorgRestore/PathTimeTable/DB.pm48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/App/BorgRestore/PathTimeTable/DB.pm b/lib/App/BorgRestore/PathTimeTable/DB.pm
new file mode 100644
index 0000000..ac9969e
--- /dev/null
+++ b/lib/App/BorgRestore/PathTimeTable/DB.pm
@@ -0,0 +1,48 @@
+package App::BorgRestore::PathTimeTable::DB;
+use strict;
+use warnings;
+
+use Function::Parameters;
+
+=head1 NAME
+
+App::BorgRestore::PathTimeTable::DB - Directly write new archive data to the database
+
+=head1 DESCRIPTION
+
+This is used by L<App::BorgRestore> to add new archive data into the database.
+Data is written to the database directly and existing data is updated where necessary.
+
+=cut
+
+method new($class: $deps = {}) {
+ return $class->new_no_defaults($deps);
+}
+
+method new_no_defaults($class: $deps = {}) {
+ my $self = {};
+ bless $self, $class;
+ $self->{deps} = $deps;
+ return $self;
+}
+
+method set_archive_id($archive_id) {
+ $self->{archive_id} = $archive_id;
+}
+
+method add_path($path, $time) {
+ while ($path =~ m#/#) {
+ $self->{deps}->{db}->update_path_if_greater($self->{archive_id}, $path, $time);
+ $path =~ s|/[^/]*$||;
+ }
+ $self->{deps}->{db}->update_path_if_greater($self->{archive_id}, $path, $time) unless $path eq ".";
+}
+
+
+method save_nodes() {
+ # do nothing because we already write everything to the DB directly
+}
+
+1;
+
+__END__