Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix: make ledger sync portable on Windows

longmeidao42e7f33e9920
diff --git a/scripts/test.ps1 b/scripts/test.ps1
index 6bdd88087..b18c89971 100644
--- a/scripts/test.ps1
+++ b/scripts/test.ps1
@@ -22,8 +22,18 @@ if (-not (Test-Path -LiteralPath $Python -PathType Leaf)) {
$SourceRoot = (Resolve-Path -LiteralPath (Join-Path $WorktreeRoot 'src')).Path
$PreviousPythonPath = $env:PYTHONPATH
+$PreviousPath = $env:PATH
$env:PYTHONPATH = $SourceRoot
+# Git for Windows 自带项目证书测试所需的 OpenSSL,但默认不会把 usr\bin 放进
+# 用户 PATH。只对本次测试进程补齐,不修改系统或用户环境变量。
+if (-not (Get-Command openssl.exe -ErrorAction SilentlyContinue)) {
+ $GitOpenSslDir = 'C:\Program Files\Git\usr\bin'
+ if (Test-Path -LiteralPath (Join-Path $GitOpenSslDir 'openssl.exe') -PathType Leaf) {
+ $env:PATH = "$GitOpenSslDir;$env:PATH"
+ }
+}
+
Push-Location $WorktreeRoot
try {
$LoadedModule = (& $Python -c 'import peach; print(peach.__file__)').Trim()
@@ -46,4 +56,5 @@ try {
} else {
$env:PYTHONPATH = $PreviousPythonPath
}
+ $env:PATH = $PreviousPath
}
diff --git a/src/peach/sync.py b/src/peach/sync.py
index 1b3a695a6..4d860cd9b 100644
--- a/src/peach/sync.py
+++ b/src/peach/sync.py
@@ -180,7 +180,10 @@ def copy_database(source: Path, target: Path) -> None:
finally:
origin.close()
shutil.copyfile(snapshot, transfer)
- with transfer.open("rb") as handle:
+ # Windows 的 FlushFileBuffers 需要可写句柄;只读句柄上调用 fsync 会返回
+ # ``OSError: [Errno 9] Bad file descriptor``。这里同步的是刚写完、尚未发布
+ # 的临时快照,使用读写句柄不会改变内容。
+ with transfer.open("r+b") as handle:
os.fsync(handle.fileno())
# 旧副本的 sidecar 不能和新快照拼在一起。同步调用方保证目标没有服务在写。
for suffix in ("-wal", "-shm", "-journal"):
diff --git a/tests/test_tray.py b/tests/test_tray.py
index 02547137a..4e3a1d37c 100644
--- a/tests/test_tray.py
+++ b/tests/test_tray.py
@@ -186,7 +186,10 @@ class ServiceStatusTests(unittest.TestCase):
self.assertIn("两侧已经一致", message)
process.terminate.assert_called_once()
start.assert_called_once()
- self.assertEqual(manager._run.call_args.args[0][:2], ["/venv/peach", "ledger-sync"])
+ self.assertEqual(
+ manager._run.call_args.args[0][:2],
+ [str(Path("/venv/peach")), "ledger-sync"],
+ )
def test_manual_sync_refuses_a_healthy_unowned_service(self):
spec = ServiceSpec("http", "http://127.0.0.1/healthz", ("peach", "serve"), True)