From 8ff5652f8a640862a5a667ce3d21eafa7d537552 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 14 Aug 2016 15:00:48 +0200 Subject: borg-restore.pl: Fix deletion of old db entries Signed-off-by: Florian Pritz --- borg-restore.pl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/borg-restore.pl b/borg-restore.pl index d9fc8e8..038d23b 100755 --- a/borg-restore.pl +++ b/borg-restore.pl @@ -216,6 +216,7 @@ sub select_archive_timespec { sub format_timestamp { my $timestamp = shift; + # FIXME this outputs UTC. fix it to output local time my $dt = DateTime->from_epoch(epoch => $timestamp); return $dt->strftime("%a. %F %H:%M:%S"); } @@ -360,20 +361,21 @@ sub handle_removed_archives { for my $archive (@$remove_archives) { my $archive_index = get_archive_index($archive, $archives); debug(sprintf("Removing archive %s at index %d", $archive, $archive_index)); + assert($archive_index >= 0) if DEBUG; splice @$archives, $archive_index, 1; while (my ($path, $data) = each %db) { # TODO remove archive indexes all at once if (@$data > 0) { - assert($archive_index >= 0) if DEBUG; - assert($archive_index < @$data) if DEBUG; - splice @$data, $archive_index, 1; + if (exists($$data[$archive_index])) { + splice @$data, $archive_index, 1; + $db{$path} = sanitize_db_data($data); + } + if (@$data == 0) { delete $db{$path}; - } else { - $db{$path} = sanitize_db_data($data); - assert(@$data == @$archives) if DEBUG; } + assert(@$data <= @$archives) if DEBUG; } } save_database($archives); -- cgit v1.2.3-24-g4f1b