fix: preserve native reads and advancing metadata operations

This commit is contained in:
阿白叔 committed 2026-11-17 00:39:30 +08:00
1 parent 5b7e7bea2f
commit 07206ce0d1
5 files changed
+128 -8

No files matched your search

+7 -1
View File
@@ -12,6 +12,7 @@ import os
from pathlib import Path
import shutil
import stat
from .operation_queue import note_metadata_progress
MANIFEST_VERSION = 1
@@ -207,6 +208,7 @@ def scan_tree(root, *, scope=None, exclude=None, check=None):
if not (stat.S_ISDIR(metadata.st_mode) or stat.S_ISREG(metadata.st_mode)):
raise ValueError(f'不支持的特殊文件:{entry.path}')
entries[path] = metadata
note_metadata_progress()
if stat.S_ISDIR(metadata.st_mode):
folders.append(path)
return dict(sorted(entries.items()))
@@ -252,6 +254,7 @@ def build_manifest(root, *, scope=None, exclude=None, progress=None, hash_functi
_emit(progress, 'hash', 0, 0, total_files=len(selected))
with ThreadPoolExecutor(max_workers=8) as pool:
for count, (relative, item) in enumerate(pool.map(hashed, selected), 1):
note_metadata_progress()
files[relative] = item
hashed_bytes += item['size']
if count % 256 == 0 or count == len(selected):
@@ -285,6 +288,7 @@ def build_exclusive_library_manifest(root, *, scope, progress=None):
raise OSError(f'LIBRARY_DATABASE_IN_USE: 无法独占读取 {path}:{error}') from error
handles[path] = handle
stack.callback(handle.Close)
note_metadata_progress()
def digest(path):
if path not in handles:
@@ -388,6 +392,7 @@ def copy_verified(source, destination, *, scope=None, progress=None, hash_functi
with ThreadPoolExecutor(max_workers=8) as pool:
for count, (relative, digest, label) in enumerate(pool.map(copy_file, files), 1):
note_metadata_progress()
if label is not None:
size = entries[source/relative].st_size
record[relative] = {'size': size, 'sha256': digest, 'scope': label}
@@ -405,7 +410,8 @@ def copy_verified(source, destination, *, scope=None, progress=None, hash_functi
if hash_function(destination/relative) != item['sha256']:
raise OSError(f'复制内容校验失败:{path}')
with ThreadPoolExecutor(max_workers=8) as pool:
list(pool.map(validate_bytes, record))
for _ in pool.map(validate_bytes, record):
note_metadata_progress()
if _metadata_record(source, scan_tree(source)) != expected_metadata:
raise OSError(f'复制期间目录内容变化:{source}')
if _metadata_record(destination, scan_tree(destination)) != expected_metadata: