参考所有分组,完成尽量多的内容。禁止顺手扩功能 smoke
结论:按 align-linuxcnc 约束收窄 OPFS removeFile 和 LinuxCNC 参数 .new/.bak 清理为文件专用语义,避免把同名目录递归删除。依据 ../linuxcnc/src/emc/rs274ngc/rs274ngc_pre.cc save_parameters() 的 fopen(filename.new)、unlink(filename.bak)、link、rename 行为。 验证:./test-native.sh 通过;./test-linuxcnc-source-link.sh 通过。
This commit is contained in:
@@ -318,6 +318,21 @@ function removeWasmPath(module, path, recursive) {
|
||||
}
|
||||
}
|
||||
|
||||
function removeWasmFilePath(module, path) {
|
||||
let mode;
|
||||
try {
|
||||
mode = module.FS.stat(path).mode;
|
||||
} catch (error) {
|
||||
if (error?.errno !== 44) {
|
||||
throw error;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (module.FS.isFile(mode)) {
|
||||
module.FS.unlink(path);
|
||||
}
|
||||
}
|
||||
|
||||
function wasmPathExists(module, path) {
|
||||
try {
|
||||
module.FS.stat(path);
|
||||
@@ -505,9 +520,12 @@ function installOpfsWorkspace(module, options) {
|
||||
throw new Error("LinuxCNC parameter file was not produced by the interpreter");
|
||||
}
|
||||
await writeOpfsFile(workspacePath, path, data);
|
||||
await removeOpfsEntry(workspacePath, `${path}.new`, false);
|
||||
removeWasmPath(module, `${LINUXCNC_DEFAULT_PARAMETER_FILE}.new`, false);
|
||||
removeWasmPath(module, `/${LINUXCNC_DEFAULT_PARAMETER_FILE}.new`, false);
|
||||
// LinuxCNC source basis: rs274ngc_pre.cc save_parameters()
|
||||
// creates filename + ".new" with fopen() and later renames that
|
||||
// file; OPFS cleanup must not remove a directory at that path.
|
||||
await removeOpfsFileEntry(workspacePath, `${path}.new`);
|
||||
removeWasmFilePath(module, `${LINUXCNC_DEFAULT_PARAMETER_FILE}.new`);
|
||||
removeWasmFilePath(module, `/${LINUXCNC_DEFAULT_PARAMETER_FILE}.new`);
|
||||
const backupPath = `${LINUXCNC_DEFAULT_PARAMETER_FILE}.bak`;
|
||||
const backupData = readFirstExistingWasmFile(module, [backupPath, `/${backupPath}`]);
|
||||
if (backupData !== null) {
|
||||
@@ -518,8 +536,11 @@ function installOpfsWorkspace(module, options) {
|
||||
return data;
|
||||
},
|
||||
async removeFile(path) {
|
||||
await removeOpfsEntry(workspacePath, path, false);
|
||||
removeWasmPath(module, this.resolvePath(path), false);
|
||||
// LinuxCNC source basis: rs274ngc_pre.cc save_parameters() uses
|
||||
// unlink() for backup files, so the browser bridge keeps file-only
|
||||
// removal separate from recursive directory cleanup.
|
||||
await removeOpfsFileEntry(workspacePath, path);
|
||||
removeWasmFilePath(module, this.resolvePath(path));
|
||||
},
|
||||
async removeDirectory(path) {
|
||||
await removeOpfsEntry(workspacePath, path, true);
|
||||
|
||||
Reference in New Issue
Block a user