diff options
author | Florian Pritz <bluewind@xinu.at> | 2017-06-11 16:05:49 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2017-06-11 16:22:56 +0200 |
commit | 371f62a3bbecd32eecf8ad2c5455771c7be6de91 (patch) | |
tree | 278cfb0ea3dccf4ba6dfe0849593d968d56d02c2 | |
parent | fb0148d9827433f6afeeb1588b6c1e851a265454 (diff) | |
download | App-BorgRestore-371f62a3bbecd32eecf8ad2c5455771c7be6de91.tar.gz App-BorgRestore-371f62a3bbecd32eecf8ad2c5455771c7be6de91.tar.xz |
Use File::pushd for temporary chdir
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r-- | META.json | 1 | ||||
-rw-r--r-- | cpanfile | 1 | ||||
-rw-r--r-- | lib/App/BorgRestore.pm | 23 |
3 files changed, 15 insertions, 10 deletions
@@ -45,6 +45,7 @@ "requires" : { "DBD::SQLite" : "0", "DBI" : "0", + "File::pushd" : "0", "Function::Parameters" : "0", "IPC::Run" : "0", "Log::Any" : "0", @@ -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 |