Multiple open `Handle`s for the same file don't share metadata
Multiple open `Handle`s for the same file don't share metadata, meaning the inode can get out of sync.
Repro:
```ts
import * as fs from '@zenfs/core/promises'; // more readable
await fs.writeFile('example.txt', 'Hello World');
const a = fs.open('example.txt', 'r+');
const b = fs.open('example.txt', 'r+');
await a.truncate(5); // Contents are now "Hello"
const { size } = await b.stat();
assert.equal(size, 5); // fails because `b` doesn't have the updated metadata from `a`
```
The fix for this is to have `Handle`s share their `inode` via a semi-global cache, which can be keyed using the FS' `uuid` and the file's `ino`.
0 条评论