-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete all files with their previous versions
- Loading branch information
1 parent
a00beae
commit d441be6
Showing
2 changed files
with
28 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from storages.backends.s3boto import S3BotoStorage | ||
|
||
|
||
class ExtendedS3BotoStorage(S3BotoStorage): | ||
|
||
def delete_all(self, name): | ||
""" | ||
Delete the key object and all its versions | ||
:param name: str. S3 key (i.e. path to the file) | ||
""" | ||
name = self._normalize_name(self._clean_name(name)) | ||
self.bucket.delete_key(self._encode_name(name)) | ||
|
||
# Delete all previous versions | ||
for versioned_key in self.bucket.list_versions(prefix=name): | ||
self.bucket.delete_key(versioned_key.name, version_id=versioned_key.version_id) |