Title: vfs: align virtual file handles with open(2) by pipobscure · Pull Request #65854 · nodejs/node · GitHub
Open Graph Title: vfs: align virtual file handles with open(2) by pipobscure · Pull Request #65854 · nodejs/node
X Title: vfs: align virtual file handles with open(2) by pipobscure · Pull Request #65854 · nodejs/node
Description: vfs: align virtual file handles with open(2) A file descriptor obtained on a mounted path answers several node:fs calls differently from one on a real file, in both providers: writeFileSync(path, data, { flag: 'r+' }) replaces the whole file instead of overwriting bytes from offset 0 and keeping the tail. Numeric open flags are mapped by treating any write-ish bit as "w": O_WRONLY alone truncates, and O_RDONLY | O_CREAT opens the file write-only and truncates it. A handle opened with "a+" starts its read offset at the end of the file, so the first read returns nothing; O_APPEND only affects writes. The ZipProvider handle additionally: throws EISDIR instead of EBADF when reading a write-only handle or writing a read-only one; leaves stale bytes in place when ftruncate grows a file that was previously shrunk, where real files read back as zeros; rejects a BigInt position with a TypeError from mixing number and BigInt arithmetic. This adds a test that runs the same sequence of calls against a memory mount and a ZIP mount and expects the real-fs result, so every divergence shows up as its own failing case. Proposed solution: decode numeric flags bit by bit (O_TRUNC decides truncation, O_CREAT decides creation, O_WRONLY/O_RDWR decide access) instead of collapsing them to a flag string; keep the read offset at 0 for append handles and only force writes to the end; make the handle writeFile for non-truncating flags write at offset 0 without shrinking; in the ZIP handle use EBADF for access-mode violations, zero-fill on growth in #doTruncate, and coerce position with Number() as the memory handle does. Note: Since these are gaps/defects in existing functionality, I decided to create the failing tests first (first commit) and then add the fix/solution as a second commit. That way whoever wants to review this can first prove out the issue, before applying the solution. This goes with the VFS work by @mcollina and the bug-fix PRs by @trivikr.
Open Graph Description: vfs: align virtual file handles with open(2) A file descriptor obtained on a mounted path answers several node:fs calls differently from one on a real file, in both providers: writeFileSync(path, ...
X Description: vfs: align virtual file handles with open(2) A file descriptor obtained on a mounted path answers several node:fs calls differently from one on a real file, in both providers: writeFileSync(path, ...
Opengraph URL: https://github.com/nodejs/node/pull/65854
X: @github
Domain: github.com
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /:user_id/:repository/pull/:id/commits/:range(.:format) |
| route-controller | pull_requests |
| route-action | commits |
| fetch-nonce | v2:bc24b084-3d11-4399-2d33-35d5b8fdd63a |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A3D2:2AD630:32BB88:46185B:6AEDB4D9 |
| html-safe-nonce | e8b5452bec1fe67ceaf788bb2071e9663ee11388b26f1ea4083ffae9e9f507ed |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBM0QyOjJBRDYzMDozMkJCODg6NDYxODVCOjZBRURCNEQ5IiwidmlzaXRvcl9pZCI6IjQzNjA3OTUxODc3OTc5MzEyMjUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 00d0047cfe70e02e86be6514af8673601084d4624ab33f65f45081aea56a9f3a |
| hovercard-subject-tag | pull_request:4455882533 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/nodejs/node/pull/65854/commits/cb3e193bdb8a39cdc4585b70814a73ac6dc93043 |
| twitter:image | https://avatars.githubusercontent.com/u/446127?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/446127?s=400&v=4 |
| og:image:alt | vfs: align virtual file handles with open(2) A file descriptor obtained on a mounted path answers several node:fs calls differently from one on a real file, in both providers: writeFileSync(path, ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | e40242599af5e7da0f281843dec7492c322688d4a48caeea85f9fb8e41c8ea53 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 89cbf2bb52a24fc179bf5925abba0ba574b262ce |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width