Skip to content

Commit 68735b6

Browse files
committed
Fixed deletion of all lifecycle rules
1 parent 99fd6de commit 68735b6

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

Diff for: IDEAS

-5
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@
4545
- Verify PHP package installation in Virtualmin
4646
- Check that DKIM works
4747

48-
- Amazon glacier support
49-
- how to clear all lifecycle rules
50-
- Documentation
51-
- https://www.virtualmin.com/node/27461
52-
5348
- Use Envelope-from address in hamtrap checking
5449
- https://www.virtualmin.com/node/27501
5550
- don't set smtpd_sasl_authenticated_header

Diff for: S3.pm

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ sub canonical_string {
9090
$buf .= '?location';
9191
} elsif ($path =~ /[&?]uploads($|=|&)/) {
9292
$buf .= '?uploads';
93+
} elsif ($path =~ /[&?]lifecycle($|=|&)/) {
94+
$buf .= '?lifecycle';
9395
} elsif ($path =~ /[&?]partNumber=([0-9]+)&uploadId=([^&]+)/) {
9496
$buf .= '?partNumber='.$1.'&uploadId='.$2;
9597
} elsif ($path =~ /[&?]uploadId=([^&]+)/) {

Diff for: S3/AWSAuthConnection.pm

+8
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,14 @@ sub put_bucket_lifecycle {
220220
$self->_make_request('PUT', "$bucket/?lifecycle", $headers, $lifecycle_xml_doc));
221221
}
222222

223+
sub delete_bucket_lifecycle {
224+
my ($self, $bucket, $headers) = @_;
225+
croak 'must specify bucket' unless $bucket;
226+
$headers ||= {};
227+
228+
return S3::Response->new($self->_make_request('DELETE', "$bucket/?lifecycle", $headers));
229+
}
230+
223231
sub abort_upload {
224232
my ($self, $bucket, $key, $uploadid, $headers) = @_;
225233
croak 'must specify bucket' unless $bucket;

Diff for: backup_form.cgi

+2-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ foreach $dest (@dests) {
185185
# Add purging option
186186
@grid = ( );
187187
if (!$nopurge) {
188-
push(@grid, &hlink($text{'backup_purge'}, "backup_purge"));
188+
push(@grid, &hlink($text{'backup_purge'}, "backup_purge").
189+
" ");
189190
push(@grid, &ui_opt_textbox("purge".$i, $purges[$i], 5,
190191
$text{'backup_purgeno'}, $text{'backup_purgeyes'})." ".
191192
$text{'newbw_days'});

Diff for: s3-lib.pl

+14-4
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,20 @@ sub s3_put_bucket_lifecycle
474474
&require_s3();
475475
local ($akey, $skey, $bucket, $lifecycle) = @_;
476476
local $conn = &make_s3_connection($akey, $skey);
477-
local $xs = XML::Simple->new(KeepRoot => 1);
478-
local $xml = $xs->XMLout({ 'LifecycleConfiguration' => [ $lifecycle ] });
479-
local $response = $conn->put_bucket_lifecycle($bucket, $xml);
480-
return $response->http_response->code == 200 ? undef :
477+
local $response;
478+
if (@{$lifecycle->{'Rule'}}) {
479+
# Update lifecycle config
480+
local $xs = XML::Simple->new(KeepRoot => 1);
481+
local $xml = $xs->XMLout(
482+
{ 'LifecycleConfiguration' => [ $lifecycle ] });
483+
$response = $conn->put_bucket_lifecycle($bucket, $xml);
484+
}
485+
else {
486+
# Delete lifecycle config
487+
$response = $conn->delete_bucket_lifecycle($bucket, $xml);
488+
}
489+
return $response->http_response->code == 200 ||
490+
$response->http_response->code == 204 ? undef :
481491
&text('s3_eputlifecycle', &extract_s3_message($response));
482492
}
483493

0 commit comments

Comments
 (0)