From f38ea4f75d4a44859b9a1c7ae56c1ebee1ab37e4 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 14 Aug 2016 15:50:28 +0200 Subject: borg-restore.pl: misc - switch back to undef instead of -1 - fix incorrect assertion - clean up path before resolving Signed-off-by: Florian Pritz --- borg-restore.pl | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/borg-restore.pl b/borg-restore.pl index 038d23b..ba4998c 100755 --- a/borg-restore.pl +++ b/borg-restore.pl @@ -87,6 +87,7 @@ use File::Basename; use File::Copy; use File::Path qw(mkpath); use File::Slurp; +use File::Spec; use File::Temp; use Getopt::Long; use IO::Compress::Gzip qw($GzipError); @@ -398,7 +399,7 @@ sub sanitize_db_data { if (defined($item)) { push @ret, $item + 0; } else { - push @ret, -1; + push @ret, undef; } } @@ -554,7 +555,7 @@ sub get_mtime_from_lookuptable { for my $component (@components) { $node = $$node[0]->{$component}; if (!defined($node)) { - return -1; + return undef; } } return $$node[1]; @@ -564,12 +565,12 @@ sub clean_db { my $archives = shift; while (my ($path, $data) = each %db) { - # check if data is empty or all fields in data are -1 - if (!@$data || all { $_ != -1 } @$data) { + # check if data is empty or all fields in data are undef + if (!@$data || all { !defined($_) } @$data) { debug("Deleting path because it's not part of any archive: ", $path); delete $db{$path}; } - assert(@$data == @$archives) if DEBUG; + assert(@$data <= @$archives) if DEBUG; } } @@ -621,7 +622,15 @@ sub main { exit(1); } - my $abs_path = abs_path($path); + my $canon_path = File::Spec->canonpath($path); + my $abs_path = abs_path($canon_path); + print Dumper($abs_path, $path, $canon_path); + if (!defined($abs_path)) { + say STDERR "Error: Failed to resolve path to absolute path: $canon_path: $!"; + say STDERR "Make sure that all parts of the path, except the last one, exist."; + exit(1); + } + if (!defined($destination)) { $destination = $abs_path; } -- cgit v1.2.3-24-g4f1b