summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2018-12-16 12:41:17 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2018-12-16 12:41:17 (GMT)
commit890224d5969b8d488f59fccf7445675caaaaf8ce (patch) (side-by-side diff)
tree17c4fb1f59fc4543a85c18209170703e3fcbce52
parentf9b3dff3aa426431d89d375c10383c0b0c9f76c7 (diff)
downloadglacier-890224d5969b8d488f59fccf7445675caaaaf8ce.tar.gz
glacier-890224d5969b8d488f59fccf7445675caaaaf8ce.tar.bz2
Use LastInventoryDate from the vault description to control directory validity
* lib/App/Glacier/Command.pm (directory): Pass pointer to glacier to the directory constructor. * lib/App/Glacier/Command/Put.pm (_upload): Don't call directory invalidate. * lib/App/Glacier/Command/Sync.pm (sync): Likewise. * lib/App/Glacier/Directory.pm (new): Expect a pointer to glacier as 3rd argument. (vault, glacier): New methods. (is_dirty, clear_dirty, invalidate): Remove methods. (status): Use LastInventoryDate from the vault description to decide the directory status.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--lib/App/Glacier/Command.pm2
-rw-r--r--lib/App/Glacier/Command/Put.pm1
-rw-r--r--lib/App/Glacier/Command/Sync.pm1
-rw-r--r--lib/App/Glacier/Directory.pm34
4 files changed, 15 insertions, 23 deletions
diff --git a/lib/App/Glacier/Command.pm b/lib/App/Glacier/Command.pm
index 747abcb..449950c 100644
--- a/lib/App/Glacier/Command.pm
+++ b/lib/App/Glacier/Command.pm
@@ -216,7 +216,7 @@ sub directory {
new App::Glacier::Directory(
$be,
$vault_name,
- create => sub { $self->describe_vault($vault_name) },
+ $self->glacier,
%{$self->config->as_hash(qw(database inv)) // {}});
}
return $self->{_dir}{$vault_name};
diff --git a/lib/App/Glacier/Command/Put.pm b/lib/App/Glacier/Command/Put.pm
index 304f889..fb5b451 100644
--- a/lib/App/Glacier/Command/Put.pm
+++ b/lib/App/Glacier/Command/Put.pm
@@ -152,7 +152,6 @@ sub _upload {
Size => $size,
CreationDate => new App::Glacier::DateTime,
ArchiveDescription => $remotename });
- $dir->invalidate;
}
sub _upload_simple {
diff --git a/lib/App/Glacier/Command/Sync.pm b/lib/App/Glacier/Command/Sync.pm
index 4904fa6..e045ce6 100644
--- a/lib/App/Glacier/Command/Sync.pm
+++ b/lib/App/Glacier/Command/Sync.pm
@@ -72,7 +72,6 @@ sub sync {
my ($self, $vault_name, %opts) = @_;
my $dir = $self->directory($vault_name);
- $dir->invalidate if $opts{force};
my $job = new App::Glacier::Job::InventoryRetrieval(
$self, $vault_name,
invalidate => $opts{force});
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.