def sync(
self,
file_path: str | Path,
reader: Reader,
writer: Writer,
dry_run: bool = False,
) -> BidirectionalResult:
file_path = Path(file_path)
result = BidirectionalResult()
snapshot = self._collect(file_path, reader, result)
classified = self._classify(
snapshot.source,
snapshot.target,
snapshot.baseline_hashes,
snapshot.source_hashes,
snapshot.target_hashes,
)
check_deactivation_threshold(
self._deactivation_threshold,
len(snapshot.target),
len(classified.target_deactivations),
)
source_timestamp = self._get_file_timestamp(file_path)
target_timestamps = (
self._storage.get_timestamps(set(classified.conflict_keys))
if classified.conflict_keys
else {}
)
resolved = self._resolve_conflicts(
classified.conflict_keys,
snapshot.source, snapshot.target,
source_timestamp, target_timestamps, result,
)
self._apply_resolutions(
resolved, classified, snapshot.source, snapshot.target,
)
self._populate_result(result, classified, resolved)
if dry_run:
return result
self._commit(
snapshot, classified, resolved,
file_path, writer, result,
)
self._finalize(result)
return result