feat: integrate native diagnostics and coordinated CBB transactions
This commit is contained in:
1 parent
9e230e1a46
commit
da67de026f
91 files changed
+14370
-435
No files matched your search
@@ -0,0 +1,61 @@
|
||||
"""Interpret the current Project Backup loading session, before any Repair."""
|
||||
import ntpath
|
||||
import re
|
||||
|
||||
|
||||
def _same(left, right):
|
||||
return ntpath.normcase(ntpath.normpath(str(left))) == ntpath.normcase(ntpath.normpath(str(right)))
|
||||
|
||||
|
||||
def classify_inspection(project, database, output):
|
||||
result = {'status': 'UNCONFIRMED', 'repair_required': False}
|
||||
if not isinstance(output, str):
|
||||
return result
|
||||
loaded = re.findall(r'Loading project file \[([^\]\r\n]+)\]\.', output)
|
||||
if len(loaded) != 1 or not _same(loaded[0], project):
|
||||
return result
|
||||
checking = 'Checking if project is in use.'
|
||||
if checking not in output:
|
||||
return result
|
||||
current = output.rsplit(checking, 1)[1]
|
||||
if re.search(r'\bProject is in use\b', current, re.I):
|
||||
return {**result, 'status': 'IN_USE'}
|
||||
if ("Project is not in use. Full iCDB Project Backup's functionality is available." not in current
|
||||
or 'Backup information loaded correctly.' not in current):
|
||||
return result
|
||||
# This exact native error was captured from the isolated EE7.9.5 project.
|
||||
# A generic 'try Repair' or an old error before the latest check is not proof.
|
||||
inconsistency_pattern = (
|
||||
r"Project database \[([^\]\r\n]+)\] is inconsistent\. It has been manually copied while the iCDB Server was running\. "
|
||||
r"Please use iCDB Project Backup 'Repair project' functionality to fix this issue\.")
|
||||
inconsistent = re.findall(inconsistency_pattern, current)
|
||||
from .icdb_recovery import _session_losses
|
||||
losses = list(_session_losses(current))
|
||||
if (len(inconsistent) > 1 or any(not _same(path, database) for path in inconsistent)
|
||||
or len(losses) > 1 or any(not lost.get('session') or lost.get('scope') != 'project'
|
||||
or not _same(lost.get('database_path', ''), database) for lost in losses)):
|
||||
return result
|
||||
required = bool(inconsistent or losses)
|
||||
remaining = re.sub(inconsistency_pattern, '', current)
|
||||
if required:
|
||||
remaining = remaining.replace('Please try to repair the project!', '')
|
||||
if re.search(r'\berror\b|try to repair|inconsistent|corrupt', remaining, re.I):
|
||||
return result
|
||||
return {'status': 'NOT_IN_USE', 'repair_required': bool(required)}
|
||||
|
||||
|
||||
def confirmed_inspection(target, record):
|
||||
"""Only an exact, exited, inspection-only native process grants a verdict."""
|
||||
if (not isinstance(record, dict) or record.get('inspection_only') is not True
|
||||
or record.get('repair_requested') is not False
|
||||
or type(record.get('native_pid')) is not int or record['native_pid'] <= 0
|
||||
or record.get('native_exit_code') != 0
|
||||
or record.get('release', {}).get('native_exited') is not True
|
||||
or not _same(record.get('project', ''), target.project)
|
||||
or not _same(record.get('database', ''), target.database)
|
||||
or record.get('unknown_dialogs')):
|
||||
return False
|
||||
expected = classify_inspection(target.project, target.database, record.get('output'))
|
||||
return (expected['status'] in ('NOT_IN_USE', 'IN_USE')
|
||||
and record.get('status') == expected['status']
|
||||
and record.get('repair_required') is expected['repair_required'])
|
||||
Reference in new issue
Block a user