From 0d24899b78307e33d72a693d33178343069187dd Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sun, 2 Apr 2017 21:35:57 +0200 Subject: Move format_timestamp to Helper Signed-off-by: Florian Pritz --- lib/App/BorgRestore.pm | 11 ++--------- lib/App/BorgRestore/Helper.pm | 7 +++++++ script/borg-restore.pl | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/App/BorgRestore.pm b/lib/App/BorgRestore.pm index c300a0b..218be49 100644 --- a/lib/App/BorgRestore.pm +++ b/lib/App/BorgRestore.pm @@ -179,11 +179,11 @@ sub select_archive_timespec { my $target_timestamp = time - $seconds; - $log->debugf("Searching for newest archive that contains a copy before %s", $self->format_timestamp($target_timestamp)); + $log->debugf("Searching for newest archive that contains a copy before %s", App::BorgRestore::Helper::format_timestamp($target_timestamp)); for my $archive (reverse @$archives) { if ($archive->{modification_time} < $target_timestamp) { - $log->debugf("Found archive with timestamp %s", $self->format_timestamp($archive->{modification_time})); + $log->debugf("Found archive with timestamp %s", App::BorgRestore::Helper::format_timestamp($archive->{modification_time})); return $archive; } } @@ -191,13 +191,6 @@ sub select_archive_timespec { die "Failed to find archive matching time specification\n"; } -sub format_timestamp { - my $self = shift; - my $timestamp = shift; - - return POSIX::strftime "%a. %F %H:%M:%S %z", localtime $timestamp; -} - sub _timespec_to_seconds { my $self = shift; my $timespec = shift; diff --git a/lib/App/BorgRestore/Helper.pm b/lib/App/BorgRestore/Helper.pm index 8403ec3..8bc4ceb 100644 --- a/lib/App/BorgRestore/Helper.pm +++ b/lib/App/BorgRestore/Helper.pm @@ -3,6 +3,7 @@ use v5.10; use strict; use warnings; +use POSIX (); sub untaint { my $data = shift; @@ -17,6 +18,12 @@ sub untaint_archive_name { return untaint($archive, qr([a-zA-Z0-9-:+\.]+)); } +sub format_timestamp { + my $timestamp = shift; + + return POSIX::strftime "%a. %F %H:%M:%S %z", localtime $timestamp; +} + 1; __END__ diff --git a/script/borg-restore.pl b/script/borg-restore.pl index 1f66fbd..1365e2e 100755 --- a/script/borg-restore.pl +++ b/script/borg-restore.pl @@ -187,7 +187,7 @@ sub user_select_archive { my $counter = 0; for my $archive (@$archives) { - printf "\e[0;33m%3d: \e[1;33m%s\e[0m %s\n", $counter++, $app->format_timestamp($archive->{modification_time}), $archive->{archive}; + printf "\e[0;33m%3d: \e[1;33m%s\e[0m %s\n", $counter++, App::BorgRestore::Helper::format_timestamp($archive->{modification_time}), $archive->{archive}; } printf "\e[0;34m%s: \e[0m", "Enter ID to restore (Enter to skip)"; -- cgit v1.2.3-24-g4f1b