@zenfs/core 2.0.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/dist/backends/backend.js +6 -5
  2. package/dist/backends/cow.d.ts +2 -2
  3. package/dist/backends/cow.js +39 -58
  4. package/dist/backends/fetch.js +27 -29
  5. package/dist/backends/passthrough.d.ts +2 -3
  6. package/dist/backends/passthrough.js +84 -199
  7. package/dist/backends/port.d.ts +16 -3
  8. package/dist/backends/port.js +61 -30
  9. package/dist/backends/single_buffer.d.ts +52 -46
  10. package/dist/backends/single_buffer.js +462 -219
  11. package/dist/backends/store/fs.d.ts +16 -10
  12. package/dist/backends/store/fs.js +227 -242
  13. package/dist/backends/store/store.d.ts +3 -3
  14. package/dist/backends/store/store.js +11 -10
  15. package/dist/config.d.ts +2 -2
  16. package/dist/config.js +10 -11
  17. package/dist/internal/devices.d.ts +2 -2
  18. package/dist/internal/devices.js +39 -49
  19. package/dist/internal/error.d.ts +9 -204
  20. package/dist/internal/error.js +19 -288
  21. package/dist/internal/file_index.d.ts +1 -1
  22. package/dist/internal/file_index.js +9 -9
  23. package/dist/internal/filesystem.d.ts +23 -8
  24. package/dist/internal/index.d.ts +1 -1
  25. package/dist/internal/index.js +1 -1
  26. package/dist/internal/index_fs.d.ts +2 -2
  27. package/dist/internal/index_fs.js +19 -19
  28. package/dist/internal/inode.d.ts +81 -103
  29. package/dist/internal/inode.js +336 -195
  30. package/dist/mixins/async.js +32 -28
  31. package/dist/mixins/mutexed.d.ts +4 -4
  32. package/dist/mixins/mutexed.js +39 -39
  33. package/dist/mixins/readonly.d.ts +2 -2
  34. package/dist/mixins/readonly.js +20 -20
  35. package/dist/mixins/sync.js +2 -2
  36. package/dist/polyfills.js +1 -1
  37. package/dist/readline.js +1 -1
  38. package/dist/utils.d.ts +8 -5
  39. package/dist/utils.js +14 -17
  40. package/dist/vfs/acl.d.ts +8 -8
  41. package/dist/vfs/acl.js +66 -47
  42. package/dist/vfs/async.d.ts +2 -2
  43. package/dist/vfs/async.js +6 -8
  44. package/dist/vfs/dir.d.ts +1 -1
  45. package/dist/vfs/dir.js +3 -4
  46. package/dist/vfs/file.js +33 -24
  47. package/dist/vfs/flags.js +3 -3
  48. package/dist/vfs/ioctl.d.ts +8 -7
  49. package/dist/vfs/ioctl.js +132 -27
  50. package/dist/vfs/promises.d.ts +3 -3
  51. package/dist/vfs/promises.js +200 -235
  52. package/dist/vfs/shared.d.ts +1 -12
  53. package/dist/vfs/shared.js +7 -35
  54. package/dist/vfs/streams.js +9 -9
  55. package/dist/vfs/sync.d.ts +1 -2
  56. package/dist/vfs/sync.js +158 -170
  57. package/dist/vfs/watchers.js +8 -8
  58. package/dist/vfs/xattr.js +89 -106
  59. package/package.json +5 -3
  60. package/scripts/test.js +2 -2
  61. package/tests/assignment.ts +1 -1
  62. package/tests/backend/port.test.ts +4 -4
  63. package/tests/backend/single-buffer.test.ts +39 -10
  64. package/tests/backend/single-buffer.worker.js +30 -0
  65. package/tests/common/context.test.ts +2 -2
  66. package/tests/common/mutex.test.ts +9 -9
  67. package/tests/fetch/fetch.ts +1 -1
  68. package/tests/fetch/run.sh +1 -1
  69. package/tests/fs/append.test.ts +4 -4
  70. package/tests/fs/directory.test.ts +25 -25
  71. package/tests/fs/errors.test.ts +15 -19
  72. package/tests/fs/links.test.ts +3 -2
  73. package/tests/fs/open.test.ts +4 -21
  74. package/tests/fs/permissions.test.ts +8 -13
  75. package/tests/fs/read.test.ts +10 -9
  76. package/tests/fs/readFile.test.ts +8 -24
  77. package/tests/fs/rename.test.ts +4 -9
  78. package/tests/fs/stat.test.ts +2 -2
  79. package/tests/fs/times.test.ts +6 -6
  80. package/tests/fs/truncate.test.ts +8 -36
  81. package/tests/fs/watch.test.ts +10 -10
  82. package/tests/fs/write.test.ts +77 -13
  83. package/tests/fs/xattr.test.ts +7 -7
  84. package/tests/logs.js +2 -2
  85. package/tests/setup/port.ts +6 -0
  86. package/dist/internal/log.d.ts +0 -139
  87. package/dist/internal/log.js +0 -219
  88. package/tests/fs/writeFile.test.ts +0 -70
@@ -50,13 +50,14 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
50
50
  var e = new Error(message);
51
51
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
52
52
  });
53
- import { _throw, canary, encodeUTF8, serialize, sizeof } from 'utilium';
53
+ import { withErrno } from 'kerium';
54
+ import { crit, debug, err, notice, warn } from 'kerium/log';
55
+ import { sizeof } from 'memium';
56
+ import { _throw, canary, encodeUTF8 } from 'utilium';
54
57
  import { extendBuffer } from 'utilium/buffer.js';
55
- import { Errno, ErrnoError } from '../../internal/error.js';
56
58
  import { Index } from '../../internal/file_index.js';
57
59
  import { FileSystem } from '../../internal/filesystem.js';
58
60
  import { Inode, isDirectory, rootIno } from '../../internal/inode.js';
59
- import { crit, debug, err, notice, warn } from '../../internal/log.js';
60
61
  import { basename, dirname, join, parse, relative } from '../../path.js';
61
62
  import { decodeDirListing, encodeDirListing } from '../../utils.js';
62
63
  import { S_IFDIR, S_IFREG, size_max } from '../../vfs/constants.js';
@@ -145,8 +146,9 @@ export class StoreFS extends FileSystem {
145
146
  */
146
147
  this._paths = new Map([[0, new Set('/')]]);
147
148
  this._initialized = false;
148
- store._fs = this;
149
+ store.fs = this;
149
150
  this._uuid = (_b = store.uuid) !== null && _b !== void 0 ? _b : this.uuid;
151
+ this.label = store.label;
150
152
  debug(this.name + ': supports features: ' + ((_c = this.store.flags) === null || _c === void 0 ? void 0 : _c.join(', ')));
151
153
  }
152
154
  /**
@@ -170,7 +172,7 @@ export class StoreFS extends FileSystem {
170
172
  const dirs = index.directories();
171
173
  for (const [path, inode] of index) {
172
174
  this._add(inode.ino, path);
173
- await tx.set(inode.ino, serialize(inode));
175
+ await tx.set(inode.ino, inode);
174
176
  if (dirs.has(path))
175
177
  await tx.set(inode.data, encodeDirListing(dirs.get(path)));
176
178
  }
@@ -197,7 +199,7 @@ export class StoreFS extends FileSystem {
197
199
  const dirs = index.directories();
198
200
  for (const [path, inode] of index) {
199
201
  this._add(inode.ino, path);
200
- tx.setSync(inode.ino, serialize(inode));
202
+ tx.setSync(inode.ino, inode);
201
203
  if (dirs.has(path))
202
204
  tx.setSync(inode.data, encodeDirListing(dirs.get(path)));
203
205
  }
@@ -218,13 +220,13 @@ export class StoreFS extends FileSystem {
218
220
  const index = new Index();
219
221
  const tx = __addDisposableResource(env_3, this.transaction(), true);
220
222
  const queue = [['/', 0]];
221
- const silence = canary(ErrnoError.With('EDEADLK'));
223
+ const silence = canary(withErrno('EDEADLK'));
222
224
  while (queue.length) {
223
225
  const [path, ino] = queue.shift();
224
226
  const inode = new Inode(await tx.get(ino));
225
227
  index.set(path, inode);
226
228
  if (inode.mode & S_IFDIR) {
227
- const dir = decodeDirListing((_a = (await tx.get(inode.data))) !== null && _a !== void 0 ? _a : _throw(ErrnoError.With('ENODATA', path)));
229
+ const dir = decodeDirListing((_a = (await tx.get(inode.data))) !== null && _a !== void 0 ? _a : _throw(withErrno('ENODATA')));
228
230
  for (const [name, id] of Object.entries(dir)) {
229
231
  queue.push([join(path, name), id]);
230
232
  }
@@ -250,13 +252,13 @@ export class StoreFS extends FileSystem {
250
252
  const index = new Index();
251
253
  const tx = __addDisposableResource(env_4, this.transaction(), false);
252
254
  const queue = [['/', 0]];
253
- const silence = canary(ErrnoError.With('EDEADLK'));
255
+ const silence = canary(withErrno('EDEADLK'));
254
256
  while (queue.length) {
255
257
  const [path, ino] = queue.shift();
256
258
  const inode = new Inode(tx.getSync(ino));
257
259
  index.set(path, inode);
258
260
  if (inode.mode & S_IFDIR) {
259
- const dir = decodeDirListing((_a = tx.getSync(inode.data)) !== null && _a !== void 0 ? _a : _throw(ErrnoError.With('ENODATA', path)));
261
+ const dir = decodeDirListing((_a = tx.getSync(inode.data)) !== null && _a !== void 0 ? _a : _throw(withErrno('ENODATA')));
260
262
  for (const [name, id] of Object.entries(dir)) {
261
263
  queue.push([join(path, name), id]);
262
264
  }
@@ -283,9 +285,9 @@ export class StoreFS extends FileSystem {
283
285
  const tx = __addDisposableResource(env_5, this.transaction(), true);
284
286
  const _old = parse(oldPath), _new = parse(newPath),
285
287
  // Remove oldPath from parent's directory listing.
286
- oldDirNode = await this.findInode(tx, _old.dir, 'rename'), oldDirList = decodeDirListing((_a = (await tx.get(oldDirNode.data))) !== null && _a !== void 0 ? _a : _throw(ErrnoError.With('ENODATA', _old.dir, 'rename')));
288
+ oldDirNode = await this.findInode(tx, _old.dir), oldDirList = decodeDirListing((_a = (await tx.get(oldDirNode.data))) !== null && _a !== void 0 ? _a : _throw(withErrno('ENODATA')));
287
289
  if (!oldDirList[_old.base])
288
- throw ErrnoError.With('ENOENT', oldPath, 'rename');
290
+ throw withErrno('ENOENT');
289
291
  const ino = oldDirList[_old.base];
290
292
  if (ino != this._ids.get(oldPath))
291
293
  err(`Ino mismatch while renaming ${oldPath} to ${newPath}`);
@@ -296,19 +298,17 @@ export class StoreFS extends FileSystem {
296
298
  We append '/' to avoid matching folders that are a substring of the bottom-most folder in the path.
297
299
  */
298
300
  if ((_new.dir + '/').startsWith(oldPath + '/'))
299
- throw new ErrnoError(Errno.EBUSY, _old.dir);
300
- // Add newPath to parent's directory listing.
301
+ throw withErrno('EBUSY');
301
302
  const sameParent = _new.dir == _old.dir;
302
303
  // Prevent us from re-grabbing the same directory listing, which still contains `old_path.base.`
303
- const newDirNode = sameParent ? oldDirNode : await this.findInode(tx, _new.dir, 'rename');
304
+ const newDirNode = sameParent ? oldDirNode : await this.findInode(tx, _new.dir);
304
305
  const newDirList = sameParent
305
306
  ? oldDirList
306
- : decodeDirListing((_b = (await tx.get(newDirNode.data))) !== null && _b !== void 0 ? _b : _throw(ErrnoError.With('ENODATA', _new.dir, 'rename')));
307
+ : decodeDirListing((_b = (await tx.get(newDirNode.data))) !== null && _b !== void 0 ? _b : _throw(withErrno('ENODATA')));
307
308
  if (newDirList[_new.base]) {
308
- // If it's a file, delete it, if it's a directory, throw a permissions error.
309
- const existing = new Inode((_c = (await tx.get(newDirList[_new.base]))) !== null && _c !== void 0 ? _c : _throw(ErrnoError.With('ENOENT', newPath, 'rename')));
309
+ const existing = new Inode((_c = (await tx.get(newDirList[_new.base]))) !== null && _c !== void 0 ? _c : _throw(withErrno('ENOENT')));
310
310
  if (!existing.toStats().isFile())
311
- throw ErrnoError.With('EPERM', newPath, 'rename');
311
+ throw withErrno('EISDIR');
312
312
  await tx.remove(existing.data);
313
313
  await tx.remove(newDirList[_new.base]);
314
314
  }
@@ -336,9 +336,9 @@ export class StoreFS extends FileSystem {
336
336
  const tx = __addDisposableResource(env_6, this.transaction(), false);
337
337
  const _old = parse(oldPath), _new = parse(newPath),
338
338
  // Remove oldPath from parent's directory listing.
339
- oldDirNode = this.findInodeSync(tx, _old.dir, 'rename'), oldDirList = decodeDirListing((_a = tx.getSync(oldDirNode.data)) !== null && _a !== void 0 ? _a : _throw(ErrnoError.With('ENODATA', _old.dir, 'rename')));
339
+ oldDirNode = this.findInodeSync(tx, _old.dir), oldDirList = decodeDirListing((_a = tx.getSync(oldDirNode.data)) !== null && _a !== void 0 ? _a : _throw(withErrno('ENODATA')));
340
340
  if (!oldDirList[_old.base])
341
- throw ErrnoError.With('ENOENT', oldPath, 'rename');
341
+ throw withErrno('ENOENT');
342
342
  const ino = oldDirList[_old.base];
343
343
  if (ino != this._ids.get(oldPath))
344
344
  err(`Ino mismatch while renaming ${oldPath} to ${newPath}`);
@@ -349,19 +349,16 @@ export class StoreFS extends FileSystem {
349
349
  We append '/' to avoid matching folders that are a substring of the bottom-most folder in the path.
350
350
  */
351
351
  if ((_new.dir + '/').startsWith(oldPath + '/'))
352
- throw new ErrnoError(Errno.EBUSY, _old.dir);
352
+ throw withErrno('EBUSY');
353
353
  // Add newPath to parent's directory listing.
354
354
  const sameParent = _new.dir === _old.dir;
355
355
  // Prevent us from re-grabbing the same directory listing, which still contains `old_path.base.`
356
- const newDirNode = sameParent ? oldDirNode : this.findInodeSync(tx, _new.dir, 'rename');
357
- const newDirList = sameParent
358
- ? oldDirList
359
- : decodeDirListing((_b = tx.getSync(newDirNode.data)) !== null && _b !== void 0 ? _b : _throw(ErrnoError.With('ENODATA', _new.dir, 'rename')));
356
+ const newDirNode = sameParent ? oldDirNode : this.findInodeSync(tx, _new.dir);
357
+ const newDirList = sameParent ? oldDirList : decodeDirListing((_b = tx.getSync(newDirNode.data)) !== null && _b !== void 0 ? _b : _throw(withErrno('ENODATA')));
360
358
  if (newDirList[_new.base]) {
361
- // If it's a file, delete it, if it's a directory, throw a permissions error.
362
- const existing = new Inode((_c = tx.getSync(newDirList[_new.base])) !== null && _c !== void 0 ? _c : _throw(ErrnoError.With('ENOENT', newPath, 'rename')));
359
+ const existing = new Inode((_c = tx.getSync(newDirList[_new.base])) !== null && _c !== void 0 ? _c : _throw(withErrno('ENOENT')));
363
360
  if (!existing.toStats().isFile())
364
- throw ErrnoError.With('EPERM', newPath, 'rename');
361
+ throw withErrno('EISDIR');
365
362
  tx.removeSync(existing.data);
366
363
  tx.removeSync(newDirList[_new.base]);
367
364
  }
@@ -384,7 +381,7 @@ export class StoreFS extends FileSystem {
384
381
  const env_7 = { stack: [], error: void 0, hasError: false };
385
382
  try {
386
383
  const tx = __addDisposableResource(env_7, this.transaction(), true);
387
- return await this.findInode(tx, path, 'stat');
384
+ return await this.findInode(tx, path);
388
385
  }
389
386
  catch (e_7) {
390
387
  env_7.error = e_7;
@@ -400,7 +397,7 @@ export class StoreFS extends FileSystem {
400
397
  const env_8 = { stack: [], error: void 0, hasError: false };
401
398
  try {
402
399
  const tx = __addDisposableResource(env_8, this.transaction(), false);
403
- return this.findInodeSync(tx, path, 'stat');
400
+ return this.findInodeSync(tx, path);
404
401
  }
405
402
  catch (e_8) {
406
403
  env_8.error = e_8;
@@ -414,10 +411,10 @@ export class StoreFS extends FileSystem {
414
411
  const env_9 = { stack: [], error: void 0, hasError: false };
415
412
  try {
416
413
  const tx = __addDisposableResource(env_9, this.transaction(), true);
417
- const inode = await this.findInode(tx, path, 'touch');
414
+ const inode = await this.findInode(tx, path);
418
415
  if (inode.update(metadata)) {
419
416
  this._add(inode.ino, path);
420
- tx.setSync(inode.ino, serialize(inode));
417
+ tx.setSync(inode.ino, inode);
421
418
  }
422
419
  await tx.commit();
423
420
  }
@@ -435,10 +432,10 @@ export class StoreFS extends FileSystem {
435
432
  const env_10 = { stack: [], error: void 0, hasError: false };
436
433
  try {
437
434
  const tx = __addDisposableResource(env_10, this.transaction(), false);
438
- const inode = this.findInodeSync(tx, path, 'touch');
435
+ const inode = this.findInodeSync(tx, path);
439
436
  if (inode.update(metadata)) {
440
437
  this._add(inode.ino, path);
441
- tx.setSync(inode.ino, serialize(inode));
438
+ tx.setSync(inode.ino, inode);
442
439
  }
443
440
  tx.commitSync();
444
441
  }
@@ -452,11 +449,11 @@ export class StoreFS extends FileSystem {
452
449
  }
453
450
  async createFile(path, options) {
454
451
  options.mode |= S_IFREG;
455
- return await this.commitNew(path, options, new Uint8Array(), 'createFile');
452
+ return await this.commitNew(path, options, new Uint8Array());
456
453
  }
457
454
  createFileSync(path, options) {
458
455
  options.mode |= S_IFREG;
459
- return this.commitNewSync(path, options, new Uint8Array(), 'createFile');
456
+ return this.commitNewSync(path, options, new Uint8Array());
460
457
  }
461
458
  async unlink(path) {
462
459
  return this.remove(path, false);
@@ -465,32 +462,30 @@ export class StoreFS extends FileSystem {
465
462
  this.removeSync(path, false);
466
463
  }
467
464
  async rmdir(path) {
468
- if ((await this.readdir(path)).length) {
469
- throw ErrnoError.With('ENOTEMPTY', path, 'rmdir');
470
- }
465
+ if ((await this.readdir(path)).length)
466
+ throw withErrno('ENOTEMPTY');
471
467
  await this.remove(path, true);
472
468
  }
473
469
  rmdirSync(path) {
474
- if (this.readdirSync(path).length) {
475
- throw ErrnoError.With('ENOTEMPTY', path, 'rmdir');
476
- }
470
+ if (this.readdirSync(path).length)
471
+ throw withErrno('ENOTEMPTY');
477
472
  this.removeSync(path, true);
478
473
  }
479
474
  async mkdir(path, options) {
480
475
  options.mode |= S_IFDIR;
481
- return await this.commitNew(path, options, encodeUTF8('{}'), 'mkdir');
476
+ return await this.commitNew(path, options, encodeUTF8('{}'));
482
477
  }
483
478
  mkdirSync(path, options) {
484
479
  options.mode |= S_IFDIR;
485
- return this.commitNewSync(path, options, encodeUTF8('{}'), 'mkdir');
480
+ return this.commitNewSync(path, options, encodeUTF8('{}'));
486
481
  }
487
482
  async readdir(path) {
488
483
  var _a;
489
484
  const env_11 = { stack: [], error: void 0, hasError: false };
490
485
  try {
491
486
  const tx = __addDisposableResource(env_11, this.transaction(), true);
492
- const node = await this.findInode(tx, path, 'readdir');
493
- return Object.keys(decodeDirListing((_a = (await tx.get(node.data))) !== null && _a !== void 0 ? _a : _throw(ErrnoError.With('ENOENT', path, 'readdir'))));
487
+ const node = await this.findInode(tx, path);
488
+ return Object.keys(decodeDirListing((_a = (await tx.get(node.data))) !== null && _a !== void 0 ? _a : _throw(withErrno('ENOENT'))));
494
489
  }
495
490
  catch (e_11) {
496
491
  env_11.error = e_11;
@@ -507,8 +502,8 @@ export class StoreFS extends FileSystem {
507
502
  const env_12 = { stack: [], error: void 0, hasError: false };
508
503
  try {
509
504
  const tx = __addDisposableResource(env_12, this.transaction(), false);
510
- const node = this.findInodeSync(tx, path, 'readdir');
511
- return Object.keys(decodeDirListing((_a = tx.getSync(node.data)) !== null && _a !== void 0 ? _a : _throw(ErrnoError.With('ENOENT', path, 'readdir'))));
505
+ const node = this.findInodeSync(tx, path);
506
+ return Object.keys(decodeDirListing((_a = tx.getSync(node.data)) !== null && _a !== void 0 ? _a : _throw(withErrno('ENOENT'))));
512
507
  }
513
508
  catch (e_12) {
514
509
  env_12.error = e_12;
@@ -521,17 +516,23 @@ export class StoreFS extends FileSystem {
521
516
  /**
522
517
  * Updated the inode and data node at `path`
523
518
  */
524
- async sync(path, data, metadata) {
519
+ async sync() { }
520
+ /**
521
+ * Updated the inode and data node at `path`
522
+ */
523
+ syncSync() { }
524
+ async link(target, link) {
525
+ var _a;
525
526
  const env_13 = { stack: [], error: void 0, hasError: false };
526
527
  try {
527
528
  const tx = __addDisposableResource(env_13, this.transaction(), true);
528
- const inode = await this.findInode(tx, path, 'sync');
529
- if (data)
530
- await tx.set(inode.data, data);
531
- if (inode.update(metadata)) {
532
- this._add(inode.ino, path);
533
- await tx.set(inode.ino, serialize(inode));
534
- }
529
+ const newDir = dirname(link), newDirNode = await this.findInode(tx, newDir), listing = decodeDirListing((_a = (await tx.get(newDirNode.data))) !== null && _a !== void 0 ? _a : _throw(withErrno('ENOENT')));
530
+ const inode = await this.findInode(tx, target);
531
+ inode.nlink++;
532
+ listing[basename(link)] = inode.ino;
533
+ this._add(inode.ino, link);
534
+ await tx.set(inode.ino, inode);
535
+ await tx.set(newDirNode.data, encodeDirListing(listing));
535
536
  await tx.commit();
536
537
  }
537
538
  catch (e_13) {
@@ -544,20 +545,18 @@ export class StoreFS extends FileSystem {
544
545
  await result_7;
545
546
  }
546
547
  }
547
- /**
548
- * Updated the inode and data node at `path`
549
- */
550
- syncSync(path, data, metadata) {
548
+ linkSync(target, link) {
549
+ var _a;
551
550
  const env_14 = { stack: [], error: void 0, hasError: false };
552
551
  try {
553
552
  const tx = __addDisposableResource(env_14, this.transaction(), false);
554
- const inode = this.findInodeSync(tx, path, 'sync');
555
- if (data)
556
- tx.setSync(inode.data, data);
557
- if (inode.update(metadata)) {
558
- this._add(inode.ino, path);
559
- tx.setSync(inode.ino, serialize(inode));
560
- }
553
+ const newDir = dirname(link), newDirNode = this.findInodeSync(tx, newDir), listing = decodeDirListing((_a = tx.getSync(newDirNode.data)) !== null && _a !== void 0 ? _a : _throw(withErrno('ENOENT')));
554
+ const inode = this.findInodeSync(tx, target);
555
+ inode.nlink++;
556
+ listing[basename(link)] = inode.ino;
557
+ this._add(inode.ino, link);
558
+ tx.setSync(inode.ino, inode);
559
+ tx.setSync(newDirNode.data, encodeDirListing(listing));
561
560
  tx.commitSync();
562
561
  }
563
562
  catch (e_14) {
@@ -568,19 +567,19 @@ export class StoreFS extends FileSystem {
568
567
  __disposeResources(env_14);
569
568
  }
570
569
  }
571
- async link(target, link) {
570
+ async read(path, buffer, offset, end) {
572
571
  var _a;
573
572
  const env_15 = { stack: [], error: void 0, hasError: false };
574
573
  try {
575
574
  const tx = __addDisposableResource(env_15, this.transaction(), true);
576
- const newDir = dirname(link), newDirNode = await this.findInode(tx, newDir, 'link'), listing = decodeDirListing((_a = (await tx.get(newDirNode.data))) !== null && _a !== void 0 ? _a : _throw(ErrnoError.With('ENOENT', newDir, 'link')));
577
- const inode = await this.findInode(tx, target, 'link');
578
- inode.nlink++;
579
- listing[basename(link)] = inode.ino;
580
- this._add(inode.ino, link);
581
- await tx.set(inode.ino, serialize(inode));
582
- await tx.set(newDirNode.data, encodeDirListing(listing));
583
- await tx.commit();
575
+ const inode = await this.findInode(tx, path);
576
+ if (inode.size == 0)
577
+ return;
578
+ const data = (_a = (await tx.get(inode.data, offset, end))) !== null && _a !== void 0 ? _a : _throw(withErrno('ENODATA'));
579
+ const _ = tx.flag('partial') ? data : data.subarray(offset, end);
580
+ if (_.byteLength > buffer.byteLength)
581
+ err(`Trying to place ${_.byteLength} bytes into a ${buffer.byteLength} byte buffer on read`);
582
+ buffer.set(_);
584
583
  }
585
584
  catch (e_15) {
586
585
  env_15.error = e_15;
@@ -592,80 +591,34 @@ export class StoreFS extends FileSystem {
592
591
  await result_8;
593
592
  }
594
593
  }
595
- linkSync(target, link) {
594
+ readSync(path, buffer, offset, end) {
596
595
  var _a;
597
596
  const env_16 = { stack: [], error: void 0, hasError: false };
598
597
  try {
599
598
  const tx = __addDisposableResource(env_16, this.transaction(), false);
600
- const newDir = dirname(link), newDirNode = this.findInodeSync(tx, newDir, 'link'), listing = decodeDirListing((_a = tx.getSync(newDirNode.data)) !== null && _a !== void 0 ? _a : _throw(ErrnoError.With('ENOENT', newDir, 'link')));
601
- const inode = this.findInodeSync(tx, target, 'link');
602
- inode.nlink++;
603
- listing[basename(link)] = inode.ino;
604
- this._add(inode.ino, link);
605
- tx.setSync(inode.ino, serialize(inode));
606
- tx.setSync(newDirNode.data, encodeDirListing(listing));
607
- tx.commitSync();
608
- }
609
- catch (e_16) {
610
- env_16.error = e_16;
611
- env_16.hasError = true;
612
- }
613
- finally {
614
- __disposeResources(env_16);
615
- }
616
- }
617
- async read(path, buffer, offset, end) {
618
- var _a;
619
- const env_17 = { stack: [], error: void 0, hasError: false };
620
- try {
621
- const tx = __addDisposableResource(env_17, this.transaction(), true);
622
- const inode = await this.findInode(tx, path, 'read');
599
+ const inode = this.findInodeSync(tx, path);
623
600
  if (inode.size == 0)
624
601
  return;
625
- const data = (_a = (await tx.get(inode.data, offset, end))) !== null && _a !== void 0 ? _a : _throw(ErrnoError.With('ENODATA', path, 'read'));
602
+ const data = (_a = tx.getSync(inode.data, offset, end)) !== null && _a !== void 0 ? _a : _throw(withErrno('ENODATA'));
626
603
  const _ = tx.flag('partial') ? data : data.subarray(offset, end);
627
604
  if (_.byteLength > buffer.byteLength)
628
605
  err(`Trying to place ${_.byteLength} bytes into a ${buffer.byteLength} byte buffer on read`);
629
606
  buffer.set(_);
630
607
  }
631
- catch (e_17) {
632
- env_17.error = e_17;
633
- env_17.hasError = true;
634
- }
635
- finally {
636
- const result_9 = __disposeResources(env_17);
637
- if (result_9)
638
- await result_9;
639
- }
640
- }
641
- readSync(path, buffer, offset, end) {
642
- var _a;
643
- const env_18 = { stack: [], error: void 0, hasError: false };
644
- try {
645
- const tx = __addDisposableResource(env_18, this.transaction(), false);
646
- const inode = this.findInodeSync(tx, path, 'read');
647
- if (inode.size == 0)
648
- return;
649
- const data = (_a = tx.getSync(inode.data, offset, end)) !== null && _a !== void 0 ? _a : _throw(ErrnoError.With('ENODATA', path, 'read'));
650
- const _ = tx.flag('partial') ? data : data.subarray(offset, end);
651
- if (_.byteLength > buffer.byteLength)
652
- err(`Trying to place ${_.byteLength} bytes into a ${buffer.byteLength} byte buffer on read`);
653
- buffer.set(_);
654
- }
655
- catch (e_18) {
656
- env_18.error = e_18;
657
- env_18.hasError = true;
608
+ catch (e_16) {
609
+ env_16.error = e_16;
610
+ env_16.hasError = true;
658
611
  }
659
612
  finally {
660
- __disposeResources(env_18);
613
+ __disposeResources(env_16);
661
614
  }
662
615
  }
663
616
  async write(path, data, offset) {
664
617
  var _a;
665
- const env_19 = { stack: [], error: void 0, hasError: false };
618
+ const env_17 = { stack: [], error: void 0, hasError: false };
666
619
  try {
667
- const tx = __addDisposableResource(env_19, this.transaction(), true);
668
- const inode = await this.findInode(tx, path, 'write');
620
+ const tx = __addDisposableResource(env_17, this.transaction(), true);
621
+ const inode = await this.findInode(tx, path);
669
622
  let buffer = data;
670
623
  if (!tx.flag('partial')) {
671
624
  buffer = extendBuffer((_a = (await tx.get(inode.data))) !== null && _a !== void 0 ? _a : new Uint8Array(), offset + data.byteLength);
@@ -676,22 +629,22 @@ export class StoreFS extends FileSystem {
676
629
  this._add(inode.ino, path);
677
630
  await tx.commit();
678
631
  }
679
- catch (e_19) {
680
- env_19.error = e_19;
681
- env_19.hasError = true;
632
+ catch (e_17) {
633
+ env_17.error = e_17;
634
+ env_17.hasError = true;
682
635
  }
683
636
  finally {
684
- const result_10 = __disposeResources(env_19);
685
- if (result_10)
686
- await result_10;
637
+ const result_9 = __disposeResources(env_17);
638
+ if (result_9)
639
+ await result_9;
687
640
  }
688
641
  }
689
642
  writeSync(path, data, offset) {
690
643
  var _a;
691
- const env_20 = { stack: [], error: void 0, hasError: false };
644
+ const env_18 = { stack: [], error: void 0, hasError: false };
692
645
  try {
693
- const tx = __addDisposableResource(env_20, this.transaction(), false);
694
- const inode = this.findInodeSync(tx, path, 'write');
646
+ const tx = __addDisposableResource(env_18, this.transaction(), false);
647
+ const inode = this.findInodeSync(tx, path);
695
648
  let buffer = data;
696
649
  if (!tx.flag('partial')) {
697
650
  buffer = extendBuffer((_a = tx.getSync(inode.data)) !== null && _a !== void 0 ? _a : new Uint8Array(), offset + data.byteLength);
@@ -702,12 +655,12 @@ export class StoreFS extends FileSystem {
702
655
  this._add(inode.ino, path);
703
656
  tx.commitSync();
704
657
  }
705
- catch (e_20) {
706
- env_20.error = e_20;
707
- env_20.hasError = true;
658
+ catch (e_18) {
659
+ env_18.error = e_18;
660
+ env_18.hasError = true;
708
661
  }
709
662
  finally {
710
- __disposeResources(env_20);
663
+ __disposeResources(env_18);
711
664
  }
712
665
  }
713
666
  /**
@@ -721,69 +674,69 @@ export class StoreFS extends FileSystem {
721
674
  * Checks if the root directory exists. Creates it if it doesn't.
722
675
  */
723
676
  async checkRoot() {
724
- const env_21 = { stack: [], error: void 0, hasError: false };
677
+ const env_19 = { stack: [], error: void 0, hasError: false };
725
678
  try {
726
- const tx = __addDisposableResource(env_21, this.transaction(), true);
679
+ const tx = __addDisposableResource(env_19, this.transaction(), true);
727
680
  if (await tx.get(rootIno))
728
681
  return;
729
682
  const inode = new Inode({ ino: rootIno, data: 1, mode: 0o777 | S_IFDIR });
730
683
  await tx.set(inode.data, encodeUTF8('{}'));
731
684
  this._add(rootIno, '/');
732
- await tx.set(rootIno, serialize(inode));
685
+ await tx.set(rootIno, inode);
733
686
  await tx.commit();
734
687
  }
735
- catch (e_21) {
736
- env_21.error = e_21;
737
- env_21.hasError = true;
688
+ catch (e_19) {
689
+ env_19.error = e_19;
690
+ env_19.hasError = true;
738
691
  }
739
692
  finally {
740
- const result_11 = __disposeResources(env_21);
741
- if (result_11)
742
- await result_11;
693
+ const result_10 = __disposeResources(env_19);
694
+ if (result_10)
695
+ await result_10;
743
696
  }
744
697
  }
745
698
  /**
746
699
  * Checks if the root directory exists. Creates it if it doesn't.
747
700
  */
748
701
  checkRootSync() {
749
- const env_22 = { stack: [], error: void 0, hasError: false };
702
+ const env_20 = { stack: [], error: void 0, hasError: false };
750
703
  try {
751
- const tx = __addDisposableResource(env_22, this.transaction(), false);
704
+ const tx = __addDisposableResource(env_20, this.transaction(), false);
752
705
  if (tx.getSync(rootIno))
753
706
  return;
754
707
  const inode = new Inode({ ino: rootIno, data: 1, mode: 0o777 | S_IFDIR });
755
708
  tx.setSync(inode.data, encodeUTF8('{}'));
756
709
  this._add(rootIno, '/');
757
- tx.setSync(rootIno, serialize(inode));
710
+ tx.setSync(rootIno, inode);
758
711
  tx.commitSync();
759
712
  }
760
- catch (e_22) {
761
- env_22.error = e_22;
762
- env_22.hasError = true;
713
+ catch (e_20) {
714
+ env_20.error = e_20;
715
+ env_20.hasError = true;
763
716
  }
764
717
  finally {
765
- __disposeResources(env_22);
718
+ __disposeResources(env_20);
766
719
  }
767
720
  }
768
721
  /**
769
722
  * Populates the `_ids` and `_paths` maps with all existing files stored in the underlying `Store`.
770
723
  */
771
724
  async _populate() {
772
- const env_23 = { stack: [], error: void 0, hasError: false };
725
+ const env_21 = { stack: [], error: void 0, hasError: false };
773
726
  try {
774
727
  if (this._initialized) {
775
728
  warn('Attempted to populate tables after initialization');
776
729
  return;
777
730
  }
778
731
  debug('Populating tables with existing store metadata');
779
- const tx = __addDisposableResource(env_23, this.transaction(), true);
732
+ const tx = __addDisposableResource(env_21, this.transaction(), true);
780
733
  const rootData = await tx.get(rootIno);
781
734
  if (!rootData) {
782
735
  notice('Store does not have a root inode');
783
736
  const inode = new Inode({ ino: rootIno, data: 1, mode: 0o777 | S_IFDIR });
784
737
  await tx.set(inode.data, encodeUTF8('{}'));
785
738
  this._add(rootIno, '/');
786
- await tx.set(rootIno, serialize(inode));
739
+ await tx.set(rootIno, inode);
787
740
  await tx.commit();
788
741
  return;
789
742
  }
@@ -830,27 +783,63 @@ export class StoreFS extends FileSystem {
830
783
  }
831
784
  debug(`Added ${i} existing inode(s) from store`);
832
785
  }
833
- catch (e_23) {
834
- env_23.error = e_23;
835
- env_23.hasError = true;
786
+ catch (e_21) {
787
+ env_21.error = e_21;
788
+ env_21.hasError = true;
836
789
  }
837
790
  finally {
838
- const result_12 = __disposeResources(env_23);
839
- if (result_12)
840
- await result_12;
791
+ const result_11 = __disposeResources(env_21);
792
+ if (result_11)
793
+ await result_11;
841
794
  }
842
795
  }
796
+ /**
797
+ * Find an inode without using the ID tables
798
+ */
799
+ async _findInode(tx, path, visited = new Set()) {
800
+ var _a, _b, _c;
801
+ if (visited.has(path))
802
+ throw crit(withErrno('EIO', 'Infinite loop detected while finding inode'));
803
+ visited.add(path);
804
+ if (path == '/')
805
+ return new Inode((_a = (await tx.get(rootIno))) !== null && _a !== void 0 ? _a : _throw(withErrno('ENODATA')));
806
+ const { dir: parent, base: filename } = parse(path);
807
+ const inode = await this._findInode(tx, parent, visited);
808
+ const dirList = decodeDirListing((_b = (await tx.get(inode.data))) !== null && _b !== void 0 ? _b : _throw(withErrno('ENODATA')));
809
+ if (!(filename in dirList))
810
+ throw withErrno('ENOENT');
811
+ return new Inode((_c = (await tx.get(dirList[filename]))) !== null && _c !== void 0 ? _c : _throw(withErrno('ENODATA')));
812
+ }
813
+ /**
814
+ * Find an inode without using the ID tables
815
+ */
816
+ _findInodeSync(tx, path, visited = new Set()) {
817
+ var _a, _b, _c;
818
+ if (visited.has(path))
819
+ throw crit(withErrno('EIO', 'Infinite loop detected while finding inode'));
820
+ visited.add(path);
821
+ if (path == '/')
822
+ return new Inode((_a = tx.getSync(rootIno)) !== null && _a !== void 0 ? _a : _throw(withErrno('ENOENT')));
823
+ const { dir: parent, base: filename } = parse(path);
824
+ const inode = this._findInodeSync(tx, parent, visited);
825
+ const dir = decodeDirListing((_b = tx.getSync(inode.data)) !== null && _b !== void 0 ? _b : _throw(withErrno('ENODATA')));
826
+ if (!(filename in dir))
827
+ throw withErrno('ENOENT');
828
+ return new Inode((_c = tx.getSync(dir[filename])) !== null && _c !== void 0 ? _c : _throw(withErrno('ENODATA')));
829
+ }
843
830
  /**
844
831
  * Finds the Inode of `path`.
845
832
  * @param path The path to look up.
846
833
  * @todo memoize/cache
847
834
  */
848
- async findInode(tx, path, syscall) {
835
+ async findInode(tx, path) {
849
836
  var _a;
837
+ if (this.attributes.has('no_id_tables'))
838
+ return await this._findInode(tx, path);
850
839
  const ino = this._ids.get(path);
851
840
  if (ino === undefined)
852
- throw ErrnoError.With('ENOENT', path, syscall);
853
- return new Inode((_a = (await tx.get(ino))) !== null && _a !== void 0 ? _a : _throw(ErrnoError.With('ENOENT', path, syscall)));
841
+ throw withErrno('ENOENT');
842
+ return new Inode((_a = (await tx.get(ino))) !== null && _a !== void 0 ? _a : _throw(withErrno('ENOENT')));
854
843
  }
855
844
  /**
856
845
  * Finds the Inode of `path`.
@@ -858,23 +847,23 @@ export class StoreFS extends FileSystem {
858
847
  * @return The Inode of the path p.
859
848
  * @todo memoize/cache
860
849
  */
861
- findInodeSync(tx, path, syscall) {
850
+ findInodeSync(tx, path) {
862
851
  var _a;
852
+ if (this.attributes.has('no_id_tables'))
853
+ return this._findInodeSync(tx, path);
863
854
  const ino = this._ids.get(path);
864
855
  if (ino === undefined)
865
- throw ErrnoError.With('ENOENT', path, syscall);
866
- return new Inode((_a = tx.getSync(ino)) !== null && _a !== void 0 ? _a : _throw(ErrnoError.With('ENOENT', path, syscall)));
856
+ throw withErrno('ENOENT');
857
+ return new Inode((_a = tx.getSync(ino)) !== null && _a !== void 0 ? _a : _throw(withErrno('ENOENT')));
867
858
  }
868
- /**
869
- * Allocates a new ID and adds the ID/path
870
- */
871
- allocNew(path, syscall) {
859
+ /** Allocates a new ID and adds the ID/path */
860
+ allocNew(path) {
872
861
  var _a;
873
862
  (_a = this._lastID) !== null && _a !== void 0 ? _a : (this._lastID = Math.max(...this._paths.keys()));
874
863
  this._lastID += 2;
875
864
  const id = this._lastID;
876
865
  if (id > size_max)
877
- throw err(new ErrnoError(Errno.ENOSPC, 'No IDs available', path, syscall), { fs: this });
866
+ throw err(withErrno('ENOSPC', 'No IDs available'));
878
867
  this._add(id, path);
879
868
  return id;
880
869
  }
@@ -885,9 +874,9 @@ export class StoreFS extends FileSystem {
885
874
  * @param options The options to create the new file with.
886
875
  * @param data The data to store at the file's data node.
887
876
  */
888
- async commitNew(path, options, data, syscall) {
877
+ async commitNew(path, options, data) {
889
878
  var _a;
890
- const env_24 = { stack: [], error: void 0, hasError: false };
879
+ const env_22 = { stack: [], error: void 0, hasError: false };
891
880
  try {
892
881
  /*
893
882
  The root always exists.
@@ -895,23 +884,24 @@ export class StoreFS extends FileSystem {
895
884
  we will create a file with name '' in root if path is '/'.
896
885
  */
897
886
  if (path == '/')
898
- throw ErrnoError.With('EEXIST', path, syscall);
899
- const tx = __addDisposableResource(env_24, this.transaction(), true);
887
+ throw withErrno('EEXIST');
888
+ const tx = __addDisposableResource(env_22, this.transaction(), true);
900
889
  const { dir: parentPath, base: fname } = parse(path);
901
- const parent = await this.findInode(tx, parentPath, syscall);
902
- const listing = decodeDirListing((_a = (await tx.get(parent.data))) !== null && _a !== void 0 ? _a : _throw(ErrnoError.With('ENOENT', parentPath, syscall)));
890
+ const parent = await this.findInode(tx, parentPath);
891
+ const listing = decodeDirListing((_a = (await tx.get(parent.data))) !== null && _a !== void 0 ? _a : _throw(withErrno('ENOENT')));
903
892
  // Check if file already exists.
904
893
  if (listing[fname])
905
- throw ErrnoError.With('EEXIST', path, syscall);
906
- const id = this.allocNew(path, syscall);
894
+ throw withErrno('EEXIST');
895
+ const id = this.allocNew(path);
907
896
  // Commit data.
908
897
  const inode = new Inode({
909
898
  ...options,
910
899
  ino: id,
911
900
  data: id + 1,
912
901
  size: data.byteLength,
902
+ nlink: 1,
913
903
  });
914
- await tx.set(inode.ino, serialize(inode));
904
+ await tx.set(inode.ino, inode);
915
905
  await tx.set(inode.data, data);
916
906
  // Update and commit parent directory listing.
917
907
  listing[fname] = inode.ino;
@@ -919,14 +909,14 @@ export class StoreFS extends FileSystem {
919
909
  await tx.commit();
920
910
  return inode;
921
911
  }
922
- catch (e_24) {
923
- env_24.error = e_24;
924
- env_24.hasError = true;
912
+ catch (e_22) {
913
+ env_22.error = e_22;
914
+ env_22.hasError = true;
925
915
  }
926
916
  finally {
927
- const result_13 = __disposeResources(env_24);
928
- if (result_13)
929
- await result_13;
917
+ const result_12 = __disposeResources(env_22);
918
+ if (result_12)
919
+ await result_12;
930
920
  }
931
921
  }
932
922
  /**
@@ -937,9 +927,9 @@ export class StoreFS extends FileSystem {
937
927
  * @param data The data to store at the file's data node.
938
928
  * @return The Inode for the new file.
939
929
  */
940
- commitNewSync(path, options, data, syscall) {
930
+ commitNewSync(path, options, data) {
941
931
  var _a;
942
- const env_25 = { stack: [], error: void 0, hasError: false };
932
+ const env_23 = { stack: [], error: void 0, hasError: false };
943
933
  try {
944
934
  /*
945
935
  The root always exists.
@@ -947,36 +937,35 @@ export class StoreFS extends FileSystem {
947
937
  we will create a file with name '' in root if path is '/'.
948
938
  */
949
939
  if (path == '/')
950
- throw ErrnoError.With('EEXIST', path, syscall);
951
- const tx = __addDisposableResource(env_25, this.transaction(), false);
940
+ throw withErrno('EEXIST');
941
+ const tx = __addDisposableResource(env_23, this.transaction(), false);
952
942
  const { dir: parentPath, base: fname } = parse(path);
953
- const parent = this.findInodeSync(tx, parentPath, syscall);
954
- const listing = decodeDirListing((_a = tx.getSync(parent.data)) !== null && _a !== void 0 ? _a : _throw(ErrnoError.With('ENOENT', parentPath, syscall)));
955
- // Check if file already exists.
943
+ const parent = this.findInodeSync(tx, parentPath);
944
+ const listing = decodeDirListing((_a = tx.getSync(parent.data)) !== null && _a !== void 0 ? _a : _throw(withErrno('ENOENT')));
956
945
  if (listing[fname])
957
- throw ErrnoError.With('EEXIST', path, syscall);
958
- const id = this.allocNew(path, syscall);
959
- // Commit data.
946
+ throw withErrno('EEXIST');
947
+ const id = this.allocNew(path);
960
948
  const inode = new Inode({
961
949
  ...options,
962
950
  ino: id,
963
951
  data: id + 1,
964
952
  size: data.byteLength,
953
+ nlink: 1,
965
954
  });
966
955
  // Update and commit parent directory listing.
967
- tx.setSync(inode.ino, serialize(inode));
956
+ tx.setSync(inode.ino, inode);
968
957
  tx.setSync(inode.data, data);
969
958
  listing[fname] = inode.ino;
970
959
  tx.setSync(parent.data, encodeDirListing(listing));
971
960
  tx.commitSync();
972
961
  return inode;
973
962
  }
974
- catch (e_25) {
975
- env_25.error = e_25;
976
- env_25.hasError = true;
963
+ catch (e_23) {
964
+ env_23.error = e_23;
965
+ env_23.hasError = true;
977
966
  }
978
967
  finally {
979
- __disposeResources(env_25);
968
+ __disposeResources(env_23);
980
969
  }
981
970
  }
982
971
  /**
@@ -986,23 +975,21 @@ export class StoreFS extends FileSystem {
986
975
  */
987
976
  async remove(path, isDir) {
988
977
  var _a, _b;
989
- const env_26 = { stack: [], error: void 0, hasError: false };
978
+ const env_24 = { stack: [], error: void 0, hasError: false };
990
979
  try {
991
- const syscall = isDir ? 'rmdir' : 'unlink';
992
- const tx = __addDisposableResource(env_26, this.transaction(), true);
993
- const { dir: parent, base: fileName } = parse(path), parentNode = await this.findInode(tx, parent, syscall), listing = decodeDirListing((_a = (await tx.get(parentNode.data))) !== null && _a !== void 0 ? _a : _throw(ErrnoError.With('ENOENT', parent, syscall)));
994
- if (!listing[fileName]) {
995
- throw ErrnoError.With('ENOENT', path, syscall);
996
- }
980
+ const tx = __addDisposableResource(env_24, this.transaction(), true);
981
+ const { dir: parent, base: fileName } = parse(path), parentNode = await this.findInode(tx, parent), listing = decodeDirListing((_a = (await tx.get(parentNode.data))) !== null && _a !== void 0 ? _a : _throw(withErrno('ENOENT')));
982
+ if (!listing[fileName])
983
+ throw withErrno('ENOENT');
997
984
  const ino = listing[fileName];
998
- const inode = new Inode((_b = (await tx.get(ino))) !== null && _b !== void 0 ? _b : _throw(ErrnoError.With('ENOENT', path, syscall)));
985
+ const inode = new Inode((_b = (await tx.get(ino))) !== null && _b !== void 0 ? _b : _throw(withErrno('ENOENT')));
999
986
  delete listing[fileName];
1000
987
  if (!isDir && isDirectory(inode))
1001
- throw ErrnoError.With('EISDIR', path, syscall);
988
+ throw withErrno('EISDIR');
1002
989
  await tx.set(parentNode.data, encodeDirListing(listing));
1003
990
  if (inode.nlink > 1) {
1004
991
  inode.update({ nlink: inode.nlink - 1 });
1005
- await tx.set(inode.ino, serialize(inode));
992
+ await tx.set(inode.ino, inode);
1006
993
  }
1007
994
  else {
1008
995
  await tx.remove(inode.data);
@@ -1011,14 +998,14 @@ export class StoreFS extends FileSystem {
1011
998
  }
1012
999
  await tx.commit();
1013
1000
  }
1014
- catch (e_26) {
1015
- env_26.error = e_26;
1016
- env_26.hasError = true;
1001
+ catch (e_24) {
1002
+ env_24.error = e_24;
1003
+ env_24.hasError = true;
1017
1004
  }
1018
1005
  finally {
1019
- const result_14 = __disposeResources(env_26);
1020
- if (result_14)
1021
- await result_14;
1006
+ const result_13 = __disposeResources(env_24);
1007
+ if (result_13)
1008
+ await result_13;
1022
1009
  }
1023
1010
  }
1024
1011
  /**
@@ -1028,22 +1015,20 @@ export class StoreFS extends FileSystem {
1028
1015
  */
1029
1016
  removeSync(path, isDir) {
1030
1017
  var _a, _b;
1031
- const env_27 = { stack: [], error: void 0, hasError: false };
1018
+ const env_25 = { stack: [], error: void 0, hasError: false };
1032
1019
  try {
1033
- const syscall = isDir ? 'rmdir' : 'unlink';
1034
- const tx = __addDisposableResource(env_27, this.transaction(), false);
1035
- const { dir: parent, base: fileName } = parse(path), parentNode = this.findInodeSync(tx, parent, syscall), listing = decodeDirListing((_a = tx.getSync(parentNode.data)) !== null && _a !== void 0 ? _a : _throw(ErrnoError.With('ENOENT', parent, syscall))), ino = listing[fileName];
1020
+ const tx = __addDisposableResource(env_25, this.transaction(), false);
1021
+ const { dir: parent, base: fileName } = parse(path), parentNode = this.findInodeSync(tx, parent), listing = decodeDirListing((_a = tx.getSync(parentNode.data)) !== null && _a !== void 0 ? _a : _throw(withErrno('ENOENT'))), ino = listing[fileName];
1036
1022
  if (!ino)
1037
- throw ErrnoError.With('ENOENT', path, syscall);
1038
- const inode = new Inode((_b = tx.getSync(ino)) !== null && _b !== void 0 ? _b : _throw(ErrnoError.With('ENOENT', path, syscall)));
1023
+ throw withErrno('ENOENT');
1024
+ const inode = new Inode((_b = tx.getSync(ino)) !== null && _b !== void 0 ? _b : _throw(withErrno('ENOENT')));
1039
1025
  delete listing[fileName];
1040
- if (!isDir && isDirectory(inode)) {
1041
- throw ErrnoError.With('EISDIR', path, syscall);
1042
- }
1026
+ if (!isDir && isDirectory(inode))
1027
+ throw withErrno('EISDIR');
1043
1028
  tx.setSync(parentNode.data, encodeDirListing(listing));
1044
1029
  if (inode.nlink > 1) {
1045
1030
  inode.update({ nlink: inode.nlink - 1 });
1046
- tx.setSync(inode.ino, serialize(inode));
1031
+ tx.setSync(inode.ino, inode);
1047
1032
  }
1048
1033
  else {
1049
1034
  tx.removeSync(inode.data);
@@ -1052,12 +1037,12 @@ export class StoreFS extends FileSystem {
1052
1037
  }
1053
1038
  tx.commitSync();
1054
1039
  }
1055
- catch (e_27) {
1056
- env_27.error = e_27;
1057
- env_27.hasError = true;
1040
+ catch (e_25) {
1041
+ env_25.error = e_25;
1042
+ env_25.hasError = true;
1058
1043
  }
1059
1044
  finally {
1060
- __disposeResources(env_27);
1045
+ __disposeResources(env_25);
1061
1046
  }
1062
1047
  }
1063
1048
  }