# HG changeset patch # User Thierry Florac # Date 1549381350 -3600 # Node ID d410e7e214735f41f2d988da814d11948e07a745 # Parent 7d176a46aa83b4456e8b8db60ba5daca111c412a Updated blobs removal script to remove all references on empty files diff -r 7d176a46aa83 -r d410e7e21473 src/pyams_file/script/__init__.py --- a/src/pyams_file/script/__init__.py Tue Feb 05 15:09:19 2019 +0100 +++ b/src/pyams_file/script/__init__.py Tue Feb 05 16:42:30 2019 +0100 @@ -12,17 +12,19 @@ __docformat__ = 'restructuredtext' - from ZODB.utils import oid_repr, p64 +from zope.lifecycleevent import ObjectRemovedEvent from pyams_file.interfaces import IBlobReferenceManager -from pyams_utils.registry import get_utility, set_local_registry +from pyams_utils.registry import get_global_registry, get_utility, set_local_registry def remove_unused_blobs(root): """Blobs removal scripts - This file is intended to be used from *pshell* after running an *mdtools.relstorage* command like this: + If you used previous versions of PyAMS_file package, files and blobs references where not handled + correctly and this file is intended to be used from *pshell* after running an *mdtools.relstorage* + command like this: /var/local/env/pyams$ ./bin/zodbsearch --config etc/zodb-relstorage.conf \ --data pyams_file.file.File pyams_file.file.ImageFile pyams_file.file.SVGImageFile \ @@ -39,6 +41,7 @@ the blob file will be physically removed after next database pack. """ + registry = get_global_registry() set_local_registry(root.getSiteManager()) references = get_utility(IBlobReferenceManager) @@ -56,5 +59,10 @@ if blob_oid not in references.refs: delattr(file, '_blob') file._blob = None + registry.notify(ObjectRemovedEvent(file)) file.__parent__ = None print("{!r}".format(file)) + else: + registry.notify(ObjectRemovedEvent(file)) + file.__parent__ = None + print("Empty file {!r}".format(file))