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 /lib | |
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>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/App/BorgRestore.pm | 23 |
1 files changed, 13 insertions, 10 deletions
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 |