diff options
Diffstat (limited to 'lib/App/BorgRestore/PathTimeTable')
-rw-r--r-- | lib/App/BorgRestore/PathTimeTable/DB.pm | 48 | ||||
-rw-r--r-- | lib/App/BorgRestore/PathTimeTable/Memory.pm | 19 |
2 files changed, 65 insertions, 2 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__ diff --git a/lib/App/BorgRestore/PathTimeTable/Memory.pm b/lib/App/BorgRestore/PathTimeTable/Memory.pm index 7aee5b0..012e937 100644 --- a/lib/App/BorgRestore/PathTimeTable/Memory.pm +++ b/lib/App/BorgRestore/PathTimeTable/Memory.pm @@ -5,6 +5,17 @@ use warnings; use Function::Parameters; +=head1 NAME + +App::BorgRestore::PathTimeTable::Memory - In-Memory preparation of new archive data + +=head1 DESCRIPTION + +This is used by L<App::BorgRestore> to add new archive data into the database. +Data is prepared in memory first and only written to the database once. + +=cut + method new($class: $deps = {}) { return $class->new_no_defaults($deps); } @@ -19,6 +30,10 @@ method new_no_defaults($class: $deps = {}) { return $self; } +method set_archive_id($archive_id) { + $self->{archive_id} = $archive_id; +} + method add_path($path, $time) { my @components = split /\//, $path; @@ -45,8 +60,8 @@ method add_path($path, $time) { } } -method save_nodes($archive_id) { - $self->_save_node($archive_id, undef, $self->{lookuptable}); +method save_nodes() { + $self->_save_node($self->{archive_id}, undef, $self->{lookuptable}); } method _save_node($archive_id, $prefix, $node) { |