fix: enforce native repair ownership and cancellation boundaries
This commit is contained in:
1 parent
2490067b2d
commit
9cd4968a97
8 files changed
+248
-10
No files matched your search
@@ -98,6 +98,9 @@ def backup_project(target, destination):
|
||||
if (before.st_size, before.st_mtime_ns) != (after.st_size, after.st_mtime_ns):
|
||||
raise OSError(f'REPAIR_BACKUP_CHANGED: 备份期间源文件变化:{path}')
|
||||
files[str(relative)] = {'size': before.st_size, 'sha256': digest}
|
||||
if {path.relative_to(source) for path in source.rglob('*')} != {
|
||||
path.relative_to(source) for path in paths}:
|
||||
raise OSError('REPAIR_BACKUP_CHANGED: 备份期间工程文件集合变化')
|
||||
record = {'complete': True, 'source': str(source), 'files': files}
|
||||
(destination/'backup-manifest.json').write_text(json.dumps(record, ensure_ascii=False, indent=2),
|
||||
encoding='utf-8')
|
||||
@@ -147,12 +150,13 @@ def run_native_repair(target, root, *, mentor_bin='', timeout_seconds=300, progr
|
||||
root.mkdir(parents=True, exist_ok=True)
|
||||
job_path = root/'repair-request.json'
|
||||
cancel = root/'cancel-repair.signal'
|
||||
desktop = 'CbbRepair_'+uuid4().hex[:12]
|
||||
job_path.write_text(json.dumps({'project': str(target.project), 'database': str(target.database),
|
||||
'root': str(root), 'mentor_bin': str(mentor_bin or ''), 'timeout': timeout_seconds,
|
||||
'cancel_signal': str(cancel), 'supervisor_pid': os.getpid()}, ensure_ascii=False), encoding='utf-8')
|
||||
'cancel_signal': str(cancel), 'supervisor_pid': os.getpid(), 'desktop': desktop},
|
||||
ensure_ascii=False), encoding='utf-8')
|
||||
command = ([sys.executable] if getattr(sys, 'frozen', False) else
|
||||
[sys.executable, '-m', 'cbb_refresh_verify']) + ['--repair-worker', str(job_path)]
|
||||
desktop = 'CbbRepair_'+uuid4().hex[:12]
|
||||
worker = DesktopWorker(command, desktop)
|
||||
worker.bind_cancellation(cancel)
|
||||
deadline = time.monotonic()+max(1, float(timeout_seconds))+5
|
||||
|
||||
Reference in new issue
Block a user