Fix Stop button not halting Google Workspace scan

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 <noreply@anthropic.com>
This commit is contained in:
StyxX65 2026-05-28 10:19:54 +02:00
parent 2c5f5d3283
commit 7ffd8370f4
2 changed files with 6 additions and 6 deletions

View File

@ -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

View File

@ -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"})