fix(windows): allow Java to read retained target snapshots (#1027)

This commit is contained in:
Ysopwnable
2026-10-08 04:33:01 +08:00
committed by GitHub
parent aafdf8a01b
commit 28d5c397c8
2 changed files with 50 additions and 5 deletions
+23
View File
@@ -300,6 +300,28 @@ try {
readbackRuntime.observation.path,
"snapshot.bin",
);
// Java RandomAccessFile uses read/write sharing without delete sharing.
// Exercise that independent Win32 reader contract without requiring Java.
const readerDigest = execFileSync(
"powershell.exe",
[
"-NoProfile",
"-NonInteractive",
"-Command",
"$ErrorActionPreference = 'Stop'; " +
"$stream = [IO.File]::Open($env:REA_SNAPSHOT_READER_PATH, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::ReadWrite); " +
"$hash = [Security.Cryptography.SHA256]::Create(); " +
"try { [BitConverter]::ToString($hash.ComputeHash($stream)).Replace('-', '').ToLowerInvariant() } " +
"finally { $hash.Dispose(); $stream.Dispose() }",
],
{
encoding: "utf8",
timeout: 15_000,
env: { ...process.env, REA_SNAPSHOT_READER_PATH: snapshotPath },
},
).trim();
assert.equal(readerDigest, readbackSnapshot.sha256);
await assert.rejects(writeFile(snapshotPath, "replace"));
await assert.rejects(rename(snapshotPath, `${snapshotPath}.renamed`));
await assert.rejects(rm(snapshotPath));
assert.equal(
@@ -310,6 +332,7 @@ try {
...report.controls,
completedRuntimeFileReadback: true,
completedRuntimeFileMutationDenied: true,
snapshotReadWriteSharingReader: true,
};
} finally {
await readbackRuntime.close();