aboutsummaryrefslogtreecommitdiff
path: root/lib/App
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2017-05-19 11:50:56 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2017-05-19 11:50:56 +0300
commitf0f8633db743bb3edf490ec0ae6035acce38be97 (patch)
treea7c0059c61040dc792c1a15e7b810327176bc36f /lib/App
parent2b029dd7f76e73bf919f9eb7ead5369b59f51587 (diff)
downloadglacier-f0f8633db743bb3edf490ec0ae6035acce38be97.tar.gz
glacier-f0f8633db743bb3edf490ec0ae6035acce38be97.tar.bz2
Implement Directory::status method.
* lib/App/Glacier/Command.pm (config, cfget): New accessors. * lib/App/Glacier/Directory.pm (status): New method. * lib/App/Glacier/Command/ListVault.pm (get_vault_inventory): Use Directory::status. (getopt): More ls-compatible options.
Diffstat (limited to 'lib/App')
-rw-r--r--lib/App/Glacier/Command.pm21
-rw-r--r--lib/App/Glacier/Command/ListVault.pm16
-rw-r--r--lib/App/Glacier/Directory.pm32
3 files changed, 58 insertions, 11 deletions
diff --git a/lib/App/Glacier/Command.pm b/lib/App/Glacier/Command.pm
index b356cb3..e049d94 100644
--- a/lib/App/Glacier/Command.pm
+++ b/lib/App/Glacier/Command.pm
@@ -196,12 +196,12 @@ sub touchdir {
sub jobdb {
my $self = shift;
unless ($self->{_jobdb}) {
- my $file = $self->{_config}->get(qw(database job file));
+ my $file = $self->cfget(qw(database job file));
$self->touchdir(dirname($file));
$self->{_jobdb} = new App::Glacier::DB::GDBM(
$file,
encoding => 'json',
- mode => $self->{_config}->get(qw(database job mode))
+ mode => $self->cfget(qw(database job mode))
);
}
return $self->{_jobdb};
@@ -230,22 +230,33 @@ sub _filename {
sub directory {
my ($self, $vault_name) = @_;
unless (exists($self->{_dir}{$vault_name})) {
- my $file = $self->{_config}->get(qw(database inv directory))
+ my $file = $self->cfget(qw(database inv directory))
. '/' . $self->_filename($vault_name) . '.db';
unless (-e $file) {
return undef unless $self->describe_vault($vault_name);
}
- $self->touchdir($self->{_config}->get(qw(database inv directory)));
+ $self->touchdir($self->cfget(qw(database inv directory)));
$self->{_dir}{$vault_name} =
new App::Glacier::Directory(
$file,
encoding => 'json',
- mode => $self->{_config}->get(qw(database inv mode))
+ mode => $self->cfget(qw(database inv mode)),
+ ttl => $self->cfget(qw(database inv ttl))
);
}
return $self->{_dir}{$vault_name};
}
+sub config {
+ my ($self) = @_;
+ return $self->{_config};
+}
+
+sub cfget {
+ my ($self, @path) = @_;
+ return $self->config->get(@path);
+}
+
sub error {
my ($self, @msg) = @_;
print STDERR "$self->{_progname}: " if $self->{_progname};
diff --git a/lib/App/Glacier/Command/ListVault.pm b/lib/App/Glacier/Command/ListVault.pm
index a0cd2c4..1df44b6 100644
--- a/lib/App/Glacier/Command/ListVault.pm
+++ b/lib/App/Glacier/Command/ListVault.pm
@@ -7,6 +7,7 @@ use parent qw(App::Glacier::Command);
use App::Glacier::DateTime;
use App::Glacier::Timestamp;
use App::Glacier::Glob;
+use App::Glacier::Directory qw(:status);
=head1 NAME
@@ -15,7 +16,11 @@ glacier list - list vaults or archives
=head1 SYNOPSIS
B<glacier list>
-[B<-dl>]
+[B<-SUdlhtr>]
+[B<--human-readable>]
+[B<--sort=>B<none>|B<name>|B<time>|B<size>]
+[B<--reverse>]
+[B<--time-style=>B<default>|B<full-iso>|B<long-iso>|B<iso>|B<locale>|B<+I<FORMAT>>]
[I<VAULT>]
[I<FILE>...]
@@ -60,7 +65,8 @@ sub getopt {
'sort=s' => \$self->{_options}{sort},
't' => sub { $self->{_options}{sort} = 'time' },
'S' => sub { $self->{_options}{sort} = 'size' },
- 'h' => \$self->{_options}{h},
+ 'U' => sub { $self->{_options}{sort} = 'none' },
+ 'human-readable|h' => \$self->{_options}{h},
'reverse|r' => \$self->{_options}{r},
'time-style=s' => \$self->{_options}{time_style},
%opts);
@@ -195,7 +201,7 @@ sub _check_dir {
if (defined($dir->last_sync_time)) {
if (time - $dir->last_sync_time >
- $self->{_config}->get(qw(database inv ttl))) {
+ $self->cfget(qw(database inv ttl))) {
return CACHE_UPDATE;
}
} else {
@@ -210,11 +216,11 @@ sub get_vault_inventory {
$self->abend(EX_FAILURE, "no such vault: $vault_name")
unless defined $dir;
- if ((my $ck = $self->_check_dir($dir)) != CACHE_OK) {
+ if ((my $status = $dir->status) != DIR_UPTODATE) {
require App::Glacier::Command::Sync;
my $sync = new App::Glacier::Command::Sync;
unless ($sync->sync($vault_name)) {
- if ($ck == CACHE_UPDATE) {
+ if ($status == DIR_OUTDATED) {
$self->error("using cached data");
} else {
exit(EX_TEMPFAIL);
diff --git a/lib/App/Glacier/Directory.pm b/lib/App/Glacier/Directory.pm
index 986236b..bf588ed 100644
--- a/lib/App/Glacier/Directory.pm
+++ b/lib/App/Glacier/Directory.pm
@@ -5,8 +5,19 @@ require App::Glacier::DB::GDBM;
use parent 'App::Glacier::DB::GDBM';
use Carp;
+our @EXPORT_OK = qw(DIR_UPTODATE DIR_PENDING DIR_OUTDATED);
+our %EXPORT_TAGS = ( status => [ qw(DIR_UPTODATE DIR_PENDING DIR_OUTDATED) ] );
+
use constant DB_INFO_KEY => ';00INFO';
-
+
+sub new {
+ my ($class, $file, %opts) = @_;
+ my $ttl = delete $opts{ttl};
+ my $self = $class->SUPER::new($file, %opts);
+ $self->{_ttl} = $ttl;
+ return $self;
+}
+
# locate(FILE, VERSION)
sub locate {
my ($self, $file, $version) = @_;
@@ -85,3 +96,22 @@ sub tempname {
}
return $s;
}
+
+use constant {
+ DIR_UPTODATE => 0, # Directory is up to date
+ DIR_PENDING => 1, # Directory is empty, needs synchronization
+ DIR_OUTDATED => 2 # Directory needs update
+};
+
+sub status {
+ my ($self) = @_;
+
+ if (defined($self->last_sync_time)) {
+ if (time - $self->last_sync_time > $self->{_ttl}) {
+ return DIR_OUTDATED;
+ }
+ } else {
+ return DIR_PENDING;
+ }
+ return DIR_UPTODATE;
+}

Return to:

Send suggestions and report system problems to the System administrator.