summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2017-11-21 20:05:57 +0100
committerFlorian Pritz <bluewind@xinu.at>2017-11-21 20:06:22 +0100
commitb7d10e6a9dfe7851479e6948b92c72f240555497 (patch)
tree13fb64aae02a77c464d5fa592639a27deba746e7 /lib
parente10e57b67c00b31b595fb92e83da8bebd8943550 (diff)
downloadApp-BorgRestore-b7d10e6a9dfe7851479e6948b92c72f240555497.tar.gz
App-BorgRestore-b7d10e6a9dfe7851479e6948b92c72f240555497.tar.xz
borg_list: Use JSON with borg 1.1
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'lib')
-rw-r--r--lib/App/BorgRestore/Borg.pm19
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/App/BorgRestore/Borg.pm b/lib/App/BorgRestore/Borg.pm
index 3e531ba..c9e4490 100644
--- a/lib/App/BorgRestore/Borg.pm
+++ b/lib/App/BorgRestore/Borg.pm
@@ -54,12 +54,21 @@ method borg_version() {
method borg_list() {
my @archives;
- $log->debug("Getting archive list");
- run [qw(borg list), $self->{borg_repo}], '>', \my $output or die $log->error("borg list returned $?")."\n";
+ if (Version::Compare::version_compare($self->{borg_version}, "1.1") >= 0) {
+ $log->debug("Getting archive list via json");
+ run [qw(borg list --json), $self->{borg_repo}], '>', \my $output or die $log->error("borg list returned $?")."\n";
+ my $json = decode_json($output);
+ for my $archive (@{$json->{archives}}) {
+ push @archives, $archive->{archive};
+ }
+ } else {
+ $log->debug("Getting archive list");
+ run [qw(borg list), $self->{borg_repo}], '>', \my $output or die $log->error("borg list returned $?")."\n";
- for (split/^/, $output) {
- if (m/^([^\s]+)\s/) {
- push @archives, $1;
+ for (split/^/, $output) {
+ if (m/^([^\s]+)\s/) {
+ push @archives, $1;
+ }
}
}