mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-24 02:08:36 +00:00
Delete S3 file only when bucket is the current one
This commit is contained in:
@@ -150,8 +150,10 @@ class IrAttachment(models.Model):
|
||||
s3uri = S3Uri(fname)
|
||||
bucket_name = s3uri.bucket()
|
||||
item_name = s3uri.item()
|
||||
|
||||
bucket = self._get_s3_bucket(name=bucket_name)
|
||||
# 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'):
|
||||
bucket = self._get_s3_bucket()
|
||||
filekey = bucket.get_key(item_name)
|
||||
if not count and filekey:
|
||||
try:
|
||||
@@ -160,7 +162,8 @@ class IrAttachment(models.Model):
|
||||
'file %s deleted on the object storage' % (fname,)
|
||||
)
|
||||
except S3ResponseError:
|
||||
# log verbose error from s3, return short message for user
|
||||
# log verbose error from s3, return short message for
|
||||
# user
|
||||
_logger.exception(
|
||||
'Error during deletion of the file %s' % fname
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user