From 16bf193b0ea065a0605aa5dcbe1baec4e092e826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 13 Sep 2017 11:05:35 +0200 Subject: [PATCH] Added soft-delete to the files schema. This allows us to soft-delete orphan files, at least until we know that the orphan file detection is solid and can really be trusted. --- pillar/api/eve_settings.py | 3 ++- pillar/cli/maintenance.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pillar/api/eve_settings.py b/pillar/api/eve_settings.py index a475856a..b7c54cf6 100644 --- a/pillar/api/eve_settings.py +++ b/pillar/api/eve_settings.py @@ -720,11 +720,12 @@ tokens = { } files = { + 'schema': files_schema, 'resource_methods': ['GET', 'POST'], 'item_methods': ['GET', 'PATCH'], 'public_methods': ['GET'], 'public_item_methods': ['GET'], - 'schema': files_schema + 'soft_delete': True, } groups = { diff --git a/pillar/cli/maintenance.py b/pillar/cli/maintenance.py index 32edec24..dc4671a5 100644 --- a/pillar/cli/maintenance.py +++ b/pillar/cli/maintenance.py @@ -544,7 +544,8 @@ def _find_orphan_files(project_id: bson.ObjectId) -> typing.Set[bson.ObjectId]: # Get all file IDs that belong to this project. files_coll = current_app.db('files') - cursor = files_coll.find({'project': project_id}, projection={'_id': 1}) + file_filter = {'project': project_id, '_deleted': {'$ne': True}} + cursor = files_coll.find(file_filter, projection={'_id': 1}) file_ids = {doc['_id'] for doc in cursor} if not file_ids: log.debug('Project %s has no files', project_id)