mirror of
https://github.com/YuJunZhiXue/dsh-purge.git
synced 2026-11-28 11:30:22 +08:00
- 门禁收敛:仅拦截中国大陆、香港、澳门,银行与金融站点,政府与军事站点 - #220 dshTarget 适配 0.2.1-rc.5 - #213 POSIX 原子写保留文件权限位 - #211 回退按钮遮挡与层级 - #209 pnpm 12 允许构建配置键名 - 提示词只由本地 lib/default-prompt-inject.md 嵌入,移除 zh/en 变体并加入忽略 - README 中英日同步,边界说明统一为禁止项
This commit is contained in:
1 parent
aa80d2e809
commit
2d428b11ff
12 files changed
+345
-312
No files matched your search
+18
-2
@@ -171,13 +171,29 @@ function ioFor(explicit, targetPath) {
|
||||
}
|
||||
|
||||
/** 宿主 lib 里的文件(bin.js / sidecar)一律先写临时文件再 rename:
|
||||
* 直接覆盖时被占用/断电会留下半截模块,宿主下次启动直接 import 失败。 */
|
||||
* 直接覆盖时被占用/断电会留下半截模块,宿主下次启动直接 import 失败。
|
||||
* #213:rename 会连临时文件的权限一起换上。POSIX 下 bin.js 丢了 +x,
|
||||
* `bin/dsh` 这个软链就再也执行不了,宿主起不来——写之前先把目标原有 mode 找回来。 */
|
||||
export function writeHostFileAtomic(nodeFs, fp, text) {
|
||||
let mode = null;
|
||||
try {
|
||||
if (typeof nodeFs.statSync === "function") {
|
||||
const st = nodeFs.statSync(fp);
|
||||
if (st && typeof st.mode === "number") mode = st.mode & 0o777;
|
||||
}
|
||||
} catch { /* 目标不存在或抽象 fs 不提供 statSync:按默认权限新建 */ }
|
||||
const tmp = `${fp}.${process.pid}.tmp`;
|
||||
nodeFs.writeFileSync(tmp, text, "utf8");
|
||||
try {
|
||||
if (mode != null && typeof nodeFs.chmodSync === "function") {
|
||||
try { nodeFs.chmodSync(tmp, mode); } catch { /* chmod 不支持时保持新文件默认权限 */ }
|
||||
}
|
||||
if (typeof nodeFs.renameSync === "function") nodeFs.renameSync(tmp, fp);
|
||||
else nodeFs.writeFileSync(fp, text, "utf8");
|
||||
else {
|
||||
// 原地写会保留现有权限;临时文件不能留在宿主 lib 目录里
|
||||
nodeFs.writeFileSync(fp, text, "utf8");
|
||||
try { nodeFs.unlinkSync(tmp); } catch { /* ignore */ }
|
||||
}
|
||||
} catch (error) {
|
||||
try { nodeFs.unlinkSync(tmp); } catch { /* ignore */ }
|
||||
throw error;
|
||||
|
||||
Reference in new issue
Block a user