diff options
Diffstat (limited to 'modules/core/core-bundle.js')
| -rw-r--r-- | modules/core/core-bundle.js | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/modules/core/core-bundle.js b/modules/core/core-bundle.js index c8a4c2e..f72a20e 100644 --- a/modules/core/core-bundle.js +++ b/modules/core/core-bundle.js @@ -548,8 +548,11 @@ class VirtualFileSystem { size: dir.content[name]._factory ? 0 : (dir.content[name].content ? dir.content[name].content.length : 0), _virtual: !!dir.content[name]._virtual })); - // Inject virtual /sys/ at root level - if ((!path || path === '/' || path === '') && !entries.some(e => e.name === 'sys' && e._virtual)) { + // Inject virtual /sys/ — but ONLY when the directory being listed IS the root. + // The old test was on the argument (`!path`), not on the result: `cd _agents; ls` + // printed a phantom `sys` inside _agents, and a follow-up list_files('_agents/sys') + // failed with 'Directory not found'. The listing lied; the resolver was right. + if (dir === this.root && !entries.some(e => e.name === 'sys' && e._virtual)) { entries.push({ name: 'sys', type: 'dir', size: 0, _virtual: true }); } return entries; @@ -765,8 +768,11 @@ class VirtualFileSystem { size: dir.content[name]._factory ? 0 : (dir.content[name].content ? dir.content[name].content.length : 0), _virtual: !!dir.content[name]._virtual })); - // Inject virtual /sys/ at root level - if ((!path || path === '/' || path === '') && !entries.some(e => e.name === 'sys' && e._virtual)) { + // Inject virtual /sys/ — but ONLY when the directory being listed IS the root. + // The old test was on the argument (`!path`), not on the result: `cd _agents; ls` + // printed a phantom `sys` inside _agents, and a follow-up list_files('_agents/sys') + // failed with 'Directory not found'. The listing lied; the resolver was right. + if (dir === this.root && !entries.some(e => e.name === 'sys' && e._virtual)) { entries.push({ name: 'sys', type: 'dir', size: 0, _virtual: true }); } return entries; @@ -804,9 +810,14 @@ class VirtualFileSystem { const isLast = i === entries.length - 1; const connector = isLast ? '└── ' : '├── '; result += prefix + connector + name + '\n'; - if (dir.content[name].type === 'dir' || dir.content[name]._virtual) { + // The loop pushes the virtual 'sys' name into `entries`, which has no node behind it: + // dereferencing dir.content['sys'].type threw 'Cannot read properties of undefined' + // and `tree` died on the root listing — often after printing a partial tree, which is + // where the disagreeing file counts came from. + const child = dir.content[name]; + if (child && child.type === 'dir') { const ext = isLast ? ' ' : '│ '; - result += this.tree(path + '/' + name, prefix + ext); + result += this.tree((path || '') + '/' + name, prefix + ext); } } return result; @@ -18814,6 +18825,11 @@ class WorldModelModule { const entries = fs.ls(path); if (!entries) return; for (const e of entries) { + // /sys is synthesized by ls() on demand and has no node behind it. Walking into it + // counted a synthetic subtree (114 dirs / 146 files in a store that holds 43 files), + // which is the "the counts disagree" report: two different populations were both + // printed as "files". + if (e._virtual) continue; if (e.type === 'file') fileCount++; else { dirCount++; walk(path === '/' ? '/' + e.name : path + '/' + e.name); } } |