From 134b935fa4014a058230980550fd7747957701f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Sainl=C3=A9ger?= Date: Mon, 10 Aug 2026 17:07:08 +0200 Subject: [PATCH] [ADD] finalize_db: run ``_gc_file_store_unsafe`` after attachment cleanup Add ``lib/python/file_gc.py``, a minimal Odoo-shell script that calls ``ir.attachment._gc_file_store_unsafe()`` to remove filestore files no longer referenced by any ``ir_attachment`` record. Invoke it in ``finalize_db.sh`` after the SQL attachment purges so that the deleted CSS/JS asset bundles, resized partner thumbnails, and orphaned ``ir_attachment`` rows also have their backing files cleaned from disk. --- lib/python/file_gc.py | 1 + scripts/finalize_db.sh | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 lib/python/file_gc.py diff --git a/lib/python/file_gc.py b/lib/python/file_gc.py new file mode 100644 index 0000000..b2f7d31 --- /dev/null +++ b/lib/python/file_gc.py @@ -0,0 +1 @@ +env['ir.attachment']._gc_file_store_unsafe() diff --git a/scripts/finalize_db.sh b/scripts/finalize_db.sh index 0048081..cc44042 100755 --- a/scripts/finalize_db.sh +++ b/scripts/finalize_db.sh @@ -122,7 +122,15 @@ SET state = 'installed' WHERE state = 'to upgrade'; " "$DB_NAME" || true +# ──────────────────────────────────────────────────────────── +# Clean orphaned filestore files left behind by the attachment +# deletions above. ``_gc_file_store_unsafe`` scans the filestore +# and removes files that no longer have a matching +# ``ir_attachment`` record. +# ──────────────────────────────────────────────────────────── +echo "Cleaning orphaned filestore files..." SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +exec_python_script_in_odoo_shell "$ODOO_SERVICE" "$DB_NAME" "$SCRIPT_DIR/lib/python/file_gc.py" PYTHON_SCRIPT="${SCRIPT_DIR}/lib/python/fix_duplicated_views.py" echo "Remove duplicated views with script $PYTHON_SCRIPT ..."