@zenfs/core 0.8.1 → 0.9.0

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.
@@ -83,14 +83,8 @@ declare const AsyncStoreFS_base: (abstract new (...args: any[]) => {
83
83
  rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
84
84
  stat(path: string, cred: Cred): Promise<Stats>;
85
85
  openFile(path: string, flag: string, cred: Cred): Promise<import("../file.js").File>;
86
- createFile(path: string, flag: string, mode: number, cred: Cred): Promise<import("../file.js").File>; /**
87
- * Promise that resolves to the store
88
- */
89
- unlink(path: string, cred: Cred): Promise<void>; /**
90
- * An asynchronous file system which uses an async store to store its data.
91
- * @see AsyncStore
92
- * @internal
93
- */
86
+ createFile(path: string, flag: string, mode: number, cred: Cred): Promise<import("../file.js").File>;
87
+ unlink(path: string, cred: Cred): Promise<void>;
94
88
  rmdir(path: string, cred: Cred): Promise<void>;
95
89
  mkdir(path: string, mode: number, cred: Cred): Promise<void>;
96
90
  readdir(path: string, cred: Cred): Promise<string[]>;
@@ -1,7 +1,7 @@
1
- import type { Cred } from './cred.js';
2
- import { NoSyncFile } from './file.js';
3
- import { FileSystem } from './filesystem.js';
4
- import { Stats } from './stats.js';
1
+ import type { Cred } from '../cred.js';
2
+ import { NoSyncFile } from '../file.js';
3
+ import { FileSystem } from '../filesystem.js';
4
+ import { Stats } from '../stats.js';
5
5
  /**
6
6
  * @internal
7
7
  */
@@ -154,11 +154,11 @@ export declare class IndexDirInode<TData> extends IndexInode<TData> {
154
154
  remove(p: string): IndexInode<TData> | null;
155
155
  }
156
156
  declare const IndexFS_base: (abstract new (...args: any[]) => {
157
- metadata(): import("./filesystem.js").FileSystemMetadata;
157
+ metadata(): import("../filesystem.js").FileSystemMetadata;
158
158
  rename(oldPath: string, newPath: string, cred: Cred): Promise<void>;
159
159
  renameSync(oldPath: string, newPath: string, cred: Cred): void;
160
- createFile(path: string, flag: string, mode: number, cred: Cred): Promise<import("./file.js").File>;
161
- createFileSync(path: string, flag: string, mode: number, cred: Cred): import("./file.js").File;
160
+ createFile(path: string, flag: string, mode: number, cred: Cred): Promise<import("../file.js").File>;
161
+ createFileSync(path: string, flag: string, mode: number, cred: Cred): import("../file.js").File;
162
162
  unlink(path: string, cred: Cred): Promise<void>;
163
163
  unlinkSync(path: string, cred: Cred): void;
164
164
  rmdir(path: string, cred: Cred): Promise<void>;
@@ -172,8 +172,8 @@ declare const IndexFS_base: (abstract new (...args: any[]) => {
172
172
  ready(): Promise<any>;
173
173
  stat(path: string, cred: Cred): Promise<Stats>;
174
174
  statSync(path: string, cred: Cred): Stats;
175
- openFile(path: string, flag: string, cred: Cred): Promise<import("./file.js").File>;
176
- openFileSync(path: string, flag: string, cred: Cred): import("./file.js").File;
175
+ openFile(path: string, flag: string, cred: Cred): Promise<import("../file.js").File>;
176
+ openFileSync(path: string, flag: string, cred: Cred): import("../file.js").File;
177
177
  readdir(path: string, cred: Cred): Promise<string[]>;
178
178
  readdirSync(path: string, cred: Cred): string[];
179
179
  exists(path: string, cred: Cred): Promise<boolean>;
@@ -1,8 +1,8 @@
1
- import { ApiError, ErrorCode } from './ApiError.js';
2
- import { basename, dirname, join } from './emulation/path.js';
3
- import { NoSyncFile, flagToMode, isWriteable } from './file.js';
4
- import { FileSystem, Readonly } from './filesystem.js';
5
- import { FileType, Stats } from './stats.js';
1
+ import { ApiError, ErrorCode } from '../ApiError.js';
2
+ import { basename, dirname, join } from '../emulation/path.js';
3
+ import { NoSyncFile, flagToMode, isWriteable } from '../file.js';
4
+ import { FileSystem, Readonly } from '../filesystem.js';
5
+ import { FileType, Stats } from '../stats.js';
6
6
  /**
7
7
  * A simple class for storing a filesystem index. Assumes that all paths passed
8
8
  * to it are *absolute* paths.
@@ -319,7 +319,7 @@ export class IndexFS extends Readonly(FileSystem) {
319
319
  statSync(path) {
320
320
  const inode = this._index.get(path);
321
321
  if (!inode) {
322
- throw ApiError.With('ENOENT', path, 'statSync');
322
+ throw ApiError.With('ENOENT', path, 'stat');
323
323
  }
324
324
  if (inode.isDirectory()) {
325
325
  return inode.stats;
@@ -356,10 +356,10 @@ export class IndexFS extends Readonly(FileSystem) {
356
356
  // Check if the path exists, and is a file.
357
357
  const inode = this._index.get(path);
358
358
  if (!inode) {
359
- throw ApiError.With('ENOENT', path, 'openFileSync');
359
+ throw ApiError.With('ENOENT', path, 'openFile');
360
360
  }
361
361
  if (!inode.toStats().hasAccess(flagToMode(flag), cred)) {
362
- throw ApiError.With('EACCES', path, 'openFileSync');
362
+ throw ApiError.With('EACCES', path, 'openFile');
363
363
  }
364
364
  if (inode.isDirectory()) {
365
365
  const stats = inode.stats;
@@ -382,12 +382,12 @@ export class IndexFS extends Readonly(FileSystem) {
382
382
  // Check if it exists.
383
383
  const inode = this._index.get(path);
384
384
  if (!inode) {
385
- throw ApiError.With('ENOENT', path, 'readdirSync');
385
+ throw ApiError.With('ENOENT', path, 'readdir');
386
386
  }
387
387
  if (inode.isDirectory()) {
388
388
  return inode.listing;
389
389
  }
390
- throw ApiError.With('ENOTDIR', path, 'readdirSync');
390
+ throw ApiError.With('ENOTDIR', path, 'readdir');
391
391
  }
392
392
  }
393
393
  export class SyncIndexFS extends IndexFS {
@@ -117,7 +117,7 @@ export class UnlockedOverlayFS extends FileSystem {
117
117
  }
118
118
  catch (e) {
119
119
  if (this._deletedFiles.has(oldPath)) {
120
- throw ApiError.With('ENOENT', oldPath, 'renameSync');
120
+ throw ApiError.With('ENOENT', oldPath, 'rename');
121
121
  }
122
122
  }
123
123
  }
@@ -143,7 +143,7 @@ export class UnlockedOverlayFS extends FileSystem {
143
143
  }
144
144
  catch (e) {
145
145
  if (this._deletedFiles.has(p)) {
146
- throw ApiError.With('ENOENT', p, 'statSync');
146
+ throw ApiError.With('ENOENT', p, 'stat');
147
147
  }
148
148
  const oldStat = new Stats(this._readable.statSync(p, cred));
149
149
  // Make the oldStat's mode writable. Preserve the topmost part of the mode, which specifies the type.
@@ -208,7 +208,7 @@ export class UnlockedOverlayFS extends FileSystem {
208
208
  this.checkInitialized();
209
209
  this.checkPath(p);
210
210
  if (!this.existsSync(p, cred)) {
211
- throw ApiError.With('ENOENT', p, 'unlinkSync');
211
+ throw ApiError.With('ENOENT', p, 'unlink');
212
212
  }
213
213
  if (this._writable.existsSync(p, cred)) {
214
214
  this._writable.unlinkSync(p, cred);
@@ -239,7 +239,7 @@ export class UnlockedOverlayFS extends FileSystem {
239
239
  rmdirSync(p, cred) {
240
240
  this.checkInitialized();
241
241
  if (!this.existsSync(p, cred)) {
242
- throw ApiError.With('ENOENT', p, 'rmdirSync');
242
+ throw ApiError.With('ENOENT', p, 'rmdir');
243
243
  }
244
244
  if (this._writable.existsSync(p, cred)) {
245
245
  this._writable.rmdirSync(p, cred);
@@ -247,7 +247,7 @@ export class UnlockedOverlayFS extends FileSystem {
247
247
  if (this.existsSync(p, cred)) {
248
248
  // Check if directory is empty.
249
249
  if (this.readdirSync(p, cred).length > 0) {
250
- throw ApiError.With('ENOTEMPTY', p, 'rmdirSync');
250
+ throw ApiError.With('ENOTEMPTY', p, 'rmdir');
251
251
  }
252
252
  else {
253
253
  this.deletePath(p, cred);
@@ -266,7 +266,7 @@ export class UnlockedOverlayFS extends FileSystem {
266
266
  mkdirSync(p, mode, cred) {
267
267
  this.checkInitialized();
268
268
  if (this.existsSync(p, cred)) {
269
- throw ApiError.With('EEXIST', p, 'mkdirSync');
269
+ throw ApiError.With('EEXIST', p, 'mkdir');
270
270
  }
271
271
  // The below will throw should any of the parent directories fail to exist on _writable.
272
272
  this.createParentDirectoriesSync(p, cred);
@@ -303,7 +303,7 @@ export class UnlockedOverlayFS extends FileSystem {
303
303
  this.checkInitialized();
304
304
  const dirStats = this.statSync(p, cred);
305
305
  if (!dirStats.isDirectory()) {
306
- throw ApiError.With('ENOTDIR', p, 'readdirSync');
306
+ throw ApiError.With('ENOTDIR', p, 'readdir');
307
307
  }
308
308
  // Readdir in both, check delete log on RO file system's listing, merge, return.
309
309
  let contents = [];
@@ -422,7 +422,7 @@ export class UnlockedOverlayFS extends FileSystem {
422
422
  }
423
423
  async operateOnWritableAsync(p, cred) {
424
424
  if (!(await this.exists(p, cred))) {
425
- throw ApiError.With('ENOENT', p, 'operateOnWritableAsync');
425
+ throw ApiError.With('ENOENT', p, 'operateOnWritable');
426
426
  }
427
427
  if (!(await this._writable.exists(p, cred))) {
428
428
  return this.copyToWritable(p, cred);
@@ -110,10 +110,10 @@ export class SyncStoreFS extends Sync(FileSystem) {
110
110
  // Remove oldPath from parent's directory listing.
111
111
  oldDirNode = this.findINode(tx, oldParent), oldDirList = this.getDirListing(tx, oldDirNode, oldParent);
112
112
  if (!oldDirNode.toStats().hasAccess(W_OK, cred)) {
113
- throw ApiError.With('EACCES', oldPath, 'renameSync');
113
+ throw ApiError.With('EACCES', oldPath, 'rename');
114
114
  }
115
115
  if (!oldDirList[oldName]) {
116
- throw ApiError.With('ENOENT', oldPath, 'renameSync');
116
+ throw ApiError.With('ENOENT', oldPath, 'rename');
117
117
  }
118
118
  const ino = oldDirList[oldName];
119
119
  delete oldDirList[oldName];
@@ -151,7 +151,7 @@ export class SyncStoreFS extends Sync(FileSystem) {
151
151
  }
152
152
  else {
153
153
  // If it's a directory, throw a permissions error.
154
- throw ApiError.With('EPERM', newPath, 'renameSync');
154
+ throw ApiError.With('EPERM', newPath, 'rename');
155
155
  }
156
156
  }
157
157
  newDirList[newName] = ino;
@@ -170,7 +170,7 @@ export class SyncStoreFS extends Sync(FileSystem) {
170
170
  // Get the inode to the item, convert it into a Stats object.
171
171
  const stats = this.findINode(this.store.beginTransaction(), p).toStats();
172
172
  if (!stats.hasAccess(R_OK, cred)) {
173
- throw ApiError.With('EACCES', p, 'statSync');
173
+ throw ApiError.With('EACCES', p, 'stat');
174
174
  }
175
175
  return stats;
176
176
  }
@@ -181,10 +181,10 @@ export class SyncStoreFS extends Sync(FileSystem) {
181
181
  openFileSync(p, flag, cred) {
182
182
  const tx = this.store.beginTransaction(), node = this.findINode(tx, p), data = tx.get(node.ino);
183
183
  if (!node.toStats().hasAccess(flagToMode(flag), cred)) {
184
- throw ApiError.With('EACCES', p, 'openFileSync');
184
+ throw ApiError.With('EACCES', p, 'openFile');
185
185
  }
186
186
  if (data === null) {
187
- throw ApiError.With('ENOENT', p, 'openFileSync');
187
+ throw ApiError.With('ENOENT', p, 'openFile');
188
188
  }
189
189
  return new PreloadFile(this, p, flag, node.toStats(), data);
190
190
  }
@@ -194,7 +194,7 @@ export class SyncStoreFS extends Sync(FileSystem) {
194
194
  rmdirSync(p, cred) {
195
195
  // Check first if directory is empty.
196
196
  if (this.readdirSync(p, cred).length > 0) {
197
- throw ApiError.With('ENOTEMPTY', p, 'rmdirSync');
197
+ throw ApiError.With('ENOTEMPTY', p, 'rmdir');
198
198
  }
199
199
  else {
200
200
  this.removeEntry(p, true, cred);
@@ -207,7 +207,7 @@ export class SyncStoreFS extends Sync(FileSystem) {
207
207
  const tx = this.store.beginTransaction();
208
208
  const node = this.findINode(tx, p);
209
209
  if (!node.toStats().hasAccess(R_OK, cred)) {
210
- throw ApiError.With('EACCES', p, 'readdirSync');
210
+ throw ApiError.With('EACCES', p, 'readdir');
211
211
  }
212
212
  return Object.keys(this.getDirListing(tx, node, p));
213
213
  }
@@ -234,16 +234,16 @@ export class SyncStoreFS extends Sync(FileSystem) {
234
234
  linkSync(existing, newpath, cred) {
235
235
  const tx = this.store.beginTransaction(), existingDir = dirname(existing), existingDirNode = this.findINode(tx, existingDir);
236
236
  if (!existingDirNode.toStats().hasAccess(R_OK, cred)) {
237
- throw ApiError.With('EACCES', existingDir, 'linkSync');
237
+ throw ApiError.With('EACCES', existingDir, 'link');
238
238
  }
239
239
  const newDir = dirname(newpath), newDirNode = this.findINode(tx, newDir), newListing = this.getDirListing(tx, newDirNode, newDir);
240
240
  if (!newDirNode.toStats().hasAccess(W_OK, cred)) {
241
- throw ApiError.With('EACCES', newDir, 'linkSync');
241
+ throw ApiError.With('EACCES', newDir, 'link');
242
242
  }
243
243
  const ino = this._findINode(tx, existingDir, basename(existing));
244
244
  const node = this.getINode(tx, ino, existing);
245
245
  if (!node.toStats().hasAccess(W_OK, cred)) {
246
- throw ApiError.With('EACCES', newpath, 'linkSync');
246
+ throw ApiError.With('EACCES', newpath, 'link');
247
247
  }
248
248
  node.nlink++;
249
249
  newListing[basename(newpath)] = ino;