参考所有分组:替换陈旧OPFS参数备份

结论:按 LinuxCNC rs274ngc_pre.cc save_parameters() 先 unlink 旧 .bak 再 link 当前参数文件的语义,浏览器 OPFS 成功保存时总是用解析前主参数文件刷新 .bak;未扩展 smoke 解析行为。

验证:./test-native.sh;./test-linuxcnc-source-link.sh;./test-web-wasm-browser-smoke.sh。
This commit is contained in:
cnc
2026-06-03 11:11:40 +08:00
parent 1928ff3b6a
commit f98a715ed7
2 changed files with 7 additions and 8 deletions

View File

@@ -713,7 +713,7 @@ export async function createWasmSimulator(moduleOptions = {}) {
// through the WASM mirror, so preserve the loaded OPFS file here. // through the WASM mirror, so preserve the loaded OPFS file here.
if (previousParameterFile === null) { if (previousParameterFile === null) {
await opfs.removeFile(`${parameterPath}.bak`); await opfs.removeFile(`${parameterPath}.bak`);
} else if (!(await opfs.exists(`${parameterPath}.bak`))) { } else {
await opfs.writeFile(`${parameterPath}.bak`, previousParameterFile); await opfs.writeFile(`${parameterPath}.bak`, previousParameterFile);
} }
return events; return events;

View File

@@ -93,9 +93,10 @@ export async function runBrowserOpfsParameterSections(context, simulator) {
await runSection("opfs parameter backup after existing save", async () => { await runSection("opfs parameter backup after existing save", async () => {
await simulator.fs.opfs.writeFile("parameters/existing-save.var", "5161\t3.000000\n"); await simulator.fs.opfs.writeFile("parameters/existing-save.var", "5161\t3.000000\n");
// LinuxCNC source basis: rs274ngc_pre.cc save_parameters() await simulator.fs.opfs.writeFile("parameters/existing-save.var.bak", "stale previous backup\n");
// unlinks filename + ".bak", links the current parameter file to // LinuxCNC source basis: rs274ngc_pre.cc save_parameters() unlinks
// filename + ".bak", then renames filename + ".new" over filename. // filename + ".bak", links the current parameter file to it,
// then renames filename + ".new" over filename.
await simulator.parseWithParameterFile( await simulator.parseWithParameterFile(
"G21 G90\nG0 X4\nG28.1\nM30\n", "G21 G90\nG0 X4\nG28.1\nM30\n",
"parameters/existing-save.var", "parameters/existing-save.var",
@@ -103,11 +104,9 @@ export async function runBrowserOpfsParameterSections(context, simulator) {
backend, backend,
); );
const existingSaveParameterFile = await readOpfsText(simulator, "parameters/existing-save.var"); const existingSaveParameterFile = await readOpfsText(simulator, "parameters/existing-save.var");
expectIncludes(existingSaveParameterFile, "5161\t4.000000", expectIncludes(existingSaveParameterFile, "5161\t4.000000", "LinuxCNC existing OPFS parameter file was not replaced after save");
"LinuxCNC existing OPFS parameter file was not replaced after save");
const existingSaveParameterBackup = await readOpfsText(simulator, "parameters/existing-save.var.bak"); const existingSaveParameterBackup = await readOpfsText(simulator, "parameters/existing-save.var.bak");
expectIncludes(existingSaveParameterBackup, "5161\t3.000000", expectIncludes(existingSaveParameterBackup, "5161\t3.000000", "LinuxCNC existing OPFS parameter backup did not replace the stale backup with the previous file");
"LinuxCNC existing OPFS parameter backup did not preserve the previous file");
await expectMissingOpfsFile( await expectMissingOpfsFile(
() => simulator.fs.opfs.readFile("parameters/existing-save.var.new"), () => simulator.fs.opfs.readFile("parameters/existing-save.var.new"),
"LinuxCNC existing OPFS parameter temporary file remained after save", "LinuxCNC existing OPFS parameter temporary file remained after save",