@zenfs/core 0.10.0 → 0.11.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.
- package/dist/backends/Index.d.ts +3 -3
- package/dist/backends/Index.js +4 -4
- package/dist/backends/backend.js +2 -1
- package/dist/backends/{Fetch.d.ts → fetch.d.ts} +4 -4
- package/dist/backends/{Fetch.js → fetch.js} +6 -7
- package/dist/backends/{Locked.d.ts → locked.d.ts} +2 -2
- package/dist/backends/{Locked.js → locked.js} +4 -5
- package/dist/backends/{InMemory.d.ts → memory.d.ts} +7 -9
- package/dist/backends/memory.js +38 -0
- package/dist/backends/{Overlay.d.ts → overlay.d.ts} +12 -13
- package/dist/backends/{Overlay.js → overlay.js} +98 -103
- package/dist/backends/port/fs.d.ts +15 -16
- package/dist/backends/port/fs.js +20 -22
- package/dist/backends/store/fs.d.ts +169 -0
- package/dist/backends/store/fs.js +743 -0
- package/dist/backends/store/simple.d.ts +64 -0
- package/dist/backends/store/simple.js +111 -0
- package/dist/backends/store/store.d.ts +111 -0
- package/dist/backends/store/store.js +62 -0
- package/dist/browser.min.js +4 -4
- package/dist/browser.min.js.map +4 -4
- package/dist/config.d.ts +1 -1
- package/dist/emulation/shared.js +1 -1
- package/dist/error.d.ts +0 -1
- package/dist/error.js +0 -1
- package/dist/file.js +1 -1
- package/dist/filesystem.d.ts +3 -3
- package/dist/filesystem.js +26 -29
- package/dist/index.d.ts +5 -7
- package/dist/index.js +5 -7
- package/dist/inode.d.ts +1 -1
- package/package.json +1 -1
- package/src/backends/Index.ts +4 -4
- package/src/backends/backend.ts +2 -1
- package/src/backends/{Fetch.ts → fetch.ts} +13 -14
- package/src/backends/{Locked.ts → locked.ts} +5 -6
- package/src/backends/memory.ts +44 -0
- package/src/backends/{Overlay.ts → overlay.ts} +99 -105
- package/src/backends/port/fs.ts +24 -26
- package/src/backends/store/fs.ts +881 -0
- package/src/backends/store/readme.md +9 -0
- package/src/backends/store/simple.ts +144 -0
- package/src/backends/store/store.ts +164 -0
- package/src/config.ts +2 -2
- package/src/emulation/shared.ts +1 -1
- package/src/error.ts +0 -1
- package/src/file.ts +1 -1
- package/src/filesystem.ts +29 -32
- package/src/index.ts +5 -7
- package/src/inode.ts +1 -1
- package/dist/backends/AsyncStore.d.ts +0 -204
- package/dist/backends/AsyncStore.js +0 -509
- package/dist/backends/InMemory.js +0 -49
- package/dist/backends/SyncStore.d.ts +0 -213
- package/dist/backends/SyncStore.js +0 -445
- package/dist/backends/port/store.d.ts +0 -30
- package/dist/backends/port/store.js +0 -142
- package/src/backends/AsyncStore.ts +0 -655
- package/src/backends/InMemory.ts +0 -56
- package/src/backends/SyncStore.ts +0 -589
- package/src/backends/port/store.ts +0 -187
|
@@ -2,7 +2,7 @@ import { FileSystem, FileSystemMetadata } from '../filesystem.js';
|
|
|
2
2
|
import { ErrnoError, Errno } from '../error.js';
|
|
3
3
|
import { File, PreloadFile, parseFlag } from '../file.js';
|
|
4
4
|
import { Stats } from '../stats.js';
|
|
5
|
-
import { LockedFS } from './
|
|
5
|
+
import { LockedFS } from './locked.js';
|
|
6
6
|
import { dirname } from '../emulation/path.js';
|
|
7
7
|
import { Cred, rootCred } from '../cred.js';
|
|
8
8
|
import { decode, encode } from '../utils.js';
|
|
@@ -35,11 +35,10 @@ export interface OverlayOptions {
|
|
|
35
35
|
* @internal
|
|
36
36
|
*/
|
|
37
37
|
export class UnlockedOverlayFS extends FileSystem {
|
|
38
|
-
async ready(): Promise<
|
|
38
|
+
async ready(): Promise<void> {
|
|
39
39
|
await this._readable.ready();
|
|
40
40
|
await this._writable.ready();
|
|
41
41
|
await this._ready;
|
|
42
|
-
return this;
|
|
43
42
|
}
|
|
44
43
|
|
|
45
44
|
private _writable: FileSystem;
|
|
@@ -155,30 +154,30 @@ export class UnlockedOverlayFS extends FileSystem {
|
|
|
155
154
|
}
|
|
156
155
|
}
|
|
157
156
|
|
|
158
|
-
public async stat(
|
|
157
|
+
public async stat(path: string, cred: Cred): Promise<Stats> {
|
|
159
158
|
this.checkInitialized();
|
|
160
159
|
try {
|
|
161
|
-
return this._writable.stat(
|
|
160
|
+
return this._writable.stat(path, cred);
|
|
162
161
|
} catch (e) {
|
|
163
|
-
if (this._deletedFiles.has(
|
|
164
|
-
throw ErrnoError.With('ENOENT',
|
|
162
|
+
if (this._deletedFiles.has(path)) {
|
|
163
|
+
throw ErrnoError.With('ENOENT', path, 'stat');
|
|
165
164
|
}
|
|
166
|
-
const oldStat = new Stats(await this._readable.stat(
|
|
165
|
+
const oldStat = new Stats(await this._readable.stat(path, cred));
|
|
167
166
|
// Make the oldStat's mode writable. Preserve the topmost part of the mode, which specifies the type
|
|
168
167
|
oldStat.mode |= 0o222;
|
|
169
168
|
return oldStat;
|
|
170
169
|
}
|
|
171
170
|
}
|
|
172
171
|
|
|
173
|
-
public statSync(
|
|
172
|
+
public statSync(path: string, cred: Cred): Stats {
|
|
174
173
|
this.checkInitialized();
|
|
175
174
|
try {
|
|
176
|
-
return this._writable.statSync(
|
|
175
|
+
return this._writable.statSync(path, cred);
|
|
177
176
|
} catch (e) {
|
|
178
|
-
if (this._deletedFiles.has(
|
|
179
|
-
throw ErrnoError.With('ENOENT',
|
|
177
|
+
if (this._deletedFiles.has(path)) {
|
|
178
|
+
throw ErrnoError.With('ENOENT', path, 'stat');
|
|
180
179
|
}
|
|
181
|
-
const oldStat = new Stats(this._readable.statSync(
|
|
180
|
+
const oldStat = new Stats(this._readable.statSync(path, cred));
|
|
182
181
|
// Make the oldStat's mode writable. Preserve the topmost part of the mode, which specifies the type.
|
|
183
182
|
oldStat.mode |= 0o222;
|
|
184
183
|
return oldStat;
|
|
@@ -230,153 +229,153 @@ export class UnlockedOverlayFS extends FileSystem {
|
|
|
230
229
|
this._writable.linkSync(srcpath, dstpath, cred);
|
|
231
230
|
}
|
|
232
231
|
|
|
233
|
-
public async unlink(
|
|
232
|
+
public async unlink(path: string, cred: Cred): Promise<void> {
|
|
234
233
|
this.checkInitialized();
|
|
235
|
-
this.checkPath(
|
|
236
|
-
if (!(await this.exists(
|
|
237
|
-
throw ErrnoError.With('ENOENT',
|
|
234
|
+
this.checkPath(path);
|
|
235
|
+
if (!(await this.exists(path, cred))) {
|
|
236
|
+
throw ErrnoError.With('ENOENT', path, 'unlink');
|
|
238
237
|
}
|
|
239
238
|
|
|
240
|
-
if (await this._writable.exists(
|
|
241
|
-
await this._writable.unlink(
|
|
239
|
+
if (await this._writable.exists(path, cred)) {
|
|
240
|
+
await this._writable.unlink(path, cred);
|
|
242
241
|
}
|
|
243
242
|
|
|
244
243
|
// if it still exists add to the delete log
|
|
245
|
-
if (await this.exists(
|
|
246
|
-
this.deletePath(
|
|
244
|
+
if (await this.exists(path, cred)) {
|
|
245
|
+
this.deletePath(path, cred);
|
|
247
246
|
}
|
|
248
247
|
}
|
|
249
248
|
|
|
250
|
-
public unlinkSync(
|
|
249
|
+
public unlinkSync(path: string, cred: Cred): void {
|
|
251
250
|
this.checkInitialized();
|
|
252
|
-
this.checkPath(
|
|
253
|
-
if (!this.existsSync(
|
|
254
|
-
throw ErrnoError.With('ENOENT',
|
|
251
|
+
this.checkPath(path);
|
|
252
|
+
if (!this.existsSync(path, cred)) {
|
|
253
|
+
throw ErrnoError.With('ENOENT', path, 'unlink');
|
|
255
254
|
}
|
|
256
255
|
|
|
257
|
-
if (this._writable.existsSync(
|
|
258
|
-
this._writable.unlinkSync(
|
|
256
|
+
if (this._writable.existsSync(path, cred)) {
|
|
257
|
+
this._writable.unlinkSync(path, cred);
|
|
259
258
|
}
|
|
260
259
|
|
|
261
260
|
// if it still exists add to the delete log
|
|
262
|
-
if (this.existsSync(
|
|
263
|
-
this.deletePath(
|
|
261
|
+
if (this.existsSync(path, cred)) {
|
|
262
|
+
this.deletePath(path, cred);
|
|
264
263
|
}
|
|
265
264
|
}
|
|
266
265
|
|
|
267
|
-
public async rmdir(
|
|
266
|
+
public async rmdir(path: string, cred: Cred): Promise<void> {
|
|
268
267
|
this.checkInitialized();
|
|
269
|
-
if (!(await this.exists(
|
|
270
|
-
throw ErrnoError.With('ENOENT',
|
|
268
|
+
if (!(await this.exists(path, cred))) {
|
|
269
|
+
throw ErrnoError.With('ENOENT', path, 'rmdir');
|
|
271
270
|
}
|
|
272
|
-
if (await this._writable.exists(
|
|
273
|
-
await this._writable.rmdir(
|
|
271
|
+
if (await this._writable.exists(path, cred)) {
|
|
272
|
+
await this._writable.rmdir(path, cred);
|
|
274
273
|
}
|
|
275
|
-
if (await this.exists(
|
|
274
|
+
if (await this.exists(path, cred)) {
|
|
276
275
|
// Check if directory is empty.
|
|
277
|
-
if ((await this.readdir(
|
|
278
|
-
throw ErrnoError.With('ENOTEMPTY',
|
|
276
|
+
if ((await this.readdir(path, cred)).length > 0) {
|
|
277
|
+
throw ErrnoError.With('ENOTEMPTY', path, 'rmdir');
|
|
279
278
|
} else {
|
|
280
|
-
this.deletePath(
|
|
279
|
+
this.deletePath(path, cred);
|
|
281
280
|
}
|
|
282
281
|
}
|
|
283
282
|
}
|
|
284
283
|
|
|
285
|
-
public rmdirSync(
|
|
284
|
+
public rmdirSync(path: string, cred: Cred): void {
|
|
286
285
|
this.checkInitialized();
|
|
287
|
-
if (!this.existsSync(
|
|
288
|
-
throw ErrnoError.With('ENOENT',
|
|
286
|
+
if (!this.existsSync(path, cred)) {
|
|
287
|
+
throw ErrnoError.With('ENOENT', path, 'rmdir');
|
|
289
288
|
}
|
|
290
|
-
if (this._writable.existsSync(
|
|
291
|
-
this._writable.rmdirSync(
|
|
289
|
+
if (this._writable.existsSync(path, cred)) {
|
|
290
|
+
this._writable.rmdirSync(path, cred);
|
|
292
291
|
}
|
|
293
|
-
if (this.existsSync(
|
|
292
|
+
if (this.existsSync(path, cred)) {
|
|
294
293
|
// Check if directory is empty.
|
|
295
|
-
if (this.readdirSync(
|
|
296
|
-
throw ErrnoError.With('ENOTEMPTY',
|
|
294
|
+
if (this.readdirSync(path, cred).length > 0) {
|
|
295
|
+
throw ErrnoError.With('ENOTEMPTY', path, 'rmdir');
|
|
297
296
|
} else {
|
|
298
|
-
this.deletePath(
|
|
297
|
+
this.deletePath(path, cred);
|
|
299
298
|
}
|
|
300
299
|
}
|
|
301
300
|
}
|
|
302
301
|
|
|
303
|
-
public async mkdir(
|
|
302
|
+
public async mkdir(path: string, mode: number, cred: Cred): Promise<void> {
|
|
304
303
|
this.checkInitialized();
|
|
305
|
-
if (await this.exists(
|
|
306
|
-
throw ErrnoError.With('EEXIST',
|
|
304
|
+
if (await this.exists(path, cred)) {
|
|
305
|
+
throw ErrnoError.With('EEXIST', path, 'mkdir');
|
|
307
306
|
}
|
|
308
307
|
// The below will throw should any of the parent directories fail to exist on _writable.
|
|
309
|
-
await this.createParentDirectories(
|
|
310
|
-
await this._writable.mkdir(
|
|
308
|
+
await this.createParentDirectories(path, cred);
|
|
309
|
+
await this._writable.mkdir(path, mode, cred);
|
|
311
310
|
}
|
|
312
311
|
|
|
313
|
-
public mkdirSync(
|
|
312
|
+
public mkdirSync(path: string, mode: number, cred: Cred): void {
|
|
314
313
|
this.checkInitialized();
|
|
315
|
-
if (this.existsSync(
|
|
316
|
-
throw ErrnoError.With('EEXIST',
|
|
314
|
+
if (this.existsSync(path, cred)) {
|
|
315
|
+
throw ErrnoError.With('EEXIST', path, 'mkdir');
|
|
317
316
|
}
|
|
318
317
|
// The below will throw should any of the parent directories fail to exist on _writable.
|
|
319
|
-
this.createParentDirectoriesSync(
|
|
320
|
-
this._writable.mkdirSync(
|
|
318
|
+
this.createParentDirectoriesSync(path, cred);
|
|
319
|
+
this._writable.mkdirSync(path, mode, cred);
|
|
321
320
|
}
|
|
322
321
|
|
|
323
|
-
public async readdir(
|
|
322
|
+
public async readdir(path: string, cred: Cred): Promise<string[]> {
|
|
324
323
|
this.checkInitialized();
|
|
325
|
-
const dirStats = await this.stat(
|
|
324
|
+
const dirStats = await this.stat(path, cred);
|
|
326
325
|
if (!dirStats.isDirectory()) {
|
|
327
|
-
throw ErrnoError.With('ENOTDIR',
|
|
326
|
+
throw ErrnoError.With('ENOTDIR', path, 'readdir');
|
|
328
327
|
}
|
|
329
328
|
|
|
330
329
|
// Readdir in both, check delete log on RO file system's listing, merge, return.
|
|
331
330
|
const contents: string[] = [];
|
|
332
331
|
try {
|
|
333
|
-
contents.push(...(await this._writable.readdir(
|
|
332
|
+
contents.push(...(await this._writable.readdir(path, cred)));
|
|
334
333
|
} catch (e) {
|
|
335
334
|
// NOP.
|
|
336
335
|
}
|
|
337
336
|
try {
|
|
338
|
-
contents.push(...(await this._readable.readdir(
|
|
337
|
+
contents.push(...(await this._readable.readdir(path, cred)).filter((fPath: string) => !this._deletedFiles.has(`${path}/${fPath}`)));
|
|
339
338
|
} catch (e) {
|
|
340
339
|
// NOP.
|
|
341
340
|
}
|
|
342
341
|
const seenMap: { [name: string]: boolean } = {};
|
|
343
|
-
return contents.filter((
|
|
344
|
-
const result = !seenMap[
|
|
345
|
-
seenMap[
|
|
342
|
+
return contents.filter((path: string) => {
|
|
343
|
+
const result = !seenMap[path];
|
|
344
|
+
seenMap[path] = true;
|
|
346
345
|
return result;
|
|
347
346
|
});
|
|
348
347
|
}
|
|
349
348
|
|
|
350
|
-
public readdirSync(
|
|
349
|
+
public readdirSync(path: string, cred: Cred): string[] {
|
|
351
350
|
this.checkInitialized();
|
|
352
|
-
const dirStats = this.statSync(
|
|
351
|
+
const dirStats = this.statSync(path, cred);
|
|
353
352
|
if (!dirStats.isDirectory()) {
|
|
354
|
-
throw ErrnoError.With('ENOTDIR',
|
|
353
|
+
throw ErrnoError.With('ENOTDIR', path, 'readdir');
|
|
355
354
|
}
|
|
356
355
|
|
|
357
356
|
// Readdir in both, check delete log on RO file system's listing, merge, return.
|
|
358
357
|
let contents: string[] = [];
|
|
359
358
|
try {
|
|
360
|
-
contents = contents.concat(this._writable.readdirSync(
|
|
359
|
+
contents = contents.concat(this._writable.readdirSync(path, cred));
|
|
361
360
|
} catch (e) {
|
|
362
361
|
// NOP.
|
|
363
362
|
}
|
|
364
363
|
try {
|
|
365
|
-
contents = contents.concat(this._readable.readdirSync(
|
|
364
|
+
contents = contents.concat(this._readable.readdirSync(path, cred).filter((fPath: string) => !this._deletedFiles.has(`${path}/${fPath}`)));
|
|
366
365
|
} catch (e) {
|
|
367
366
|
// NOP.
|
|
368
367
|
}
|
|
369
368
|
const seenMap: { [name: string]: boolean } = {};
|
|
370
|
-
return contents.filter((
|
|
371
|
-
const result = !seenMap[
|
|
372
|
-
seenMap[
|
|
369
|
+
return contents.filter((path: string) => {
|
|
370
|
+
const result = !seenMap[path];
|
|
371
|
+
seenMap[path] = true;
|
|
373
372
|
return result;
|
|
374
373
|
});
|
|
375
374
|
}
|
|
376
375
|
|
|
377
|
-
private deletePath(
|
|
378
|
-
this._deletedFiles.add(
|
|
379
|
-
this.updateLog(`d${
|
|
376
|
+
private deletePath(path: string, cred: Cred): void {
|
|
377
|
+
this._deletedFiles.add(path);
|
|
378
|
+
this.updateLog(`d${path}\n`, cred);
|
|
380
379
|
}
|
|
381
380
|
|
|
382
381
|
private async updateLog(addition: string, cred: Cred) {
|
|
@@ -437,8 +436,8 @@ export class UnlockedOverlayFS extends FileSystem {
|
|
|
437
436
|
* With the given path, create the needed parent directories on the writable storage
|
|
438
437
|
* should they not exist. Use modes from the read-only storage.
|
|
439
438
|
*/
|
|
440
|
-
private createParentDirectoriesSync(
|
|
441
|
-
let parent = dirname(
|
|
439
|
+
private createParentDirectoriesSync(path: string, cred: Cred): void {
|
|
440
|
+
let parent = dirname(path),
|
|
442
441
|
toCreate: string[] = [];
|
|
443
442
|
while (!this._writable.existsSync(parent, cred)) {
|
|
444
443
|
toCreate.push(parent);
|
|
@@ -451,8 +450,8 @@ export class UnlockedOverlayFS extends FileSystem {
|
|
|
451
450
|
}
|
|
452
451
|
}
|
|
453
452
|
|
|
454
|
-
private async createParentDirectories(
|
|
455
|
-
let parent = dirname(
|
|
453
|
+
private async createParentDirectories(path: string, cred: Cred): Promise<void> {
|
|
454
|
+
let parent = dirname(path),
|
|
456
455
|
toCreate: string[] = [];
|
|
457
456
|
while (!(await this._writable.exists(parent, cred))) {
|
|
458
457
|
toCreate.push(parent);
|
|
@@ -471,24 +470,24 @@ export class UnlockedOverlayFS extends FileSystem {
|
|
|
471
470
|
* - Ensures p is on writable before proceeding. Throws an error if it doesn't exist.
|
|
472
471
|
* - Calls f to perform operation on writable.
|
|
473
472
|
*/
|
|
474
|
-
private operateOnWritable(
|
|
475
|
-
if (!this.existsSync(
|
|
476
|
-
throw ErrnoError.With('ENOENT',
|
|
473
|
+
private operateOnWritable(path: string, cred: Cred): void {
|
|
474
|
+
if (!this.existsSync(path, cred)) {
|
|
475
|
+
throw ErrnoError.With('ENOENT', path, 'operateOnWriteable');
|
|
477
476
|
}
|
|
478
|
-
if (!this._writable.existsSync(
|
|
477
|
+
if (!this._writable.existsSync(path, cred)) {
|
|
479
478
|
// File is on readable storage. Copy to writable storage before
|
|
480
479
|
// changing its mode.
|
|
481
|
-
this.copyToWritableSync(
|
|
480
|
+
this.copyToWritableSync(path, cred);
|
|
482
481
|
}
|
|
483
482
|
}
|
|
484
483
|
|
|
485
|
-
private async operateOnWritableAsync(
|
|
486
|
-
if (!(await this.exists(
|
|
487
|
-
throw ErrnoError.With('ENOENT',
|
|
484
|
+
private async operateOnWritableAsync(path: string, cred: Cred): Promise<void> {
|
|
485
|
+
if (!(await this.exists(path, cred))) {
|
|
486
|
+
throw ErrnoError.With('ENOENT', path, 'operateOnWritable');
|
|
488
487
|
}
|
|
489
488
|
|
|
490
|
-
if (!(await this._writable.exists(
|
|
491
|
-
return this.copyToWritable(
|
|
489
|
+
if (!(await this._writable.exists(path, cred))) {
|
|
490
|
+
return this.copyToWritable(path, cred);
|
|
492
491
|
}
|
|
493
492
|
}
|
|
494
493
|
|
|
@@ -496,34 +495,34 @@ export class UnlockedOverlayFS extends FileSystem {
|
|
|
496
495
|
* Copy from readable to writable storage.
|
|
497
496
|
* PRECONDITION: File does not exist on writable storage.
|
|
498
497
|
*/
|
|
499
|
-
private copyToWritableSync(
|
|
500
|
-
const stats = this.statSync(
|
|
498
|
+
private copyToWritableSync(path: string, cred: Cred): void {
|
|
499
|
+
const stats = this.statSync(path, cred);
|
|
501
500
|
if (stats.isDirectory()) {
|
|
502
|
-
this._writable.mkdirSync(
|
|
501
|
+
this._writable.mkdirSync(path, stats.mode, cred);
|
|
503
502
|
return;
|
|
504
503
|
}
|
|
505
504
|
|
|
506
505
|
const data = new Uint8Array(stats.size);
|
|
507
|
-
const readable = this._readable.openFileSync(
|
|
506
|
+
const readable = this._readable.openFileSync(path, parseFlag('r'), cred);
|
|
508
507
|
readable.readSync(data);
|
|
509
508
|
readable.closeSync();
|
|
510
|
-
const writable = this._writable.openFileSync(
|
|
509
|
+
const writable = this._writable.openFileSync(path, parseFlag('w'), cred);
|
|
511
510
|
writable.writeSync(data);
|
|
512
511
|
writable.closeSync();
|
|
513
512
|
}
|
|
514
513
|
|
|
515
|
-
private async copyToWritable(
|
|
516
|
-
const stats = await this.stat(
|
|
514
|
+
private async copyToWritable(path: string, cred: Cred): Promise<void> {
|
|
515
|
+
const stats = await this.stat(path, cred);
|
|
517
516
|
if (stats.isDirectory()) {
|
|
518
|
-
await this._writable.mkdir(
|
|
517
|
+
await this._writable.mkdir(path, stats.mode, cred);
|
|
519
518
|
return;
|
|
520
519
|
}
|
|
521
520
|
|
|
522
521
|
const data = new Uint8Array(stats.size);
|
|
523
|
-
const readable = await this._readable.openFile(
|
|
522
|
+
const readable = await this._readable.openFile(path, parseFlag('r'), cred);
|
|
524
523
|
await readable.read(data);
|
|
525
524
|
await readable.close();
|
|
526
|
-
const writable = await this._writable.openFile(
|
|
525
|
+
const writable = await this._writable.openFile(path, parseFlag('w'), cred);
|
|
527
526
|
await writable.write(data);
|
|
528
527
|
await writable.close();
|
|
529
528
|
}
|
|
@@ -536,11 +535,6 @@ export class UnlockedOverlayFS extends FileSystem {
|
|
|
536
535
|
* @internal
|
|
537
536
|
*/
|
|
538
537
|
export class OverlayFS extends LockedFS<UnlockedOverlayFS> {
|
|
539
|
-
public async ready() {
|
|
540
|
-
await super.ready();
|
|
541
|
-
return this;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
538
|
/**
|
|
545
539
|
* @param options The options to initialize the OverlayFS with
|
|
546
540
|
*/
|
package/src/backends/port/fs.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import {
|
|
2
|
+
import type { FileReadResult } from 'node:fs/promises';
|
|
3
|
+
import type { ExtractProperties } from 'utilium';
|
|
3
4
|
import type { Cred } from '../../cred.js';
|
|
4
|
-
import {
|
|
5
|
+
import { Errno, ErrnoError } from '../../error.js';
|
|
5
6
|
import { File } from '../../file.js';
|
|
7
|
+
import { Async, FileSystem, type FileSystemMetadata } from '../../filesystem.js';
|
|
6
8
|
import { Stats, type FileType } from '../../stats.js';
|
|
7
|
-
import { InMemory } from '../
|
|
8
|
-
import type { SyncStoreFS } from '../SyncStore.js';
|
|
9
|
+
import { InMemory } from '../memory.js';
|
|
9
10
|
import type { Backend } from '../backend.js';
|
|
10
11
|
import * as RPC from './rpc.js';
|
|
11
|
-
import type { ExtractProperties } from 'utilium';
|
|
12
|
-
import type { FileReadResult } from 'node:fs/promises';
|
|
13
12
|
|
|
14
13
|
type FileMethods = ExtractProperties<File, (...args: any[]) => Promise<any>>;
|
|
15
14
|
type FileMethod = keyof FileMethods;
|
|
@@ -136,7 +135,7 @@ export class PortFS extends Async(FileSystem) {
|
|
|
136
135
|
/**
|
|
137
136
|
* @hidden
|
|
138
137
|
*/
|
|
139
|
-
_sync
|
|
138
|
+
_sync = InMemory.create({ name: 'port-tmpfs' });
|
|
140
139
|
|
|
141
140
|
/**
|
|
142
141
|
* Constructs a new PortFS instance that connects with ZenFS running on
|
|
@@ -166,43 +165,42 @@ export class PortFS extends Async(FileSystem) {
|
|
|
166
165
|
);
|
|
167
166
|
}
|
|
168
167
|
|
|
169
|
-
public async ready(): Promise<
|
|
168
|
+
public async ready(): Promise<void> {
|
|
170
169
|
await this.rpc('ready');
|
|
171
170
|
await super.ready();
|
|
172
|
-
return this;
|
|
173
171
|
}
|
|
174
172
|
|
|
175
173
|
public rename(oldPath: string, newPath: string, cred: Cred): Promise<void> {
|
|
176
174
|
return this.rpc('rename', oldPath, newPath, cred);
|
|
177
175
|
}
|
|
178
176
|
|
|
179
|
-
public async stat(
|
|
180
|
-
return new Stats(await this.rpc('stat',
|
|
177
|
+
public async stat(path: string, cred: Cred): Promise<Stats> {
|
|
178
|
+
return new Stats(await this.rpc('stat', path, cred));
|
|
181
179
|
}
|
|
182
180
|
|
|
183
181
|
public sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void> {
|
|
184
182
|
return this.rpc('sync', path, data, stats);
|
|
185
183
|
}
|
|
186
|
-
public openFile(
|
|
187
|
-
return this.rpc('openFile',
|
|
184
|
+
public openFile(path: string, flag: string, cred: Cred): Promise<File> {
|
|
185
|
+
return this.rpc('openFile', path, flag, cred);
|
|
188
186
|
}
|
|
189
|
-
public createFile(
|
|
190
|
-
return this.rpc('createFile',
|
|
187
|
+
public createFile(path: string, flag: string, mode: number, cred: Cred): Promise<File> {
|
|
188
|
+
return this.rpc('createFile', path, flag, mode, cred);
|
|
191
189
|
}
|
|
192
|
-
public unlink(
|
|
193
|
-
return this.rpc('unlink',
|
|
190
|
+
public unlink(path: string, cred: Cred): Promise<void> {
|
|
191
|
+
return this.rpc('unlink', path, cred);
|
|
194
192
|
}
|
|
195
|
-
public rmdir(
|
|
196
|
-
return this.rpc('rmdir',
|
|
193
|
+
public rmdir(path: string, cred: Cred): Promise<void> {
|
|
194
|
+
return this.rpc('rmdir', path, cred);
|
|
197
195
|
}
|
|
198
|
-
public mkdir(
|
|
199
|
-
return this.rpc('mkdir',
|
|
196
|
+
public mkdir(path: string, mode: number, cred: Cred): Promise<void> {
|
|
197
|
+
return this.rpc('mkdir', path, mode, cred);
|
|
200
198
|
}
|
|
201
|
-
public readdir(
|
|
202
|
-
return this.rpc('readdir',
|
|
199
|
+
public readdir(path: string, cred: Cred): Promise<string[]> {
|
|
200
|
+
return this.rpc('readdir', path, cred);
|
|
203
201
|
}
|
|
204
|
-
public exists(
|
|
205
|
-
return this.rpc('exists',
|
|
202
|
+
public exists(path: string, cred: Cred): Promise<boolean> {
|
|
203
|
+
return this.rpc('exists', path, cred);
|
|
206
204
|
}
|
|
207
205
|
public link(srcpath: string, dstpath: string, cred: Cred): Promise<void> {
|
|
208
206
|
return this.rpc('link', srcpath, dstpath, cred);
|
|
@@ -298,7 +296,7 @@ export const Port = {
|
|
|
298
296
|
},
|
|
299
297
|
},
|
|
300
298
|
|
|
301
|
-
async isAvailable(
|
|
299
|
+
async isAvailable(): Promise<boolean> {
|
|
302
300
|
return true;
|
|
303
301
|
},
|
|
304
302
|
|