@zenfs/core 1.0.10 → 1.0.11
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/backend.d.ts +4 -8
- package/dist/backends/backend.js +7 -11
- package/dist/backends/fetch.d.ts +2 -4
- package/dist/backends/fetch.js +1 -3
- package/dist/backends/memory.d.ts +1 -1
- package/dist/backends/overlay.d.ts +7 -3
- package/dist/backends/overlay.js +10 -6
- package/dist/backends/port/fs.d.ts +12 -17
- package/dist/backends/port/fs.js +5 -8
- package/dist/backends/port/rpc.d.ts +1 -1
- package/dist/backends/store/fs.d.ts +8 -10
- package/dist/backends/store/fs.js +30 -49
- package/dist/backends/store/simple.d.ts +1 -1
- package/dist/backends/store/simple.js +1 -1
- package/dist/backends/store/store.d.ts +7 -13
- package/dist/config.d.ts +5 -5
- package/dist/config.js +26 -26
- package/dist/emulation/async.d.ts +21 -176
- package/dist/emulation/async.js +17 -111
- package/dist/emulation/dir.d.ts +0 -1
- package/dist/emulation/path.d.ts +0 -4
- package/dist/emulation/path.js +4 -8
- package/dist/emulation/promises.d.ts +31 -121
- package/dist/emulation/promises.js +30 -97
- package/dist/emulation/shared.d.ts +7 -3
- package/dist/emulation/shared.js +8 -5
- package/dist/emulation/streams.d.ts +0 -3
- package/dist/emulation/sync.d.ts +25 -178
- package/dist/emulation/sync.js +36 -129
- package/dist/emulation/watchers.d.ts +0 -4
- package/dist/error.d.ts +11 -11
- package/dist/error.js +8 -10
- package/dist/file.d.ts +50 -171
- package/dist/file.js +33 -115
- package/dist/filesystem.d.ts +10 -62
- package/dist/filesystem.js +5 -6
- package/dist/mixins/async.d.ts +4 -6
- package/dist/mixins/async.js +3 -1
- package/dist/mixins/mutexed.d.ts +4 -4
- package/dist/mixins/mutexed.js +7 -5
- package/dist/mixins/readonly.js +14 -15
- package/dist/mixins/shared.d.ts +5 -5
- package/dist/mixins/sync.d.ts +2 -2
- package/dist/stats.d.ts +21 -37
- package/dist/stats.js +9 -21
- package/dist/utils.d.ts +1 -3
- package/package.json +4 -4
- package/src/backends/backend.ts +7 -11
- package/src/backends/fetch.ts +2 -4
- package/src/backends/memory.ts +1 -1
- package/src/backends/overlay.ts +8 -6
- package/src/backends/port/fs.ts +11 -14
- package/src/backends/port/rpc.ts +1 -0
- package/src/backends/store/fs.ts +30 -46
- package/src/backends/store/simple.ts +1 -1
- package/src/backends/store/store.ts +7 -13
- package/src/config.ts +26 -26
- package/src/emulation/async.ts +28 -178
- package/src/emulation/path.ts +4 -11
- package/src/emulation/promises.ts +34 -116
- package/src/emulation/shared.ts +8 -6
- package/src/emulation/sync.ts +41 -185
- package/src/error.ts +7 -11
- package/src/file.ts +47 -180
- package/src/filesystem.ts +14 -65
- package/src/mixins/async.ts +4 -6
- package/src/mixins/mutexed.ts +4 -4
- package/src/mixins/readonly.ts +15 -15
- package/src/mixins/shared.ts +5 -5
- package/src/mixins/sync.ts +3 -3
- package/src/stats.ts +21 -38
|
@@ -72,15 +72,13 @@ export type OptionsOf<T extends Backend> = T extends Backend<FileSystem, infer T
|
|
|
72
72
|
* @internal
|
|
73
73
|
*/
|
|
74
74
|
export type FilesystemOf<T extends Backend> = T extends Backend<infer FS> ? FS : never;
|
|
75
|
-
/**
|
|
76
|
-
* @internal
|
|
77
|
-
*/
|
|
75
|
+
/** @internal */
|
|
78
76
|
export declare function isBackend(arg: unknown): arg is Backend;
|
|
79
77
|
/**
|
|
80
|
-
* Checks that
|
|
78
|
+
* Checks that `options` object is valid for the file system options.
|
|
81
79
|
* @internal
|
|
82
80
|
*/
|
|
83
|
-
export declare function checkOptions<T extends Backend>(backend: T,
|
|
81
|
+
export declare function checkOptions<T extends Backend>(backend: T, options: Record<string, unknown>): Promise<void>;
|
|
84
82
|
/**
|
|
85
83
|
* Specifies a file system backend type and its options.
|
|
86
84
|
*
|
|
@@ -91,8 +89,6 @@ export declare function checkOptions<T extends Backend>(backend: T, opts: Record
|
|
|
91
89
|
export type BackendConfiguration<T extends Backend> = OptionsOf<T> & Partial<SharedConfig> & {
|
|
92
90
|
backend: T;
|
|
93
91
|
};
|
|
94
|
-
/**
|
|
95
|
-
* @internal
|
|
96
|
-
*/
|
|
92
|
+
/** @internal */
|
|
97
93
|
export declare function isBackendConfig<T extends Backend>(arg: unknown): arg is BackendConfiguration<T>;
|
|
98
94
|
export {};
|
package/dist/backends/backend.js
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import { ErrnoError, Errno } from '../error.js';
|
|
2
2
|
import { levenshtein } from '../utils.js';
|
|
3
|
-
/**
|
|
4
|
-
* @internal
|
|
5
|
-
*/
|
|
3
|
+
/** @internal */
|
|
6
4
|
export function isBackend(arg) {
|
|
7
5
|
return arg != null && typeof arg == 'object' && 'isAvailable' in arg && typeof arg.isAvailable == 'function' && 'create' in arg && typeof arg.create == 'function';
|
|
8
6
|
}
|
|
9
7
|
/**
|
|
10
|
-
* Checks that
|
|
8
|
+
* Checks that `options` object is valid for the file system options.
|
|
11
9
|
* @internal
|
|
12
10
|
*/
|
|
13
|
-
export async function checkOptions(backend,
|
|
14
|
-
if (typeof
|
|
11
|
+
export async function checkOptions(backend, options) {
|
|
12
|
+
if (typeof options != 'object' || options === null) {
|
|
15
13
|
throw new ErrnoError(Errno.EINVAL, 'Invalid options');
|
|
16
14
|
}
|
|
17
15
|
// Check for required options.
|
|
18
16
|
for (const [optName, opt] of Object.entries(backend.options)) {
|
|
19
|
-
const providedValue =
|
|
17
|
+
const providedValue = options?.[optName];
|
|
20
18
|
if (providedValue === undefined || providedValue === null) {
|
|
21
19
|
if (!opt.required) {
|
|
22
20
|
continue;
|
|
@@ -24,7 +22,7 @@ export async function checkOptions(backend, opts) {
|
|
|
24
22
|
/* Required option not provided.
|
|
25
23
|
if any incorrect options provided, which ones are close to the provided one?
|
|
26
24
|
(edit distance 5 === close)*/
|
|
27
|
-
const incorrectOptions = Object.keys(
|
|
25
|
+
const incorrectOptions = Object.keys(options)
|
|
28
26
|
.filter(o => !(o in backend.options))
|
|
29
27
|
.map((a) => {
|
|
30
28
|
return { str: a, distance: levenshtein(optName, a) };
|
|
@@ -44,9 +42,7 @@ export async function checkOptions(backend, opts) {
|
|
|
44
42
|
// Otherwise: All good!
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
|
-
/**
|
|
48
|
-
* @internal
|
|
49
|
-
*/
|
|
45
|
+
/** @internal */
|
|
50
46
|
export function isBackendConfig(arg) {
|
|
51
47
|
return arg != null && typeof arg == 'object' && 'backend' in arg && isBackend(arg.backend);
|
|
52
48
|
}
|
package/dist/backends/fetch.d.ts
CHANGED
|
@@ -41,9 +41,7 @@ export declare class FetchFS extends IndexFS {
|
|
|
41
41
|
constructor({ index, baseUrl }: FetchOptions);
|
|
42
42
|
metadata(): FileSystemMetadata;
|
|
43
43
|
/**
|
|
44
|
-
* Preload the
|
|
45
|
-
* @param path
|
|
46
|
-
* @param buffer
|
|
44
|
+
* Preload the `path` into the index.
|
|
47
45
|
*/
|
|
48
46
|
preload(path: string, buffer: Uint8Array): void;
|
|
49
47
|
/**
|
|
@@ -70,7 +68,7 @@ declare const _Fetch: {
|
|
|
70
68
|
readonly create: (options: FetchOptions) => FetchFS;
|
|
71
69
|
};
|
|
72
70
|
type _Fetch = typeof _Fetch;
|
|
73
|
-
interface Fetch extends _Fetch {
|
|
71
|
+
export interface Fetch extends _Fetch {
|
|
74
72
|
}
|
|
75
73
|
export declare const Fetch: Fetch;
|
|
76
74
|
export {};
|
package/dist/backends/fetch.js
CHANGED
|
@@ -69,10 +69,14 @@ export declare class UnmutexedOverlayFS extends FileSystem {
|
|
|
69
69
|
private checkInitialized;
|
|
70
70
|
private checkPath;
|
|
71
71
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
72
|
+
* Create the needed parent directories on the writable storage should they not exist.
|
|
73
|
+
* Use modes from the read-only storage.
|
|
74
74
|
*/
|
|
75
75
|
private createParentDirectoriesSync;
|
|
76
|
+
/**
|
|
77
|
+
* Create the needed parent directories on the writable storage should they not exist.
|
|
78
|
+
* Use modes from the read-only storage.
|
|
79
|
+
*/
|
|
76
80
|
private createParentDirectories;
|
|
77
81
|
/**
|
|
78
82
|
* Helper function:
|
|
@@ -117,7 +121,7 @@ declare const _Overlay: {
|
|
|
117
121
|
readonly create: (options: OverlayOptions) => OverlayFS;
|
|
118
122
|
};
|
|
119
123
|
type _Overlay = typeof _Overlay;
|
|
120
|
-
interface Overlay extends _Overlay {
|
|
124
|
+
export interface Overlay extends _Overlay {
|
|
121
125
|
}
|
|
122
126
|
export declare const Overlay: Overlay;
|
|
123
127
|
export {};
|
package/dist/backends/overlay.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
2
|
if (value !== null && value !== void 0) {
|
|
3
3
|
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
-
var dispose;
|
|
4
|
+
var dispose, inner;
|
|
5
5
|
if (async) {
|
|
6
6
|
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
7
|
dispose = value[Symbol.asyncDispose];
|
|
@@ -9,8 +9,10 @@ var __addDisposableResource = (this && this.__addDisposableResource) || function
|
|
|
9
9
|
if (dispose === void 0) {
|
|
10
10
|
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
11
|
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
12
13
|
}
|
|
13
14
|
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
14
16
|
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
15
17
|
}
|
|
16
18
|
else if (async) {
|
|
@@ -50,9 +52,7 @@ import { FileSystem } from '../filesystem.js';
|
|
|
50
52
|
import { Mutexed } from '../mixins/mutexed.js';
|
|
51
53
|
import { Stats } from '../stats.js';
|
|
52
54
|
import { decode, encode } from '../utils.js';
|
|
53
|
-
/**
|
|
54
|
-
* @internal
|
|
55
|
-
*/
|
|
55
|
+
/** @internal */
|
|
56
56
|
const deletionLogPath = '/.deleted';
|
|
57
57
|
/**
|
|
58
58
|
* OverlayFS makes a read-only filesystem writable by storing writes on a second, writable file system.
|
|
@@ -419,8 +419,8 @@ export class UnmutexedOverlayFS extends FileSystem {
|
|
|
419
419
|
}
|
|
420
420
|
}
|
|
421
421
|
/**
|
|
422
|
-
*
|
|
423
|
-
*
|
|
422
|
+
* Create the needed parent directories on the writable storage should they not exist.
|
|
423
|
+
* Use modes from the read-only storage.
|
|
424
424
|
*/
|
|
425
425
|
createParentDirectoriesSync(path) {
|
|
426
426
|
let parent = dirname(path);
|
|
@@ -433,6 +433,10 @@ export class UnmutexedOverlayFS extends FileSystem {
|
|
|
433
433
|
this.writable.mkdirSync(path, this.statSync(path).mode);
|
|
434
434
|
}
|
|
435
435
|
}
|
|
436
|
+
/**
|
|
437
|
+
* Create the needed parent directories on the writable storage should they not exist.
|
|
438
|
+
* Use modes from the read-only storage.
|
|
439
|
+
*/
|
|
436
440
|
async createParentDirectories(path) {
|
|
437
441
|
let parent = dirname(path);
|
|
438
442
|
const toCreate = [];
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
1
|
import type { FileReadResult } from 'node:fs/promises';
|
|
4
2
|
import type { ExtractProperties } from 'utilium';
|
|
5
3
|
import { type MountConfiguration } from '../../config.js';
|
|
@@ -10,7 +8,8 @@ import type { Backend, FilesystemOf } from '../backend.js';
|
|
|
10
8
|
import * as RPC from './rpc.js';
|
|
11
9
|
type FileMethods = Omit<ExtractProperties<File, (...args: any[]) => Promise<any>>, typeof Symbol.asyncDispose>;
|
|
12
10
|
type FileMethod = keyof FileMethods;
|
|
13
|
-
|
|
11
|
+
/** @internal */
|
|
12
|
+
export interface FileRequest<TMethod extends FileMethod = FileMethod> extends RPC.Request {
|
|
14
13
|
fd: number;
|
|
15
14
|
scope: 'file';
|
|
16
15
|
method: TMethod;
|
|
@@ -46,13 +45,14 @@ export declare class PortFile extends File {
|
|
|
46
45
|
}
|
|
47
46
|
type FSMethods = ExtractProperties<FileSystem, (...args: any[]) => Promise<any> | FileSystemMetadata>;
|
|
48
47
|
type FSMethod = keyof FSMethods;
|
|
49
|
-
|
|
48
|
+
/** @internal */
|
|
49
|
+
export interface FSRequest<TMethod extends FSMethod = FSMethod> extends RPC.Request {
|
|
50
50
|
scope: 'fs';
|
|
51
51
|
method: TMethod;
|
|
52
52
|
args: Parameters<FSMethods[TMethod]>;
|
|
53
53
|
}
|
|
54
54
|
declare const PortFS_base: import("../../index.js").Mixin<typeof FileSystem, {
|
|
55
|
-
_sync?: FileSystem
|
|
55
|
+
_sync?: FileSystem;
|
|
56
56
|
queueDone(): Promise<void>;
|
|
57
57
|
ready(): Promise<void>;
|
|
58
58
|
renameSync(oldPath: string, newPath: string): void;
|
|
@@ -67,10 +67,10 @@ declare const PortFS_base: import("../../index.js").Mixin<typeof FileSystem, {
|
|
|
67
67
|
syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
|
|
68
68
|
}>;
|
|
69
69
|
/**
|
|
70
|
-
* PortFS lets you access
|
|
70
|
+
* PortFS lets you access an FS instance that is running in a port, or the other way around.
|
|
71
71
|
*
|
|
72
|
-
* Note that synchronous operations are not permitted on the PortFS,
|
|
73
|
-
* of the configuration option of the remote FS.
|
|
72
|
+
* Note that *direct* synchronous operations are not permitted on the PortFS,
|
|
73
|
+
* regardless of the configuration option of the remote FS.
|
|
74
74
|
*/
|
|
75
75
|
export declare class PortFS extends PortFS_base {
|
|
76
76
|
readonly options: RPC.Options;
|
|
@@ -80,8 +80,7 @@ export declare class PortFS extends PortFS_base {
|
|
|
80
80
|
*/
|
|
81
81
|
_sync: import("../store/fs.js").StoreFS<import("../memory.js").InMemoryStore>;
|
|
82
82
|
/**
|
|
83
|
-
* Constructs a new PortFS instance that connects with
|
|
84
|
-
* the specified port.
|
|
83
|
+
* Constructs a new PortFS instance that connects with the FS running on `options.port`.
|
|
85
84
|
*/
|
|
86
85
|
constructor(options: RPC.Options);
|
|
87
86
|
metadata(): FileSystemMetadata;
|
|
@@ -99,13 +98,9 @@ export declare class PortFS extends PortFS_base {
|
|
|
99
98
|
exists(path: string): Promise<boolean>;
|
|
100
99
|
link(srcpath: string, dstpath: string): Promise<void>;
|
|
101
100
|
}
|
|
102
|
-
/**
|
|
103
|
-
* @internal
|
|
104
|
-
*/
|
|
101
|
+
/** @internal */
|
|
105
102
|
export type FileOrFSRequest = FSRequest | FileRequest;
|
|
106
|
-
/**
|
|
107
|
-
* @internal
|
|
108
|
-
*/
|
|
103
|
+
/** @internal */
|
|
109
104
|
export declare function handleRequest(port: RPC.Port, fs: FileSystem, request: FileOrFSRequest): Promise<void>;
|
|
110
105
|
export declare function attachFS(port: RPC.Port, fs: FileSystem): void;
|
|
111
106
|
export declare function detachFS(port: RPC.Port, fs: FileSystem): void;
|
|
@@ -128,7 +123,7 @@ declare const _Port: {
|
|
|
128
123
|
create(options: RPC.Options): PortFS;
|
|
129
124
|
};
|
|
130
125
|
type _Port = typeof _Port;
|
|
131
|
-
interface Port extends _Port {
|
|
126
|
+
export interface Port extends _Port {
|
|
132
127
|
}
|
|
133
128
|
export declare const Port: Port;
|
|
134
129
|
export declare function resolveRemoteMount<T extends Backend>(port: RPC.Port, config: MountConfiguration<T>, _depth?: number): Promise<FilesystemOf<T>>;
|
package/dist/backends/port/fs.js
CHANGED
|
@@ -87,15 +87,14 @@ export class PortFile extends File {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
/**
|
|
90
|
-
* PortFS lets you access
|
|
90
|
+
* PortFS lets you access an FS instance that is running in a port, or the other way around.
|
|
91
91
|
*
|
|
92
|
-
* Note that synchronous operations are not permitted on the PortFS,
|
|
93
|
-
* of the configuration option of the remote FS.
|
|
92
|
+
* Note that *direct* synchronous operations are not permitted on the PortFS,
|
|
93
|
+
* regardless of the configuration option of the remote FS.
|
|
94
94
|
*/
|
|
95
95
|
export class PortFS extends Async(FileSystem) {
|
|
96
96
|
/**
|
|
97
|
-
* Constructs a new PortFS instance that connects with
|
|
98
|
-
* the specified port.
|
|
97
|
+
* Constructs a new PortFS instance that connects with the FS running on `options.port`.
|
|
99
98
|
*/
|
|
100
99
|
constructor(options) {
|
|
101
100
|
super();
|
|
@@ -160,9 +159,7 @@ export class PortFS extends Async(FileSystem) {
|
|
|
160
159
|
}
|
|
161
160
|
let nextFd = 0;
|
|
162
161
|
const descriptors = new Map();
|
|
163
|
-
/**
|
|
164
|
-
* @internal
|
|
165
|
-
*/
|
|
162
|
+
/** @internal */
|
|
166
163
|
export async function handleRequest(port, fs, request) {
|
|
167
164
|
if (!RPC.isMessage(request)) {
|
|
168
165
|
return;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
1
|
import { type ErrnoErrorJSON } from '../../error.js';
|
|
3
2
|
import type { Backend, FilesystemOf } from '../backend.js';
|
|
4
3
|
import { type PortFS } from './fs.js';
|
|
5
4
|
type _MessageEvent<T = any> = T | {
|
|
6
5
|
data: T;
|
|
7
6
|
};
|
|
7
|
+
/** @internal */
|
|
8
8
|
export interface Port {
|
|
9
9
|
postMessage(value: unknown): void;
|
|
10
10
|
on?(event: 'message', listener: (value: unknown) => void): this;
|
|
@@ -47,12 +47,12 @@ export declare class StoreFS<T extends Store = Store> extends FileSystem {
|
|
|
47
47
|
readdir(path: string): Promise<string[]>;
|
|
48
48
|
readdirSync(path: string): string[];
|
|
49
49
|
/**
|
|
50
|
-
* Updated the inode and data node at
|
|
50
|
+
* Updated the inode and data node at `path`
|
|
51
51
|
* @todo Ensure mtime updates properly, and use that to determine if a data update is required.
|
|
52
52
|
*/
|
|
53
53
|
sync(path: string, data: Uint8Array, stats: Readonly<Stats>): Promise<void>;
|
|
54
54
|
/**
|
|
55
|
-
* Updated the inode and data node at
|
|
55
|
+
* Updated the inode and data node at `path`
|
|
56
56
|
* @todo Ensure mtime updates properly, and use that to determine if a data update is required.
|
|
57
57
|
*/
|
|
58
58
|
syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
|
|
@@ -82,13 +82,13 @@ export declare class StoreFS<T extends Store = Store> extends FileSystem {
|
|
|
82
82
|
*/
|
|
83
83
|
protected _findINodeSync(tx: Transaction, parent: string, filename: string, visited?: Set<string>): Ino;
|
|
84
84
|
/**
|
|
85
|
-
* Finds the Inode of
|
|
85
|
+
* Finds the Inode of `path`.
|
|
86
86
|
* @param path The path to look up.
|
|
87
87
|
* @todo memoize/cache
|
|
88
88
|
*/
|
|
89
89
|
private findINode;
|
|
90
90
|
/**
|
|
91
|
-
* Finds the Inode of
|
|
91
|
+
* Finds the Inode of `path`.
|
|
92
92
|
* @param path The path to look up.
|
|
93
93
|
* @return The Inode of the path p.
|
|
94
94
|
* @todo memoize/cache
|
|
@@ -131,18 +131,16 @@ export declare class StoreFS<T extends Store = Store> extends FileSystem {
|
|
|
131
131
|
*/
|
|
132
132
|
protected addNewSync(tx: Transaction, data: Uint8Array, path: string): Ino;
|
|
133
133
|
/**
|
|
134
|
-
* Commits a new file (well, a FILE or a DIRECTORY) to the file system with
|
|
135
|
-
* the given mode.
|
|
134
|
+
* Commits a new file (well, a FILE or a DIRECTORY) to the file system with `mode`.
|
|
136
135
|
* Note: This will commit the transaction.
|
|
137
136
|
* @param path The path to the new file.
|
|
138
137
|
* @param type The type of the new file.
|
|
139
138
|
* @param mode The mode to create the new file with.
|
|
140
|
-
* @param cred The UID/GID to create the file with
|
|
141
139
|
* @param data The data to store at the file's data node.
|
|
142
140
|
*/
|
|
143
141
|
private commitNew;
|
|
144
142
|
/**
|
|
145
|
-
* Commits a new file (well, a FILE or a DIRECTORY) to the file system with
|
|
143
|
+
* Commits a new file (well, a FILE or a DIRECTORY) to the file system with `mode`.
|
|
146
144
|
* Note: This will commit the transaction.
|
|
147
145
|
* @param path The path to the new file.
|
|
148
146
|
* @param type The type of the new file.
|
|
@@ -152,14 +150,14 @@ export declare class StoreFS<T extends Store = Store> extends FileSystem {
|
|
|
152
150
|
*/
|
|
153
151
|
protected commitNewSync(path: string, type: FileType, mode: number, data?: Uint8Array): Inode;
|
|
154
152
|
/**
|
|
155
|
-
* Remove all traces of
|
|
153
|
+
* Remove all traces of `path` from the file system.
|
|
156
154
|
* @param path The path to remove from the file system.
|
|
157
155
|
* @param isDir Does the path belong to a directory, or a file?
|
|
158
156
|
* @todo Update mtime.
|
|
159
157
|
*/
|
|
160
158
|
private remove;
|
|
161
159
|
/**
|
|
162
|
-
* Remove all traces of
|
|
160
|
+
* Remove all traces of `path` from the file system.
|
|
163
161
|
* @param path The path to remove from the file system.
|
|
164
162
|
* @param isDir Does the path belong to a directory, or a file?
|
|
165
163
|
* @todo Update mtime.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
2
|
if (value !== null && value !== void 0) {
|
|
3
3
|
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
-
var dispose;
|
|
4
|
+
var dispose, inner;
|
|
5
5
|
if (async) {
|
|
6
6
|
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
7
|
dispose = value[Symbol.asyncDispose];
|
|
@@ -9,8 +9,10 @@ var __addDisposableResource = (this && this.__addDisposableResource) || function
|
|
|
9
9
|
if (dispose === void 0) {
|
|
10
10
|
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
11
|
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
12
13
|
}
|
|
13
14
|
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
14
16
|
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
15
17
|
}
|
|
16
18
|
else if (async) {
|
|
@@ -112,25 +114,19 @@ export class StoreFS extends FileSystem {
|
|
|
112
114
|
}
|
|
113
115
|
const nodeId = oldDirList[oldName];
|
|
114
116
|
delete oldDirList[oldName];
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
/*
|
|
118
|
+
Can't move a folder inside itself.
|
|
119
|
+
This ensures that the check passes only if `oldPath` is a subpath of `newParent`.
|
|
120
|
+
We append '/' to avoid matching folders that are a substring of the bottom-most folder in the path.
|
|
121
|
+
*/
|
|
119
122
|
if ((newParent + '/').indexOf(oldPath + '/') === 0) {
|
|
120
123
|
throw new ErrnoError(Errno.EBUSY, oldParent);
|
|
121
124
|
}
|
|
122
125
|
// Add newPath to parent's directory listing.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
newDirNode = oldDirNode;
|
|
128
|
-
newDirList = oldDirList;
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
newDirNode = await this.findINode(tx, newParent);
|
|
132
|
-
newDirList = await this.getDirListing(tx, newDirNode, newParent);
|
|
133
|
-
}
|
|
126
|
+
const sameParent = newParent === oldParent;
|
|
127
|
+
// Prevent us from re-grabbing the same directory listing, which still contains `oldName.`
|
|
128
|
+
const newDirNode = sameParent ? oldDirNode : await this.findINode(tx, newParent);
|
|
129
|
+
const newDirList = sameParent ? oldDirList : await this.getDirListing(tx, newDirNode, newParent);
|
|
134
130
|
if (newDirList[newName]) {
|
|
135
131
|
// If it's a file, delete it, if it's a directory, throw a permissions error.
|
|
136
132
|
const newNameNode = await this.getINode(tx, newDirList[newName], newPath);
|
|
@@ -168,25 +164,19 @@ export class StoreFS extends FileSystem {
|
|
|
168
164
|
}
|
|
169
165
|
const ino = oldDirList[oldName];
|
|
170
166
|
delete oldDirList[oldName];
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
167
|
+
/*
|
|
168
|
+
Can't move a folder inside itself.
|
|
169
|
+
This ensures that the check passes only if `oldPath` is a subpath of `newParent`.
|
|
170
|
+
We append '/' to avoid matching folders that are a substring of the bottom-most folder in the path.
|
|
171
|
+
*/
|
|
175
172
|
if ((newParent + '/').indexOf(oldPath + '/') == 0) {
|
|
176
173
|
throw new ErrnoError(Errno.EBUSY, oldParent);
|
|
177
174
|
}
|
|
178
175
|
// Add newPath to parent's directory listing.
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
newDirNode = oldDirNode;
|
|
184
|
-
newDirList = oldDirList;
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
newDirNode = this.findINodeSync(tx, newParent);
|
|
188
|
-
newDirList = this.getDirListingSync(tx, newDirNode, newParent);
|
|
189
|
-
}
|
|
176
|
+
const sameParent = newParent === oldParent;
|
|
177
|
+
// Prevent us from re-grabbing the same directory listing, which still contains `oldName.`
|
|
178
|
+
const newDirNode = sameParent ? oldDirNode : this.findINodeSync(tx, newParent);
|
|
179
|
+
const newDirList = sameParent ? oldDirList : this.getDirListingSync(tx, newDirNode, newParent);
|
|
190
180
|
if (newDirList[newName]) {
|
|
191
181
|
// If it's a file, delete it, if it's a directory, throw a permissions error.
|
|
192
182
|
const newNameNode = this.getINodeSync(tx, newDirList[newName], newPath);
|
|
@@ -214,11 +204,7 @@ export class StoreFS extends FileSystem {
|
|
|
214
204
|
const env_3 = { stack: [], error: void 0, hasError: false };
|
|
215
205
|
try {
|
|
216
206
|
const tx = __addDisposableResource(env_3, this.store.transaction(), true);
|
|
217
|
-
|
|
218
|
-
if (!inode) {
|
|
219
|
-
throw ErrnoError.With('ENOENT', path, 'stat');
|
|
220
|
-
}
|
|
221
|
-
return inode.toStats();
|
|
207
|
+
return (await this.findINode(tx, path)).toStats();
|
|
222
208
|
}
|
|
223
209
|
catch (e_3) {
|
|
224
210
|
env_3.error = e_3;
|
|
@@ -234,7 +220,6 @@ export class StoreFS extends FileSystem {
|
|
|
234
220
|
const env_4 = { stack: [], error: void 0, hasError: false };
|
|
235
221
|
try {
|
|
236
222
|
const tx = __addDisposableResource(env_4, this.store.transaction(), false);
|
|
237
|
-
// Get the inode to the item, convert it into a Stats object.
|
|
238
223
|
return this.findINodeSync(tx, path).toStats();
|
|
239
224
|
}
|
|
240
225
|
catch (e_4) {
|
|
@@ -298,14 +283,12 @@ export class StoreFS extends FileSystem {
|
|
|
298
283
|
this.removeSync(path, false);
|
|
299
284
|
}
|
|
300
285
|
async rmdir(path) {
|
|
301
|
-
// Check first if directory is empty.
|
|
302
286
|
if ((await this.readdir(path)).length) {
|
|
303
287
|
throw ErrnoError.With('ENOTEMPTY', path, 'rmdir');
|
|
304
288
|
}
|
|
305
289
|
await this.remove(path, true);
|
|
306
290
|
}
|
|
307
291
|
rmdirSync(path) {
|
|
308
|
-
// Check first if directory is empty.
|
|
309
292
|
if (this.readdirSync(path).length) {
|
|
310
293
|
throw ErrnoError.With('ENOTEMPTY', path, 'rmdir');
|
|
311
294
|
}
|
|
@@ -350,7 +333,7 @@ export class StoreFS extends FileSystem {
|
|
|
350
333
|
}
|
|
351
334
|
}
|
|
352
335
|
/**
|
|
353
|
-
* Updated the inode and data node at
|
|
336
|
+
* Updated the inode and data node at `path`
|
|
354
337
|
* @todo Ensure mtime updates properly, and use that to determine if a data update is required.
|
|
355
338
|
*/
|
|
356
339
|
async sync(path, data, stats) {
|
|
@@ -378,7 +361,7 @@ export class StoreFS extends FileSystem {
|
|
|
378
361
|
}
|
|
379
362
|
}
|
|
380
363
|
/**
|
|
381
|
-
* Updated the inode and data node at
|
|
364
|
+
* Updated the inode and data node at `path`
|
|
382
365
|
* @todo Ensure mtime updates properly, and use that to determine if a data update is required.
|
|
383
366
|
*/
|
|
384
367
|
syncSync(path, data, stats) {
|
|
@@ -547,7 +530,7 @@ export class StoreFS extends FileSystem {
|
|
|
547
530
|
return dir[filename];
|
|
548
531
|
}
|
|
549
532
|
/**
|
|
550
|
-
* Finds the Inode of
|
|
533
|
+
* Finds the Inode of `path`.
|
|
551
534
|
* @param path The path to look up.
|
|
552
535
|
* @todo memoize/cache
|
|
553
536
|
*/
|
|
@@ -556,7 +539,7 @@ export class StoreFS extends FileSystem {
|
|
|
556
539
|
return this.getINode(tx, id, path);
|
|
557
540
|
}
|
|
558
541
|
/**
|
|
559
|
-
* Finds the Inode of
|
|
542
|
+
* Finds the Inode of `path`.
|
|
560
543
|
* @param path The path to look up.
|
|
561
544
|
* @return The Inode of the path p.
|
|
562
545
|
* @todo memoize/cache
|
|
@@ -656,13 +639,11 @@ export class StoreFS extends FileSystem {
|
|
|
656
639
|
throw new ErrnoError(Errno.ENOSPC, 'No inode IDs available', path, 'addNewNode');
|
|
657
640
|
}
|
|
658
641
|
/**
|
|
659
|
-
* Commits a new file (well, a FILE or a DIRECTORY) to the file system with
|
|
660
|
-
* the given mode.
|
|
642
|
+
* Commits a new file (well, a FILE or a DIRECTORY) to the file system with `mode`.
|
|
661
643
|
* Note: This will commit the transaction.
|
|
662
644
|
* @param path The path to the new file.
|
|
663
645
|
* @param type The type of the new file.
|
|
664
646
|
* @param mode The mode to create the new file with.
|
|
665
|
-
* @param cred The UID/GID to create the file with
|
|
666
647
|
* @param data The data to store at the file's data node.
|
|
667
648
|
*/
|
|
668
649
|
async commitNew(path, type, mode, data) {
|
|
@@ -708,7 +689,7 @@ export class StoreFS extends FileSystem {
|
|
|
708
689
|
}
|
|
709
690
|
}
|
|
710
691
|
/**
|
|
711
|
-
* Commits a new file (well, a FILE or a DIRECTORY) to the file system with
|
|
692
|
+
* Commits a new file (well, a FILE or a DIRECTORY) to the file system with `mode`.
|
|
712
693
|
* Note: This will commit the transaction.
|
|
713
694
|
* @param path The path to the new file.
|
|
714
695
|
* @param type The type of the new file.
|
|
@@ -756,7 +737,7 @@ export class StoreFS extends FileSystem {
|
|
|
756
737
|
}
|
|
757
738
|
}
|
|
758
739
|
/**
|
|
759
|
-
* Remove all traces of
|
|
740
|
+
* Remove all traces of `path` from the file system.
|
|
760
741
|
* @param path The path to remove from the file system.
|
|
761
742
|
* @param isDir Does the path belong to a directory, or a file?
|
|
762
743
|
* @todo Update mtime.
|
|
@@ -800,7 +781,7 @@ export class StoreFS extends FileSystem {
|
|
|
800
781
|
}
|
|
801
782
|
}
|
|
802
783
|
/**
|
|
803
|
-
* Remove all traces of
|
|
784
|
+
* Remove all traces of `path` from the file system.
|
|
804
785
|
* @param path The path to remove from the file system.
|
|
805
786
|
* @param isDir Does the path belong to a directory, or a file?
|
|
806
787
|
* @todo Update mtime.
|
|
@@ -56,7 +56,7 @@ export declare class SimpleTransaction extends SyncTransaction<SimpleSyncStore>
|
|
|
56
56
|
*/
|
|
57
57
|
protected stashOldValue(ino: Ino, value?: Uint8Array): void;
|
|
58
58
|
/**
|
|
59
|
-
* Marks
|
|
59
|
+
* Marks `ino` as modified, and stashes its value if it has not been
|
|
60
60
|
* stashed already.
|
|
61
61
|
*/
|
|
62
62
|
protected markModified(ino: Ino): void;
|
|
@@ -102,7 +102,7 @@ export class SimpleTransaction extends SyncTransaction {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
105
|
-
* Marks
|
|
105
|
+
* Marks `ino` as modified, and stashes its value if it has not been
|
|
106
106
|
* stashed already.
|
|
107
107
|
*/
|
|
108
108
|
markModified(ino) {
|