diff options
| author | Agando <roduccomm@gmail.com> | 2026-10-27 12:32:37 +0100 |
|---|---|---|
| committer | Agando <roduccomm@gmail.com> | 2026-10-27 12:32:37 +0100 |
| commit | 9a61780447066919964b66cdbaa35b9165629419 (patch) | |
| tree | a96a40371314705317e8cc8473c8d32690ff1b39 /modules/core/virtual-fs.js | |
| parent | 97279c0eb918701ac915187f5deb9f0adf9236bd (diff) | |
fix(newos4): never overwrite a directory node; ls honours a path after its flags
MAINT-010 and MAINT-016, the two high items the review left open. Both were re-probed
before the change and the new test is red on HEAD (5 passed, 7 FAILED).
- virtual-fs.js rename()/copy(): they assigned dst.dir.content[dst.name] with no destination
type check, so `mv file /docs` replaced the /docs node and every child vanished while the
command printed "Moved: …". Refuse when the destination is a real directory node (the
virtual /sys entry is exempt). rename() also erased the file on `mv a a`, because assigning
and then deleting the same key removes it; that path is now an explicit no-op.
- module-fs.js mv/cp: a refusal used to surface as "No such file or directory", which sent
the operator looking for a missing source. The destination is now inspected first and the
message says "is a directory — refusing to overwrite it".
- module-fs.js ls: the path was only read from argv[0], so `ls -l /work` listed the cwd.
The first non-flag argument is now the target; the path-first form is unchanged.
Tests: modules/test/test-fs-mv-cp-guard.js (12 asserts) — RED on HEAD (A1-A3, B1, B2, C2, E1),
GREEN now; maintain --fix reports "node tests 7/7 pass". Browser on v4.6.104:
"mv: /vtest: is a directory — refusing to overwrite it", child and source intact,
"ls -l /vtest" lists /vtest (keep.txt), not the cwd.
Diffstat (limited to 'modules/core/virtual-fs.js')
| -rw-r--r-- | modules/core/virtual-fs.js | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/modules/core/virtual-fs.js b/modules/core/virtual-fs.js index 3ed1b40..3a3e119 100644 --- a/modules/core/virtual-fs.js +++ b/modules/core/virtual-fs.js @@ -686,6 +686,11 @@ class VirtualFileSystem { if (!dst || !dst.name) return false; const node = src.dir.content[src.name]; if (!node) return false; + // mv a a is a no-op, not a delete (assign-then-delete on the same key used to erase it) + if (src.dir === dst.dir && src.name === dst.name) return true; + const existing = dst.dir.content[dst.name]; + // Never clobber a directory node: its children would vanish with it (MAINT-010). + if (existing && existing.type === 'dir' && !existing._virtual) return false; dst.dir.content[dst.name] = node; delete src.dir.content[src.name]; this.saveToStorage(); @@ -701,6 +706,9 @@ class VirtualFileSystem { if (!dst || !dst.name) return false; const node = src.dir.content[src.name]; if (!node) return false; + const existing = dst.dir.content[dst.name]; + // Never clobber a directory node: its children would vanish with it (MAINT-010). + if (existing && existing.type === 'dir' && !existing._virtual) return false; dst.dir.content[dst.name] = JSON.parse(JSON.stringify(node)); this.saveToStorage(); this._emitChange(dstPath); |