diff src/memory/memory.py @ 2526:35d591086974

core (memory, sqlite): added fileUpdate method to update "extra" and "access" avoiding race condition
author Goffi <goffi@goffi.org>
date Fri, 16 Mar 2018 17:03:46 +0100
parents e4de2f16a284
children 8d82a62fa098
line wrap: on
line diff
--- a/src/memory/memory.py	Fri Mar 16 17:00:57 2018 +0100
+++ b/src/memory/memory.py	Fri Mar 16 17:03:46 2018 +0100
@@ -1302,6 +1302,18 @@
                                    owner=owner,
                                    access=access, extra=extra)
 
+    def fileUpdate(self, file_id, column, update_cb):
+        """update a file column taking care of race condition
+
+        access is NOT checked in this method, it must be checked beforehand
+        @param file_id(unicode): id of the file to update
+        @param column(unicode): one of "access" or "extra"
+        @param update_cb(callable): method to update the value of the colum
+            the method will take older value as argument, and must update it in place
+            Note that the callable must be thread-safe
+        """
+        return self.storage.fileUpdate(file_id, column, update_cb)
+
     ## Misc ##
 
     def isEntityAvailable(self, entity_jid, profile_key):