按源保护 OPFS 参数备份失败边界
This commit is contained in:
@@ -529,7 +529,12 @@ function installOpfsWorkspace(module, options) {
|
|||||||
const backupPath = `${LINUXCNC_DEFAULT_PARAMETER_FILE}.bak`;
|
const backupPath = `${LINUXCNC_DEFAULT_PARAMETER_FILE}.bak`;
|
||||||
const backupData = readFirstExistingWasmFile(module, [backupPath, `/${backupPath}`]);
|
const backupData = readFirstExistingWasmFile(module, [backupPath, `/${backupPath}`]);
|
||||||
if (backupData !== null) {
|
if (backupData !== null) {
|
||||||
await writeOpfsFile(workspacePath, `${path}.bak`, backupData);
|
try {
|
||||||
|
await writeOpfsFile(workspacePath, `${path}.bak`, backupData);
|
||||||
|
} catch (_backupError) {
|
||||||
|
// LinuxCNC reports link(filename, filename + ".bak") failures
|
||||||
|
// with perror() and still renames filename + ".new" over filename.
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
await removeOpfsFileEntry(workspacePath, `${path}.bak`);
|
await removeOpfsFileEntry(workspacePath, `${path}.bak`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
export async function runBrowserOpfsMirrorSections(context, simulator) {
|
export async function runBrowserOpfsMirrorSections(context, simulator) {
|
||||||
const {
|
const {
|
||||||
expectEvent,
|
expectEvent,
|
||||||
|
expectIncludes,
|
||||||
|
expectOpfsDirectoryStat,
|
||||||
expectMissingWasmPath,
|
expectMissingWasmPath,
|
||||||
expectText,
|
expectText,
|
||||||
|
expectWasmFilesMissing,
|
||||||
near,
|
near,
|
||||||
|
readOpfsText,
|
||||||
runSection,
|
runSection,
|
||||||
withSmokeSimulator,
|
withSmokeSimulator,
|
||||||
} = context;
|
} = context;
|
||||||
@@ -123,4 +127,27 @@ export async function runBrowserOpfsMirrorSections(context, simulator) {
|
|||||||
const truncatedWasmProgram = new TextDecoder().decode(simulator.fs.module.FS.readFile(truncatedWasmPath));
|
const truncatedWasmProgram = new TextDecoder().decode(simulator.fs.module.FS.readFile(truncatedWasmPath));
|
||||||
expectText(truncatedWasmProgram, "G21\n", "OPFS writeFile did not truncate the WASM mirror");
|
expectText(truncatedWasmProgram, "G21\n", "OPFS writeFile did not truncate the WASM mirror");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await runSection("opfs parameter backup bridge failure is non-fatal", async () => {
|
||||||
|
// LinuxCNC source basis: rs274ngc_pre.cc save_parameters()
|
||||||
|
// reports link(filename, filename + ".bak") failure with perror()
|
||||||
|
// but still renames filename + ".new" over the parameter file.
|
||||||
|
simulator.fs.module.FS.writeFile("rs274ngc.var", "5161\t12.000000\n");
|
||||||
|
simulator.fs.module.FS.writeFile("rs274ngc.var.bak", "5161\t11.000000\n");
|
||||||
|
const backupBridgeDirectory = simulator.fs.opfs.resolvePath("parameters/backup-bridge-directory.var.bak");
|
||||||
|
simulator.fs.module.FS.mkdir(backupBridgeDirectory);
|
||||||
|
await simulator.fs.opfs.persistDirectory("parameters/backup-bridge-directory.var.bak");
|
||||||
|
await simulator.fs.opfs.persistParameterFile("parameters/backup-bridge-directory.var");
|
||||||
|
expectIncludes(
|
||||||
|
await readOpfsText(simulator, "parameters/backup-bridge-directory.var"),
|
||||||
|
"5161\t12.000000",
|
||||||
|
"LinuxCNC parameter bridge did not persist the main file when backup link failed",
|
||||||
|
);
|
||||||
|
await expectOpfsDirectoryStat(
|
||||||
|
simulator,
|
||||||
|
"parameters/backup-bridge-directory.var.bak",
|
||||||
|
"LinuxCNC parameter backup bridge removed an existing OPFS backup directory",
|
||||||
|
);
|
||||||
|
expectWasmFilesMissing(simulator.fs.module.FS, ["rs274ngc.var", "rs274ngc.var.new", "rs274ngc.var.bak"], (parameterPath) => `LinuxCNC parameter scratch file remained outside OPFS after non-fatal backup bridge failure: ${parameterPath}`);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user