参考所有分组:替换陈旧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.
if (previousParameterFile === null) {
await opfs.removeFile(`${parameterPath}.bak`);
} else if (!(await opfs.exists(`${parameterPath}.bak`))) {
} else {
await opfs.writeFile(`${parameterPath}.bak`, previousParameterFile);
}
return events;

View File

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