summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--META.json1
-rw-r--r--cpanfile1
-rw-r--r--lib/App/BorgRestore.pm23
3 files changed, 15 insertions, 10 deletions
diff --git a/META.json b/META.json
index f4e8529..840ca4b 100644
--- a/META.json
+++ b/META.json
@@ -45,6 +45,7 @@
"requires" : {
"DBD::SQLite" : "0",
"DBI" : "0",
+ "File::pushd" : "0",
"Function::Parameters" : "0",
"IPC::Run" : "0",
"Log::Any" : "0",
diff --git a/cpanfile b/cpanfile
index ea9b833..7a2609f 100644
--- a/cpanfile
+++ b/cpanfile
@@ -6,6 +6,7 @@ requires 'IPC::Run';
requires 'Log::Any';
requires 'Log::Any::Adapter::Log4perl';
requires 'Log::Log4perl';
+requires 'File::pushd';
on 'test' => sub {
requires 'Test::More', '0.98';
diff --git a/lib/App/BorgRestore.pm b/lib/App/BorgRestore.pm
index a3f4838..d250b61 100644
--- a/lib/App/BorgRestore.pm
+++ b/lib/App/BorgRestore.pm
@@ -14,6 +14,7 @@ use autodie;
use Carp;
use Cwd qw(abs_path getcwd);
use File::Basename;
+use File::pushd;
use File::Spec;
use File::Temp;
use Function::Parameters;
@@ -330,16 +331,18 @@ method restore($path, $archive, $destination) {
my $components_to_strip =()= $path =~ /\//g;
$log->debugf("CWD is %s", getcwd());
- $log->debugf("Changing CWD to %s", $destination);
- mkdir($destination) unless -d $destination;
- chdir($destination) or die "Failed to chdir: $!";
- # TODO chdir back to original after restore
-
- my $final_destination = abs_path($basename);
- $final_destination = App::BorgRestore::Helper::untaint($final_destination, qr(.*));
- $log->debugf("Removing %s", $final_destination);
- File::Path::remove_tree($final_destination);
- $self->{borg}->restore($components_to_strip, $archive_name, $path);
+ {
+ $log->debugf("Changing CWD to %s", $destination);
+ mkdir($destination) unless -d $destination;
+ my $workdir = pushd($destination, {untaint_pattern => qr{^(.*)$}});
+
+ my $final_destination = abs_path($basename);
+ $final_destination = App::BorgRestore::Helper::untaint($final_destination, qr(.*));
+ $log->debugf("Removing %s", $final_destination);
+ File::Path::remove_tree($final_destination);
+ $self->{borg}->restore($components_to_strip, $archive_name, $path);
+ }
+ $log->debugf("CWD is %s", getcwd());
}
=head3 restore_simple