Repository navigation
Conversation
…he caller The per-entry `fs.stat` had a catch that substituted `size: 0` and `mtime: new Date(0)`. `formatSize` renders 0 as "0 B", so an entry whose size could not be read came out identical to an empty file, and the fabricated 0 was added to the combined size the tool reports. A stat failure is not a measurement, so let it reject. `list_directory` and `directory_tree` already let their `readdir` reject, and `search_files` now does the same for its own recursion.
7 of 12 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
list_directory_with_sizesreported a size for entries it could not read. The per-entryfs.stathad acatchthat substitutedsize: 0andmtime: new Date(0), andformatSizerenders0as0 B— so an unreadable file and an empty one come out identical:Nothing marks the number as unknown, so the listing reads as a complete measurement.
Publishing Your Server
Not applicable — this modifies the existing
filesystemserver.Server Details
list_directory_with_sizes)Motivation and Context
size: 0is a real measurement for an empty file and a fabricated one for a file whose metadata could not be read. The two cases reach the same line, and because the fabricated0is summed intoCombined size, a directory containing unreadable entries reports a total that is too small rather than one that is incomplete.A failing
fs.statis not unusual: a file removed betweenreaddirandstatis enough, and a permission-restricted entry does it too.The fix is to let the error propagate, which is what
list_directoryanddirectory_treealready do with theirreaddir.How Has This Been Tested?
One case in
src/filesystem/__tests__/structured-content.test.tsusing a dangling symlink, soreaddirlists the entry andfs.statgenuinely fails on it. Onmainthe call succeeds —isErrorisundefinedand the entry is listed as0 B; on this branch it rejects withENOENT.vitest runin the package is 166 passed. The three failures inunicode-paths.test.tsare pre-existing on this machine: macOS resolvesos.tmpdir()through the/var→/private/varsymlink, and APFS treats the composed and decomposed spellings ofcaféas one name, so the test's secondmkdirgetsEEXIST. They fail the same way without this change.Breaking Changes
None to the tool's schema. A directory containing an entry whose metadata cannot be read now answers
isErrorwhere it previously answered a listing with a0 Bin it.Types of changes
Checklist
Additional context
One judgement call worth flagging: the alternative is to keep listing the entry and print its size as unknown rather than
0 B, which keeps a partial listing useful at the cost of an output format change. I went with propagating because it is what the two sibling tools in this server already do, and because a combined size that silently excludes entries is the more dangerous of the two wrong answers. Say the word if you would rather have the unknown-size form — it is a small change from here.Related, not overlapping: #4910 makes
search_filespropagate itsreaddirfailure for the same reason. These are separate tools with separate root causes, so I have kept them apart.