Skip to content

Commit

Permalink
temp rebasing PR 151 (00c3358)
Browse files Browse the repository at this point in the history
  • Loading branch information
roboadhoc committed Jan 2, 2024
2 parents 1f7c75b + 00c3358 commit 71632f2
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions attachment_s3/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,22 @@ def _store_file_delete(self, fname):
s3uri = S3Uri(fname)
bucket_name = s3uri.bucket()
item_name = s3uri.item()
skip_objects_deletion = os.environ.get(
'SKIP_OBJECTS_DELETION') or False
skip_objects_deletion = os.environ.get("SKIP_OBJECTS_DELETION") or False
# delete the file only if it is on the current configured bucket
# otherwise, we might delete files used on a different environment
if bucket_name == os.environ.get("AWS_BUCKETNAME") and \
not skip_objects_deletion:
bucket = self._get_s3_bucket()
obj = bucket.Object(key=item_name)
try:
bucket.meta.client.head_object(Bucket=bucket.name, Key=item_name)
obj.delete()
_logger.info("file %s deleted on the object storage" % (fname,))
except ClientError:
# log verbose error from s3, return short message for
# user
_logger.exception("Error during deletion of the file %s" % fname)
if bucket_name == os.environ.get("AWS_BUCKETNAME"):
if not skip_objects_deletion:
bucket = self._get_s3_bucket()
obj = bucket.Object(key=item_name)
try:
bucket.meta.client.head_object(Bucket=bucket.name, Key=item_name)
obj.delete()
_logger.info("file %s deleted on the object storage" % (fname,))
except ClientError:
# log verbose error from s3, return short message for
# user
_logger.exception("Error during deletion of the file %s" % fname)
else:
_logger.exception("file %s deletion on the object storage skipped by policy" % fname)
else:
return super()._store_file_delete(fname)

0 comments on commit 71632f2

Please sign in to comment.