summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2017-04-02 13:35:14 +0200
committerFlorian Pritz <bluewind@xinu.at>2017-04-02 13:42:15 +0200
commit44441d8c67f155284af4e5f39f29368dd374fdbd (patch)
treea10252bcf311aebbfea4b55205f0d4ca03c92e79
parent5901cde8b9a5a02c3f8cebc70205cd4de3b4e0ca (diff)
downloadApp-BorgRestore-44441d8c67f155284af4e5f39f29368dd374fdbd.tar.gz
App-BorgRestore-44441d8c67f155284af4e5f39f29368dd374fdbd.tar.xz
Move path resolving to main package
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r--lib/App/BorgRestore.pm16
-rwxr-xr-xscript/borg-restore.pl10
2 files changed, 18 insertions, 8 deletions
diff --git a/lib/App/BorgRestore.pm b/lib/App/BorgRestore.pm
index e8a3edb..d072a31 100644
--- a/lib/App/BorgRestore.pm
+++ b/lib/App/BorgRestore.pm
@@ -104,6 +104,22 @@ sub new_no_defaults {
return $self;
}
+sub resolve_relative_path {
+ my $self = shift;
+ my $path = shift;
+
+ my $canon_path = File::Spec->canonpath($path);
+ my $abs_path = abs_path($canon_path);
+
+ if (!defined($abs_path)) {
+ $log->fatalf("Failed to resolve path to absolute path: %s: %s", $canon_path, $!);
+ $log->fatal("Make sure that all parts of the path, except the last one, exist.");
+ return;
+ }
+
+ return $abs_path;
+}
+
sub find_archives {
my $self = shift;
my $path = shift;
diff --git a/script/borg-restore.pl b/script/borg-restore.pl
index 40c0ca1..2beb306 100755
--- a/script/borg-restore.pl
+++ b/script/borg-restore.pl
@@ -164,7 +164,6 @@ use App::BorgRestore::Settings;
use autodie;
use Cwd qw(abs_path);
use File::Basename;
-use File::Spec;
use Getopt::Long;
use Log::Any qw($log);
use Log::Any::Adapter;
@@ -260,13 +259,8 @@ sub main {
exit(1);
}
- my $canon_path = File::Spec->canonpath($path);
- my $abs_path = abs_path($canon_path);
- if (!defined($abs_path)) {
- $log->fatalf("Failed to resolve path to absolute path: %s: %s", $canon_path, $!);
- $log->fatal("Make sure that all parts of the path, except the last one, exist.");
- exit(1);
- }
+ my $abs_path = $app->resolve_relative_path($path);
+ return 1 unless defined $abs_path;
if (!defined($destination)) {
$destination = dirname($abs_path);