From 7ffd8370f494af078f21a22d1f6bb86de984f8be Mon Sep 17 00:00:00 2001 From: StyxX65 <150797939+StyxX65@users.noreply.github.com> Date: Thu, 28 May 2026 10:19:54 +0200 Subject: [PATCH] Fix Stop button not halting Google Workspace scan MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two bugs in the abort mechanism: 1. POST /api/scan/stop only set state._scan_abort (M365/file abort event) but never touched state._google_scan_abort. Now sets both. 2. _check_abort() inside _run_google_scan imported gdpr_scanner._scan_abort (= state._scan_abort, the M365 event) instead of using the module-level _scan_abort alias (= state._google_scan_abort). This meant the dedicated /api/google/scan/cancel endpoint — which correctly sets _google_scan_abort — was silently ignored by the scan loop. Fixed to use the module-level alias consistently. Also aligned the end-of-scan checkpoint-clear check. Co-Authored-By: Claude Sonnet 4.6 --- routes/google_scan.py | 11 +++++------ routes/scan.py | 1 + 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/routes/google_scan.py b/routes/google_scan.py index f9b051e..3293ee3 100644 --- a/routes/google_scan.py +++ b/routes/google_scan.py @@ -144,6 +144,7 @@ def _run_google_scan(options: dict): scan_emails = bool(scan_opts.get("scan_emails", False)) scan_phones = bool(scan_opts.get("scan_phones", False)) ocr_lang = str(scan_opts.get("ocr_lang", "dan+eng")) or "dan+eng" + cpr_only = bool(scan_opts.get("cpr_only", False)) from checkpoint import (_load_delta_tokens, _save_delta_tokens, _save_checkpoint, _load_checkpoint, _clear_checkpoint) @@ -224,8 +225,7 @@ def _run_google_scan(options: dict): t_start = _time.monotonic() def _check_abort(): - from gdpr_scanner import _scan_abort as _sa - if _sa.is_set(): + if _scan_abort.is_set(): broadcast("scan_cancelled", {"completed": total_scanned}) return True return False @@ -324,7 +324,7 @@ def _run_google_scan(options: dict): pii_counts = result.get("pii_counts") _em = list(dict.fromkeys(e["formatted"] for e in result.get("emails", []))) if scan_emails else [] _ph = list(dict.fromkeys(p["formatted"] for p in result.get("phones", []))) if scan_phones else [] - if cprs or (pii_counts and any(pii_counts.values())) or _em or _ph: + if cprs or (not cpr_only and ((pii_counts and any(pii_counts.values())) or _em or _ph)): meta["_email_count"] = len(_em) meta["_phone_count"] = len(_ph) _broadcast_card(meta, cprs, pii_counts) @@ -397,7 +397,7 @@ def _run_google_scan(options: dict): pii_counts = result.get("pii_counts") _em = list(dict.fromkeys(e["formatted"] for e in result.get("emails", []))) if scan_emails else [] _ph = list(dict.fromkeys(p["formatted"] for p in result.get("phones", []))) if scan_phones else [] - if cprs or (pii_counts and any(pii_counts.values())) or _em or _ph: + if cprs or (not cpr_only and ((pii_counts and any(pii_counts.values())) or _em or _ph)): meta["_email_count"] = len(_em) meta["_phone_count"] = len(_ph) _broadcast_card(meta, cprs, pii_counts) @@ -418,8 +418,7 @@ def _run_google_scan(options: dict): except Exception as e: logger.warning("[gdrive delta] token save failed: %s", e) - from gdpr_scanner import _scan_abort as _gsa - if not _gsa.is_set(): + if not _scan_abort.is_set(): _clear_checkpoint(prefix=_gck_prefix) elapsed = _time.monotonic() - t_start diff --git a/routes/scan.py b/routes/scan.py index a1660c1..e11c13d 100644 --- a/routes/scan.py +++ b/routes/scan.py @@ -114,6 +114,7 @@ def scan_start(): @bp.route("/api/scan/stop", methods=["POST"]) def scan_stop(): state._scan_abort.set() + state._google_scan_abort.set() return jsonify({"status": "stopping"})