details:   
https://code.tryton.org/contrib/tryton-filestore-cellar/commit/7047fb853e79
branch:    default
user:      Cédric Krier <[email protected]>
date:      Sat Oct 31 14:33:14 2026 +0100
description:
        Implement delete for trytond >= 8.0
diffstat:

 CHANGELOG                  |   1 +
 tryton_filestore_cellar.py |  26 +++++++++++++++++++++++++-
 2 files changed, 26 insertions(+), 1 deletions(-)

diffs (51 lines):

diff -r 8e4bdd748cc6 -r 7047fb853e79 CHANGELOG
--- a/CHANGELOG Tue Oct 13 16:06:40 2026 +0200
+++ b/CHANGELOG Sat Oct 31 14:33:14 2026 +0100
@@ -1,3 +1,4 @@
+* Implement delete
 * Upgrade dependency to boto3
 
 Version 0.2.0 - 2026-03-21
diff -r 8e4bdd748cc6 -r 7047fb853e79 tryton_filestore_cellar.py
--- a/tryton_filestore_cellar.py        Tue Oct 13 16:06:40 2026 +0200
+++ b/tryton_filestore_cellar.py        Sat Oct 31 14:33:14 2026 +0100
@@ -53,7 +53,10 @@
         return response['ContentLength']
 
     def set(self, data, prefix=''):
-        id = uuid.uuid4().hex
+        if hasattr(FileStore, 'delete'):
+            id = str(uuid.uuid4())
+        else:
+            id = uuid.uuid4().hex
         self.s3.put_object(
             Bucket=self.bucket,
             Key=name(id, prefix),
@@ -61,6 +64,27 @@
             )
         return id
 
+    def delete(self, id, prefix=''):
+        # Older file ids didn't have a dash in the filename. We want to keep
+        # those as we don't know which resource might point to them.
+        if '-' not in id:
+            return
+        self.s3.delete_object(
+            Bucket=self.bucket,
+            Key=name(id, prefix),
+            )
+
+    def deletemany(self, ids, prefix=''):
+        keys = [{'Key': name(id, prefix)} for id in ids if '-' in id]
+        for start in range(0, len(keys), 1000):
+            self.s3.delete_objects(
+                Bucket=self.bucket,
+                Delete={
+                    'Objects': keys[start:start + 1000],
+                    },
+                )
+    delete_many = deletemany
+
 
 def name(id, prefix=''):
     return '/'.join(filter(None, [prefix, id]))

Reply via email to