aboutsummaryrefslogtreecommitdiff
path: root/lib/App/Glacier/Directory.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/App/Glacier/Directory.pm')
-rw-r--r--lib/App/Glacier/Directory.pm34
1 files changed, 14 insertions, 20 deletions
diff --git a/lib/App/Glacier/Directory.pm b/lib/App/Glacier/Directory.pm
index 7271423..0ab998f 100644
--- a/lib/App/Glacier/Directory.pm
+++ b/lib/App/Glacier/Directory.pm
@@ -3,6 +3,7 @@ use strict;
use warnings;
use parent 'App::Glacier::DB';
use Carp;
+use App::Glacier::Timestamp;
our @EXPORT_OK = qw(DIR_UPTODATE DIR_PENDING DIR_OUTDATED);
our %EXPORT_TAGS = ( status => [ qw(DIR_UPTODATE DIR_PENDING DIR_OUTDATED) ] );
@@ -10,18 +11,26 @@ our %EXPORT_TAGS = ( status => [ qw(DIR_UPTODATE DIR_PENDING DIR_OUTDATED) ] );
use constant DB_INFO_KEY => ';00INFO';
sub new {
- my ($class, $backend, $vault, %opts) = @_;
+ my ($class, $backend, $vault, $glacier, %opts) = @_;
my $ttl = delete $opts{ttl};
(my $vault_name = $vault) =~
s/([^A-Za-z_0-9\.-])/sprintf("%%%02X", ord($1))/gex;
map { $opts{$_} =~ s/\$(?:vault|\{vault\})/$vault_name/g } keys %opts;
- my $self = $class->SUPER::new($backend, %opts);
+ my $self = $class->SUPER::new($backend,
+ %opts,
+ create => sub { $glacier->describe_vault($vault_name) },
+ );
if ($self) {
+ $self->{_vault} = $vault;
+ $self->{_glacier} = $glacier;
$self->{_ttl} = $ttl;
}
return $self;
}
+sub vault { shift->{_vault} }
+sub glacier { shift->{_glacier} }
+
# locate(FILE, VERSION)
sub locate {
my ($self, $file, $version) = @_;
@@ -53,24 +62,8 @@ sub last_sync_time {
sub update_sync_time {
my ($self) = @_;
$self->set_info('SyncTimeStamp', time);
- $self->clear_dirty;
}
-sub is_dirty {
- my ($self) = @_;
- return $self->info('Dirty');
-}
-
-sub clear_dirty {
- my ($self) = @_;
- return $self->set_info('Dirty', 0);
-}
-
-sub invalidate {
- my ($self) = @_;
- return $self->set_info('Dirty', 1);
-}
-
sub foreach {
my ($self, $code) = @_;
$self->SUPER::foreach(sub {
@@ -147,8 +140,9 @@ sub status {
my ($self) = @_;
if (defined($self->last_sync_time)) {
- if (time - $self->last_sync_time > $self->{_ttl}
- || $self->info('Dirty')) {
+ my $dsc = timestamp_deserialize($self->glacier->Describe_vault($self->vault));
+ unless ($dsc
+ && $dsc->{LastInventoryDate}->epoch < $self->last_sync_time) {
return DIR_OUTDATED;
}
} else {

Return to:

Send suggestions and report system problems to the System administrator.