feat: add guarded native CBB management and recovery coordination
This commit is contained in:
1 parent
3415e010ff
commit
797a79c30e
17 files changed
+2423
-15
No files matched your search
@@ -131,6 +131,11 @@ def hash_file(path):
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
def _coordination_checkpoint(path):
|
||||
from .library_lock import checkpoint_record
|
||||
return checkpoint_record(path) is not None
|
||||
|
||||
|
||||
def scan_tree(root, *, scope=None, exclude=None):
|
||||
"""Refuse links/special files; optionally prune trees outside semantic scope.
|
||||
|
||||
@@ -153,7 +158,7 @@ def scan_tree(root, *, scope=None, exclude=None):
|
||||
if entry.is_dir(follow_symlinks=False):
|
||||
if not scope.includes_directory(relative):
|
||||
continue
|
||||
elif scope.classify(relative) is None:
|
||||
elif scope.classify(relative) is None or _coordination_checkpoint(path):
|
||||
continue
|
||||
metadata = entry.stat(follow_symlinks=False)
|
||||
if metadata.st_file_attributes & stat.FILE_ATTRIBUTE_REPARSE_POINT:
|
||||
@@ -241,6 +246,11 @@ def copy_verified(source, destination, *, scope=None, progress=None, hash_functi
|
||||
expected_metadata = _metadata_record(source, entries)
|
||||
destination.mkdir(parents=True, exist_ok=False)
|
||||
files = [path for path, info in entries.items() if stat.S_ISREG(info.st_mode)]
|
||||
from .library_lock import owned_snapshot
|
||||
# Resolve ownership on the operation thread, before parallel copy workers.
|
||||
owned = {path: data for path in files
|
||||
if path.name.endswith('.cbb-upload.lock')
|
||||
and (data := owned_snapshot(path)) is not None}
|
||||
record = {}
|
||||
hashed_count = hashed_bytes = 0
|
||||
_emit(progress, 'copy', 0, 0, copied_files=0, total_files=len(files))
|
||||
@@ -260,9 +270,14 @@ def copy_verified(source, destination, *, scope=None, progress=None, hash_functi
|
||||
relative = path.relative_to(source)
|
||||
copied = destination/relative
|
||||
copied.parent.mkdir(parents=True, exist_ok=True)
|
||||
label = scope.classify(relative)
|
||||
label = None if _coordination_checkpoint(path) else scope.classify(relative)
|
||||
digest = None
|
||||
if path in locks:
|
||||
if path in owned:
|
||||
copied.write_bytes(owned[path])
|
||||
shutil.copystat(path, copied)
|
||||
if label is not None:
|
||||
digest = hashlib.sha256(owned[path]).hexdigest()
|
||||
elif path in locks:
|
||||
stream_hash = hashlib.sha256() if label is not None else None
|
||||
with copied.open('wb') as stream:
|
||||
while True:
|
||||
|
||||
Reference in new issue
Block a user