]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/amazon_s3.pm
simplify key determination code
[ikiwiki.git] / IkiWiki / Plugin / amazon_s3.pm
index b5629eb4ab383b799a1e2d12e5abbb3addf24e89..cc15fbdb1bd2a967ed7b2aca4e4979b9fd81ffdb 100644 (file)
@@ -125,18 +125,20 @@ sub writefile ($$$;$$) { #{{{
                        # read back in the file that the writer emitted
                        $res=$bucket->add_key_filename($key, "$destdir/$file", \%opts);
                }
-               if ($res && $key=~/(^|\/)index.$config{htmlext}$/) {
+               if ($res && $key=~/(^|.*\/)index.$config{htmlext}$/) {
                        # index.html files are a special case. Since S3 is
                        # not a normal web server, it won't serve up
                        # foo/index.html when foo/ is requested. So the
                        # file has to be stored twice. (This is bad news
                        # when usedirs is enabled!)
-                       $key=~s/index.$config{htmlext}$//;
+                       # TODO: invesitgate using the new copy operation.
+                       #       (It may not be robust enough.)
+                       my $base=$1;
                        if (! $writer) {
-                               $res=$bucket->add_key($key, $content, \%opts);
+                               $res=$bucket->add_key($base, $content, \%opts);
                        }
                        else {
-                               $res=$bucket->add_key_filename($key, "$destdir/$file", \%opts);
+                               $res=$bucket->add_key_filename($base, "$destdir/$file", \%opts);
                        }
                }
                if (! $res) {
@@ -152,10 +154,23 @@ sub writefile ($$$;$$) { #{{{
 sub prune ($) { #{{{
        my $file=shift;
 
-       my $bucket=IkiWiki::Plugin::amazon_s3::getbucket();
-       print STDERR "wrapped prune\n";
+       # If a file in the destdir is being pruned, need to delete it out
+       # of S3 as well.
+       if ($file =~ /^\Q$config{destdir}\/\E(.*)/) {
+               my $key=$config{amazon_s3_prefix}.$1;
+               my $bucket=IkiWiki::Plugin::amazon_s3::getbucket();
+               my $res=$bucket->delete_key($key);
+               if ($res && $key=~/(^|.*\/)index.$config{htmlext}$/) {
+                       # index.html special case: Delete other file too
+                       $res=$bucket->delete_key($1);
+               }
+               if (! $res) {
+                       error(gettext("Failed to delete file from S3: ").
+                               $bucket->err.": ".$bucket->errstr."\n");
+               }
+       }
 
-       return $IkiWiki::Plugin::amazon_s3::subs{'IkiWiki::writefile'}->($file);
+       return $IkiWiki::Plugin::amazon_s3::subs{'IkiWiki::prune'}->($file);
 } #}}}
 
 1