From 4223ac1e4f10268810e84242132e77b5aeac1cee Mon Sep 17 00:00:00 2001 From: Nikita Karetnikov Date: Thu, 14 Sep 2023 10:25:48 +0000 Subject: [PATCH] Update build metadata on deletion, fix misc bugs Fixes #560. --- conda-store-server/conda_store_server/worker/tasks.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/conda-store-server/conda_store_server/worker/tasks.py b/conda-store-server/conda_store_server/worker/tasks.py index 644174e41..a8aed6016 100644 --- a/conda-store-server/conda_store_server/worker/tasks.py +++ b/conda-store-server/conda_store_server/worker/tasks.py @@ -1,3 +1,4 @@ +import datetime import shutil import os @@ -231,7 +232,7 @@ def delete_build_artifact(db: Session, conda_store, build_artifact): # ignore key conda_prefix = build_artifact.build.build_path(conda_store) # be REALLY sure this is a directory within store directory - if conda_prefix.startswith(conda_store.store_directory) and os.path.isdir( + if str(conda_prefix).startswith(conda_store.store_directory) and os.path.isdir( conda_prefix ): shutil.rmtree(conda_prefix) @@ -254,6 +255,7 @@ def task_delete_build(self, build_id): build = api.get_build(db, build_id) + # Deletes build artifacts for this build conda_store.log.info(f"deleting artifacts for build={build.id}") for build_artifact in api.list_build_artifacts( db, @@ -261,7 +263,12 @@ def task_delete_build(self, build_id): excluded_artifact_types=settings.build_artifacts_kept_on_deletion, ).all(): delete_build_artifact(db, conda_store, build_artifact) - conda_store.db.commit() + + # Updates build size and marks build as deleted + build.deleted_on = datetime.datetime.utcnow() + build.size = 0 + + db.commit() @shared_task(base=WorkerTask, name="task_delete_environment", bind=True)