perf: replace automatic backups with manual backup reminders
This commit is contained in:
1 parent
7527800128
commit
c85696080d
26 files changed
+385
-102
No files matched your search
@@ -128,7 +128,7 @@ def recover_from_backup(request, source, *, progress=None, verifier=None, idle_c
|
||||
installed = False
|
||||
record = {'operation': 'same_cbb_complete_project_restore', 'source': str(source),
|
||||
'library': str(library), 'block': request.block_name, 'installed': False,
|
||||
'validation_library': str(validation_dir/library.name)}
|
||||
'validation_library': str(validation_dir/library.name), 'backup_policy': 'manual'}
|
||||
def emit(stage, message, **details):
|
||||
if progress:
|
||||
progress({'stage': stage, 'block': request.block_name, 'message': message, **details})
|
||||
@@ -165,22 +165,17 @@ def recover_from_backup(request, source, *, progress=None, verifier=None, idle_c
|
||||
library_size = sum(info.st_size for info in _scan(library_root).values() if stat.S_ISREG(info.st_mode))
|
||||
source_size = sum(info.st_size for info in _scan(source.parent).values() if stat.S_ISREG(info.st_mode))
|
||||
same_drive = root.anchor.casefold() == validation_dir.anchor.casefold()
|
||||
required = library_size * (2 if same_drive else 1) + source_size * 3
|
||||
required = (library_size + source_size * 2) if same_drive else 0
|
||||
if (shutil.disk_usage(root).free < required
|
||||
or shutil.disk_usage(validation_base).free < library_size + source_size * 2):
|
||||
raise ValueError('磁盘空间不足:需要容纳中心库回退副本和验证副本。')
|
||||
or shutil.disk_usage(validation_base).free < library_size + source_size * 2
|
||||
or shutil.disk_usage(library_root).free < source_size):
|
||||
raise ValueError('磁盘空间不足:需要容纳隔离验证库和待安装工程。')
|
||||
(root/'recovery-request.json').write_text(json.dumps(record, ensure_ascii=False, indent=2), encoding='utf-8')
|
||||
emit('backup', '正在保留完整中心库副本…')
|
||||
emit('prepare_source', '正在准备隔离验证库;应用不自动创建回退备份…')
|
||||
library_scope = ManifestScope.library(request.block_name, library.name)
|
||||
original_manifest = _copy_verified(library_root, root/'library-before', scope=library_scope,
|
||||
progress=copy_progress('backup', '正在保留中心库副本:'))
|
||||
(root/'library-before-manifest.json').write_text(json.dumps(original_manifest, indent=2), encoding='utf-8')
|
||||
emit('prepare_source', '正在准备备份验证副本…')
|
||||
source_manifest = _copy_verified(source.parent, root/'source-before',
|
||||
progress=copy_progress('prepare_source', '正在保留备份工程副本:'))
|
||||
(root/'source-before-manifest.json').write_text(json.dumps(source_manifest, indent=2), encoding='utf-8')
|
||||
_copy_verified(root/'library-before', validation_dir, scope=library_scope,
|
||||
original_manifest = _copy_verified(library_root, validation_dir, scope=library_scope,
|
||||
progress=copy_progress('prepare_source', '正在准备验证库:'))
|
||||
(root/'library-baseline-manifest.json').write_text(json.dumps(original_manifest, indent=2), encoding='utf-8')
|
||||
staged_library = validation_dir/library.name
|
||||
staged_work = staged_library.parent/'ReusableBlocksLP'/request.block_name/'Work'
|
||||
# Both paths are newly created private copies; originals are retained.
|
||||
@@ -188,8 +183,9 @@ def recover_from_backup(request, source, *, progress=None, verifier=None, idle_c
|
||||
if not resolved_work.is_relative_to(validation_dir.resolve()):
|
||||
raise ValueError('验证副本工程路径越界。')
|
||||
shutil.rmtree(resolved_work)
|
||||
_copy_verified(root/'source-before', staged_work,
|
||||
source_manifest = _copy_verified(source.parent, staged_work,
|
||||
progress=copy_progress('prepare_source', '正在准备备份验证工程:'))
|
||||
(root/'source-manifest.json').write_text(json.dumps(source_manifest, indent=2), encoding='utf-8')
|
||||
staged_project = staged_work/source.name
|
||||
staged_pcb = staged_work/source_pcb.relative_to(source.parent)
|
||||
_align_library(staged_project, staged_pcb, staged_library)
|
||||
@@ -239,7 +235,7 @@ def recover_from_backup(request, source, *, progress=None, verifier=None, idle_c
|
||||
if final.status == 'PASS' and (final.library_flag != 'GREEN' or not final.safe_to_continue):
|
||||
final = replace(final, status='FAIL', stderr='目标工程恢复后的 Ready 状态未确认。')
|
||||
if final.status != 'PASS':
|
||||
final = replace(final, stderr=(final.stderr + '\n原工程和完整库副本已保留,请查看恢复记录。').strip())
|
||||
final = replace(final, stderr=(final.stderr + '\n原 Work 已改名保留;应用未创建完整库备份,请查看恢复记录并使用手动备份。').strip())
|
||||
return save(final)
|
||||
except Exception as error:
|
||||
return save(VerifyResult('FAIL' if installed else 'BLOCKED', stderr=str(error),
|
||||
|
||||
Reference in new issue
Block a user