comparison sat/memory/memory.py @ 3523:30779935c0aa

core (memory, sqlite): new `fileGetUsedSpace` method
author Goffi <goffi@goffi.org>
date Wed, 05 May 2021 15:37:21 +0200
parents a83a04b7394b
children f9a5b810f14d
comparison
equal deleted inserted replaced
3522:41a6c144dc90 3523:30779935c0aa
1454 def getFilesOwner( 1454 def getFilesOwner(
1455 self, 1455 self,
1456 client, 1456 client,
1457 owner: Optional[jid.JID], 1457 owner: Optional[jid.JID],
1458 peer_jid: Optional[jid.JID], 1458 peer_jid: Optional[jid.JID],
1459 file_id: Optional[str], 1459 file_id: Optional[str] = None,
1460 parent: Optional[str] 1460 parent: Optional[str] = None
1461 ) -> jid.JID: 1461 ) -> jid.JID:
1462 """Get owner to use for a file operation 1462 """Get owner to use for a file operation
1463 1463
1464 if owner is not explicitely set, a suitable one will be used (client.jid for 1464 if owner is not explicitely set, a suitable one will be used (client.jid for
1465 clients, peer_jid for components). 1465 clients, peer_jid for components).
1707 owner=owner, 1707 owner=owner,
1708 access=access, 1708 access=access,
1709 extra=extra, 1709 extra=extra,
1710 ) 1710 )
1711 1711
1712 async def fileGetUsedSpace(
1713 self,
1714 client,
1715 peer_jid: jid.JID,
1716 owner: Optional[jid.JID] = None
1717 ) -> int:
1718 """Get space taken by all files owned by an entity
1719
1720 @param peer_jid: entity requesting the size
1721 @param owner: entity owning the file to check. If None, will be determined by
1722 getFilesOwner
1723 @return: size of total space used by files of this owner
1724 """
1725 owner = self.getFilesOwner(client, owner, peer_jid)
1726 if peer_jid.userhostJID() != owner and client.profile not in self.admins:
1727 raise exceptions.PermissionError("You are not allowed to check this size")
1728 return await self.storage.fileGetUsedSpace(client, owner)
1729
1712 def fileUpdate(self, file_id, column, update_cb): 1730 def fileUpdate(self, file_id, column, update_cb):
1713 """Update a file column taking care of race condition 1731 """Update a file column taking care of race condition
1714 1732
1715 access is NOT checked in this method, it must be checked beforehand 1733 access is NOT checked in this method, it must be checked beforehand
1716 @param file_id(unicode): id of the file to update 1734 @param file_id(unicode): id of the file to update