diff options
author | Florian Pritz <bluewind@xinu.at> | 2017-03-04 00:15:30 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2017-03-04 00:18:04 +0100 |
commit | 12a21ee5bbde99ae5273f777aaf5e3c606b69729 (patch) | |
tree | 7138bc09e1b36d4147e975136828000bac472093 | |
parent | e400b5e8672c1eea428e14ca82c0ce0ed223db8d (diff) | |
download | App-BorgRestore-12a21ee5bbde99ae5273f777aaf5e3c606b69729.tar.gz App-BorgRestore-12a21ee5bbde99ae5273f777aaf5e3c606b69729.tar.xz |
Borg::list_archive: Use open() instead of IPC::Run for performance
Surprisingly the callback isn't actually that bad, but IPC::Run
(probably new_chunker) adds quite some overhead. Since open supports
everything we need, use that instead.
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r-- | lib/App/BorgRestore.pm | 3 | ||||
-rw-r--r-- | lib/App/BorgRestore/Borg.pm | 9 |
2 files changed, 9 insertions, 3 deletions
diff --git a/lib/App/BorgRestore.pm b/lib/App/BorgRestore.pm index 1fb5124..4ca2716 100644 --- a/lib/App/BorgRestore.pm +++ b/lib/App/BorgRestore.pm @@ -314,7 +314,7 @@ sub handle_added_archives { $self->debug(sprintf("Adding archive %s", $archive)); - my $proc = $self->{borg}->list_archive($archive, sub { + $self->{borg}->list_archive($archive, sub { my $line = shift; # roll our own parsing of timestamps for speed since we will be parsing # a huge number of lines here @@ -325,7 +325,6 @@ sub handle_added_archives { $self->add_path_to_hash($lookuptable, $+{path}, $time); } }); - $proc->finish() or die "borg list returned $?"; $self->debug(sprintf("Finished parsing borg output after %.5fs. Adding to db", Time::HiRes::gettimeofday - $start)); diff --git a/lib/App/BorgRestore/Borg.pm b/lib/App/BorgRestore/Borg.pm index 412269f..8b4e953 100644 --- a/lib/App/BorgRestore/Borg.pm +++ b/lib/App/BorgRestore/Borg.pm @@ -43,7 +43,14 @@ sub list_archive { my $archive = shift; my $cb = shift; - return start [qw(borg list --list-format), '{isomtime} {path}{NEWLINE}', "::".$archive], ">", new_chunker, $cb; + open (my $fh, '-|', 'borg', qw/list --list-format/, '{isomtime} {path}{NEWLINE}', "::".$archive); + while (<$fh>) { + $cb->($_); + } + + # this is slow + #return start [qw(borg list --list-format), '{isomtime} {path}{NEWLINE}', "::".$archive], ">", new_chunker, $cb; + #$proc->finish() or die "borg list returned $?"; } 1; |