@zenfs/core 1.11.4 → 2.1.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/backend.d.ts +19 -15
- package/dist/backends/backend.js +36 -19
- package/dist/backends/cow.d.ts +20 -30
- package/dist/backends/cow.js +83 -192
- package/dist/backends/fetch.d.ts +1 -0
- package/dist/backends/fetch.js +30 -30
- package/dist/backends/index.d.ts +1 -1
- package/dist/backends/index.js +1 -1
- package/dist/backends/memory.d.ts +5 -7
- package/dist/backends/memory.js +2 -3
- package/dist/backends/passthrough.d.ts +19 -23
- package/dist/backends/passthrough.js +98 -288
- package/dist/backends/port.d.ts +220 -0
- package/dist/backends/port.js +328 -0
- package/dist/backends/single_buffer.d.ts +59 -47
- package/dist/backends/single_buffer.js +468 -219
- package/dist/backends/store/fs.d.ts +25 -35
- package/dist/backends/store/fs.js +276 -315
- package/dist/backends/store/store.d.ts +10 -15
- package/dist/backends/store/store.js +11 -10
- package/dist/config.d.ts +3 -12
- package/dist/config.js +17 -19
- package/dist/context.d.ts +8 -21
- package/dist/context.js +33 -10
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/internal/contexts.d.ts +63 -0
- package/dist/internal/contexts.js +15 -0
- package/dist/internal/credentials.d.ts +2 -11
- package/dist/internal/credentials.js +0 -19
- package/dist/internal/devices.d.ts +18 -80
- package/dist/internal/devices.js +103 -316
- package/dist/internal/error.d.ts +9 -204
- package/dist/internal/error.js +19 -288
- package/dist/internal/file_index.d.ts +1 -1
- package/dist/internal/file_index.js +11 -11
- package/dist/internal/filesystem.d.ts +51 -94
- package/dist/internal/filesystem.js +21 -20
- package/dist/internal/index.d.ts +1 -2
- package/dist/internal/index.js +1 -2
- package/dist/internal/index_fs.d.ts +12 -30
- package/dist/internal/index_fs.js +37 -69
- package/dist/internal/inode.d.ts +140 -24
- package/dist/internal/inode.js +515 -66
- package/dist/mixins/async.js +52 -112
- package/dist/mixins/mutexed.d.ts +19 -18
- package/dist/mixins/mutexed.js +62 -64
- package/dist/mixins/readonly.d.ts +7 -6
- package/dist/mixins/readonly.js +24 -18
- package/dist/mixins/sync.js +8 -8
- package/dist/{vfs/path.d.ts → path.d.ts} +3 -4
- package/dist/{vfs/path.js → path.js} +6 -9
- package/dist/polyfills.js +1 -1
- package/dist/readline.d.ts +134 -0
- package/dist/readline.js +623 -0
- package/dist/utils.d.ts +9 -37
- package/dist/utils.js +17 -85
- package/dist/vfs/acl.d.ts +42 -0
- package/dist/vfs/acl.js +268 -0
- package/dist/vfs/async.d.ts +9 -23
- package/dist/vfs/async.js +25 -27
- package/dist/vfs/config.d.ts +6 -18
- package/dist/vfs/config.js +8 -18
- package/dist/vfs/dir.d.ts +3 -3
- package/dist/vfs/dir.js +12 -12
- package/dist/vfs/file.d.ts +106 -0
- package/dist/vfs/file.js +244 -0
- package/dist/vfs/flags.d.ts +19 -0
- package/dist/vfs/flags.js +62 -0
- package/dist/vfs/index.d.ts +4 -10
- package/dist/vfs/index.js +4 -13
- package/dist/vfs/ioctl.d.ts +88 -0
- package/dist/vfs/ioctl.js +409 -0
- package/dist/vfs/promises.d.ts +81 -19
- package/dist/vfs/promises.js +404 -288
- package/dist/vfs/shared.d.ts +7 -37
- package/dist/vfs/shared.js +29 -85
- package/dist/{stats.d.ts → vfs/stats.d.ts} +14 -28
- package/dist/{stats.js → vfs/stats.js} +11 -66
- package/dist/vfs/streams.d.ts +1 -0
- package/dist/vfs/streams.js +32 -27
- package/dist/vfs/sync.d.ts +3 -3
- package/dist/vfs/sync.js +263 -260
- package/dist/vfs/watchers.d.ts +2 -2
- package/dist/vfs/watchers.js +12 -12
- package/dist/vfs/xattr.d.ts +116 -0
- package/dist/vfs/xattr.js +201 -0
- package/package.json +5 -3
- package/readme.md +1 -1
- package/scripts/test.js +2 -2
- package/tests/assignment.ts +1 -1
- package/tests/backend/config.worker.js +4 -1
- package/tests/backend/fetch.test.ts +3 -0
- package/tests/backend/port.test.ts +19 -33
- package/tests/backend/remote.worker.js +4 -1
- package/tests/backend/single-buffer.test.ts +53 -0
- package/tests/backend/single-buffer.worker.js +30 -0
- package/tests/common/context.test.ts +3 -3
- package/tests/common/handle.test.ts +17 -12
- package/tests/common/mutex.test.ts +9 -9
- package/tests/common/path.test.ts +1 -1
- package/tests/common/readline.test.ts +104 -0
- package/tests/common.ts +4 -19
- package/tests/fetch/fetch.ts +2 -2
- package/tests/fs/append.test.ts +4 -4
- package/tests/fs/directory.test.ts +25 -25
- package/tests/fs/errors.test.ts +15 -19
- package/tests/fs/links.test.ts +4 -3
- package/tests/fs/open.test.ts +4 -21
- package/tests/fs/permissions.test.ts +14 -18
- package/tests/fs/read.test.ts +10 -9
- package/tests/fs/readFile.test.ts +10 -26
- package/tests/fs/rename.test.ts +4 -9
- package/tests/fs/stat.test.ts +8 -8
- package/tests/fs/streams.test.ts +2 -11
- package/tests/fs/times.test.ts +7 -7
- package/tests/fs/truncate.test.ts +8 -36
- package/tests/fs/watch.test.ts +10 -10
- package/tests/fs/write.test.ts +77 -13
- package/tests/fs/xattr.test.ts +85 -0
- package/tests/logs.js +22 -0
- package/tests/setup/context.ts +1 -1
- package/tests/setup/index.ts +3 -3
- package/tests/setup/port.ts +7 -1
- package/dist/backends/port/fs.d.ts +0 -84
- package/dist/backends/port/fs.js +0 -151
- package/dist/backends/port/rpc.d.ts +0 -77
- package/dist/backends/port/rpc.js +0 -100
- package/dist/backends/store/simple.d.ts +0 -20
- package/dist/backends/store/simple.js +0 -13
- package/dist/internal/file.d.ts +0 -359
- package/dist/internal/file.js +0 -751
- package/dist/internal/log.d.ts +0 -133
- package/dist/internal/log.js +0 -218
- package/tests/fs/writeFile.test.ts +0 -70
package/dist/utils.js
CHANGED
|
@@ -1,56 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { resolve } from './
|
|
4
|
-
/**
|
|
5
|
-
* Encodes a string into a buffer
|
|
6
|
-
* @internal
|
|
7
|
-
*/
|
|
8
|
-
export function encodeRaw(input) {
|
|
9
|
-
if (typeof input != 'string') {
|
|
10
|
-
throw new ErrnoError(Errno.EINVAL, 'Can not encode a non-string');
|
|
11
|
-
}
|
|
12
|
-
return new Uint8Array(Array.from(input).map(char => char.charCodeAt(0)));
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Decodes a string from a buffer
|
|
16
|
-
* @internal
|
|
17
|
-
*/
|
|
18
|
-
export function decodeRaw(input) {
|
|
19
|
-
if (!(input instanceof Uint8Array)) {
|
|
20
|
-
throw new ErrnoError(Errno.EINVAL, 'Can not decode a non-Uint8Array');
|
|
21
|
-
}
|
|
22
|
-
return Array.from(input)
|
|
23
|
-
.map(char => String.fromCharCode(char))
|
|
24
|
-
.join('');
|
|
25
|
-
}
|
|
26
|
-
const encoder = new TextEncoder();
|
|
27
|
-
/**
|
|
28
|
-
* Encodes a string into a buffer
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
|
-
export function encodeUTF8(input) {
|
|
32
|
-
if (typeof input != 'string') {
|
|
33
|
-
throw new ErrnoError(Errno.EINVAL, 'Can not encode a non-string');
|
|
34
|
-
}
|
|
35
|
-
return encoder.encode(input);
|
|
36
|
-
}
|
|
37
|
-
/* node:coverage disable */
|
|
38
|
-
export { /** @deprecated @hidden */ encodeUTF8 as encode };
|
|
39
|
-
/* node:coverage enable */
|
|
40
|
-
const decoder = new TextDecoder();
|
|
41
|
-
/**
|
|
42
|
-
* Decodes a string from a buffer
|
|
43
|
-
* @internal
|
|
44
|
-
*/
|
|
45
|
-
export function decodeUTF8(input) {
|
|
46
|
-
if (!(input instanceof Uint8Array)) {
|
|
47
|
-
throw new ErrnoError(Errno.EINVAL, 'Can not decode a non-Uint8Array');
|
|
48
|
-
}
|
|
49
|
-
return decoder.decode(input);
|
|
50
|
-
}
|
|
51
|
-
/* node:coverage disable */
|
|
52
|
-
export { /** @deprecated @hidden */ decodeUTF8 as decode };
|
|
53
|
-
/* node:coverage enable */
|
|
1
|
+
import { withErrno } from 'kerium';
|
|
2
|
+
import { decodeUTF8, encodeUTF8 } from 'utilium';
|
|
3
|
+
import { resolve } from './path.js';
|
|
54
4
|
/**
|
|
55
5
|
* Decodes a directory listing
|
|
56
6
|
* @hidden
|
|
@@ -81,7 +31,7 @@ export function normalizeMode(mode, def) {
|
|
|
81
31
|
}
|
|
82
32
|
if (typeof def == 'number')
|
|
83
33
|
return def;
|
|
84
|
-
throw
|
|
34
|
+
throw withErrno('EINVAL', 'Invalid mode: ' + (mode === null || mode === void 0 ? void 0 : mode.toString()));
|
|
85
35
|
}
|
|
86
36
|
/**
|
|
87
37
|
* Normalizes a time
|
|
@@ -94,9 +44,15 @@ export function normalizeTime(time) {
|
|
|
94
44
|
return Number(time);
|
|
95
45
|
}
|
|
96
46
|
catch {
|
|
97
|
-
throw
|
|
47
|
+
throw withErrno('EINVAL', 'Invalid time.');
|
|
98
48
|
}
|
|
99
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* TypeScript is dumb, so we need to assert the type of a value sometimes.
|
|
52
|
+
* For example, after calling `normalizePath`, TS still thinks the type is `PathLike` and not `string`.
|
|
53
|
+
* @internal @hidden
|
|
54
|
+
*/
|
|
55
|
+
export function __assertType(value) { }
|
|
100
56
|
/**
|
|
101
57
|
* Normalizes a path
|
|
102
58
|
* @internal
|
|
@@ -104,19 +60,18 @@ export function normalizeTime(time) {
|
|
|
104
60
|
export function normalizePath(p, noResolve = false) {
|
|
105
61
|
if (p instanceof URL) {
|
|
106
62
|
if (p.protocol != 'file:')
|
|
107
|
-
throw
|
|
63
|
+
throw withErrno('EINVAL', 'URLs must use the file: protocol');
|
|
108
64
|
p = p.pathname;
|
|
109
65
|
}
|
|
110
66
|
p = p.toString();
|
|
111
67
|
if (p.startsWith('file://'))
|
|
112
68
|
p = p.slice('file://'.length);
|
|
113
|
-
if (p.includes('\x00'))
|
|
114
|
-
throw
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
throw new ErrnoError(Errno.EINVAL, 'Path can not be empty');
|
|
118
|
-
}
|
|
69
|
+
if (p.includes('\x00'))
|
|
70
|
+
throw withErrno('EINVAL', 'Path can not contain null character');
|
|
71
|
+
if (p.length == 0)
|
|
72
|
+
throw withErrno('EINVAL', 'Path can not be empty');
|
|
119
73
|
p = p.replaceAll(/[/\\]+/g, '/');
|
|
74
|
+
// Note: PWD is not resolved here, it is resolved later.
|
|
120
75
|
return noResolve ? p : resolve(p);
|
|
121
76
|
}
|
|
122
77
|
/**
|
|
@@ -141,26 +96,3 @@ export function normalizeOptions(options, encoding = 'utf8', flag, mode = 0) {
|
|
|
141
96
|
mode: normalizeMode('mode' in options ? options === null || options === void 0 ? void 0 : options.mode : null, mode),
|
|
142
97
|
};
|
|
143
98
|
}
|
|
144
|
-
/* node:coverage disable */
|
|
145
|
-
import { randomHex } from 'utilium';
|
|
146
|
-
/**
|
|
147
|
-
* Generate a random ino
|
|
148
|
-
* @internal @deprecated @hidden
|
|
149
|
-
*/
|
|
150
|
-
export function randomBigInt() {
|
|
151
|
-
log_deprecated('randomBigInt');
|
|
152
|
-
return BigInt('0x' + randomHex(8));
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Prevents infinite loops
|
|
156
|
-
* @internal
|
|
157
|
-
* @deprecated Use `canary` from Utilium
|
|
158
|
-
*/
|
|
159
|
-
export function canary(path, syscall) {
|
|
160
|
-
log_deprecated('canary');
|
|
161
|
-
const timeout = setTimeout(() => {
|
|
162
|
-
throw ErrnoError.With('EDEADLK', path, syscall);
|
|
163
|
-
}, 5000);
|
|
164
|
-
return () => clearTimeout(timeout);
|
|
165
|
-
}
|
|
166
|
-
/* node:coverage enable */
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { BufferView } from 'utilium/buffer.js';
|
|
2
|
+
import { type V_Context } from '../internal/contexts.js';
|
|
3
|
+
import { type InodeLike } from '../internal/inode.js';
|
|
4
|
+
export declare const enum Type {
|
|
5
|
+
Access = 32768,
|
|
6
|
+
Default = 16384
|
|
7
|
+
}
|
|
8
|
+
export declare const enum Tag {
|
|
9
|
+
UserObj = 1,
|
|
10
|
+
User = 2,
|
|
11
|
+
GroupObj = 4,
|
|
12
|
+
Group = 8,
|
|
13
|
+
Mask = 16,
|
|
14
|
+
Other = 32,
|
|
15
|
+
/**
|
|
16
|
+
* @internal @hidden
|
|
17
|
+
*/
|
|
18
|
+
_None = 0
|
|
19
|
+
}
|
|
20
|
+
export declare class Entry extends BufferView {
|
|
21
|
+
accessor tag: Tag;
|
|
22
|
+
accessor perm: number;
|
|
23
|
+
accessor id: number;
|
|
24
|
+
}
|
|
25
|
+
export declare class ACL extends BufferView {
|
|
26
|
+
accessor version: number;
|
|
27
|
+
entries: Entry[];
|
|
28
|
+
constructor(...args: ConstructorParameters<typeof BufferView>);
|
|
29
|
+
}
|
|
30
|
+
export declare function fromMode(mode: number): ACL;
|
|
31
|
+
export declare function toMode(acl: ACL): number;
|
|
32
|
+
export declare function get($: V_Context, path: string): Promise<ACL>;
|
|
33
|
+
export declare function getSync($: V_Context, path: string): ACL;
|
|
34
|
+
export declare function set($: V_Context, path: string, acl: ACL): Promise<void>;
|
|
35
|
+
export declare function setSync($: V_Context, path: string, acl: ACL): void;
|
|
36
|
+
export declare let shouldCheck: boolean;
|
|
37
|
+
export declare function setChecks(enabled: boolean): void;
|
|
38
|
+
/**
|
|
39
|
+
* Checks if a given user/group has access to this item
|
|
40
|
+
* @param access The requested access, combination of `W_OK`, `R_OK`, and `X_OK`
|
|
41
|
+
*/
|
|
42
|
+
export declare function check($: V_Context, inode: InodeLike, access: number): boolean;
|
package/dist/vfs/acl.js
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
2
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
3
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
4
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
5
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
6
|
+
var _, done = false;
|
|
7
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
8
|
+
var context = {};
|
|
9
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
10
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
11
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
12
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
13
|
+
if (kind === "accessor") {
|
|
14
|
+
if (result === void 0) continue;
|
|
15
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
16
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
17
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
18
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
19
|
+
}
|
|
20
|
+
else if (_ = accept(result)) {
|
|
21
|
+
if (kind === "field") initializers.unshift(_);
|
|
22
|
+
else descriptor[key] = _;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
26
|
+
done = true;
|
|
27
|
+
};
|
|
28
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
29
|
+
var useValue = arguments.length > 2;
|
|
30
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
31
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
32
|
+
}
|
|
33
|
+
return useValue ? value : void 0;
|
|
34
|
+
};
|
|
35
|
+
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
|
|
36
|
+
if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
|
|
37
|
+
return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
|
|
38
|
+
};
|
|
39
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
40
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
41
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
42
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
43
|
+
};
|
|
44
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
45
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
46
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
47
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
48
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
49
|
+
};
|
|
50
|
+
/*
|
|
51
|
+
Access Control Lists.
|
|
52
|
+
At the moment, they are only intended for internal use.
|
|
53
|
+
They also are not checked for permissions yet.
|
|
54
|
+
Please use a namespace import for the best experience.
|
|
55
|
+
*/
|
|
56
|
+
import { withErrno } from 'kerium';
|
|
57
|
+
import { err } from 'kerium/log';
|
|
58
|
+
import { packed, sizeof, struct, types as t } from 'memium';
|
|
59
|
+
import { BufferView } from 'utilium/buffer.js';
|
|
60
|
+
import { defaultContext } from '../internal/contexts.js';
|
|
61
|
+
import { Attributes } from '../internal/inode.js';
|
|
62
|
+
import { R_OK, S_IRWXG, S_IRWXO, S_IRWXU, W_OK, X_OK } from './constants.js';
|
|
63
|
+
import * as xattr from './xattr.js';
|
|
64
|
+
const version = 2;
|
|
65
|
+
export var Type;
|
|
66
|
+
(function (Type) {
|
|
67
|
+
Type[Type["Access"] = 32768] = "Access";
|
|
68
|
+
Type[Type["Default"] = 16384] = "Default";
|
|
69
|
+
})(Type || (Type = {}));
|
|
70
|
+
export var Tag;
|
|
71
|
+
(function (Tag) {
|
|
72
|
+
Tag[Tag["UserObj"] = 1] = "UserObj";
|
|
73
|
+
Tag[Tag["User"] = 2] = "User";
|
|
74
|
+
Tag[Tag["GroupObj"] = 4] = "GroupObj";
|
|
75
|
+
Tag[Tag["Group"] = 8] = "Group";
|
|
76
|
+
Tag[Tag["Mask"] = 16] = "Mask";
|
|
77
|
+
Tag[Tag["Other"] = 32] = "Other";
|
|
78
|
+
/**
|
|
79
|
+
* @internal @hidden
|
|
80
|
+
*/
|
|
81
|
+
Tag[Tag["_None"] = 0] = "_None";
|
|
82
|
+
})(Tag || (Tag = {}));
|
|
83
|
+
let Entry = (() => {
|
|
84
|
+
var _Entry_tag_accessor_storage, _Entry_perm_accessor_storage, _Entry_id_accessor_storage;
|
|
85
|
+
var _a, _b, _c;
|
|
86
|
+
let _classDecorators = [struct(packed)];
|
|
87
|
+
let _classDescriptor;
|
|
88
|
+
let _classExtraInitializers = [];
|
|
89
|
+
let _classThis;
|
|
90
|
+
let _classSuper = BufferView;
|
|
91
|
+
let _tag_decorators;
|
|
92
|
+
let _tag_initializers = [];
|
|
93
|
+
let _tag_extraInitializers = [];
|
|
94
|
+
let _perm_decorators;
|
|
95
|
+
let _perm_initializers = [];
|
|
96
|
+
let _perm_extraInitializers = [];
|
|
97
|
+
let _id_decorators;
|
|
98
|
+
let _id_initializers = [];
|
|
99
|
+
let _id_extraInitializers = [];
|
|
100
|
+
var Entry = _classThis = class extends _classSuper {
|
|
101
|
+
get tag() { return __classPrivateFieldGet(this, _Entry_tag_accessor_storage, "f"); }
|
|
102
|
+
set tag(value) { __classPrivateFieldSet(this, _Entry_tag_accessor_storage, value, "f"); }
|
|
103
|
+
get perm() { return __classPrivateFieldGet(this, _Entry_perm_accessor_storage, "f"); }
|
|
104
|
+
set perm(value) { __classPrivateFieldSet(this, _Entry_perm_accessor_storage, value, "f"); }
|
|
105
|
+
get id() { return __classPrivateFieldGet(this, _Entry_id_accessor_storage, "f"); }
|
|
106
|
+
set id(value) { __classPrivateFieldSet(this, _Entry_id_accessor_storage, value, "f"); }
|
|
107
|
+
constructor() {
|
|
108
|
+
super(...arguments);
|
|
109
|
+
_Entry_tag_accessor_storage.set(this, __runInitializers(this, _tag_initializers, void 0));
|
|
110
|
+
_Entry_perm_accessor_storage.set(this, (__runInitializers(this, _tag_extraInitializers), __runInitializers(this, _perm_initializers, void 0)));
|
|
111
|
+
_Entry_id_accessor_storage.set(this, (__runInitializers(this, _perm_extraInitializers), __runInitializers(this, _id_initializers, void 0)));
|
|
112
|
+
__runInitializers(this, _id_extraInitializers);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
_Entry_tag_accessor_storage = new WeakMap();
|
|
116
|
+
_Entry_perm_accessor_storage = new WeakMap();
|
|
117
|
+
_Entry_id_accessor_storage = new WeakMap();
|
|
118
|
+
__setFunctionName(_classThis, "Entry");
|
|
119
|
+
(() => {
|
|
120
|
+
var _a;
|
|
121
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create((_a = _classSuper[Symbol.metadata]) !== null && _a !== void 0 ? _a : null) : void 0;
|
|
122
|
+
_tag_decorators = [(_a = t).uint16.bind(_a)];
|
|
123
|
+
_perm_decorators = [(_b = t).uint16.bind(_b)];
|
|
124
|
+
_id_decorators = [(_c = t).uint32.bind(_c)];
|
|
125
|
+
__esDecorate(_classThis, null, _tag_decorators, { kind: "accessor", name: "tag", static: false, private: false, access: { has: obj => "tag" in obj, get: obj => obj.tag, set: (obj, value) => { obj.tag = value; } }, metadata: _metadata }, _tag_initializers, _tag_extraInitializers);
|
|
126
|
+
__esDecorate(_classThis, null, _perm_decorators, { kind: "accessor", name: "perm", static: false, private: false, access: { has: obj => "perm" in obj, get: obj => obj.perm, set: (obj, value) => { obj.perm = value; } }, metadata: _metadata }, _perm_initializers, _perm_extraInitializers);
|
|
127
|
+
__esDecorate(_classThis, null, _id_decorators, { kind: "accessor", name: "id", static: false, private: false, access: { has: obj => "id" in obj, get: obj => obj.id, set: (obj, value) => { obj.id = value; } }, metadata: _metadata }, _id_initializers, _id_extraInitializers);
|
|
128
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
129
|
+
Entry = _classThis = _classDescriptor.value;
|
|
130
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
131
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
132
|
+
})();
|
|
133
|
+
return Entry = _classThis;
|
|
134
|
+
})();
|
|
135
|
+
export { Entry };
|
|
136
|
+
let ACL = (() => {
|
|
137
|
+
var _ACL_version_accessor_storage;
|
|
138
|
+
var _a;
|
|
139
|
+
let _classDecorators = [struct(packed)];
|
|
140
|
+
let _classDescriptor;
|
|
141
|
+
let _classExtraInitializers = [];
|
|
142
|
+
let _classThis;
|
|
143
|
+
let _classSuper = BufferView;
|
|
144
|
+
let _version_decorators;
|
|
145
|
+
let _version_initializers = [];
|
|
146
|
+
let _version_extraInitializers = [];
|
|
147
|
+
var ACL = _classThis = class extends _classSuper {
|
|
148
|
+
get version() { return __classPrivateFieldGet(this, _ACL_version_accessor_storage, "f"); }
|
|
149
|
+
set version(value) { __classPrivateFieldSet(this, _ACL_version_accessor_storage, value, "f"); }
|
|
150
|
+
constructor(...args) {
|
|
151
|
+
super(...args);
|
|
152
|
+
_ACL_version_accessor_storage.set(this, __runInitializers(this, _version_initializers, void 0));
|
|
153
|
+
this.entries = (__runInitializers(this, _version_extraInitializers), []);
|
|
154
|
+
this.version || (this.version = version);
|
|
155
|
+
if (this.version != version)
|
|
156
|
+
throw err(withErrno('EINVAL', 'Invalid ACL version'));
|
|
157
|
+
for (let offset = sizeof(ACL); offset < this.byteLength; offset += sizeof(Entry)) {
|
|
158
|
+
if (offset + sizeof(Entry) > this.byteLength)
|
|
159
|
+
throw err(withErrno('EIO', 'Invalid ACL data'));
|
|
160
|
+
this.entries.push(new Entry(this.buffer, offset));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
_ACL_version_accessor_storage = new WeakMap();
|
|
165
|
+
__setFunctionName(_classThis, "ACL");
|
|
166
|
+
(() => {
|
|
167
|
+
var _a;
|
|
168
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create((_a = _classSuper[Symbol.metadata]) !== null && _a !== void 0 ? _a : null) : void 0;
|
|
169
|
+
_version_decorators = [(_a = t).uint32.bind(_a)];
|
|
170
|
+
__esDecorate(_classThis, null, _version_decorators, { kind: "accessor", name: "version", static: false, private: false, access: { has: obj => "version" in obj, get: obj => obj.version, set: (obj, value) => { obj.version = value; } }, metadata: _metadata }, _version_initializers, _version_extraInitializers);
|
|
171
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
172
|
+
ACL = _classThis = _classDescriptor.value;
|
|
173
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
174
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
175
|
+
})();
|
|
176
|
+
return ACL = _classThis;
|
|
177
|
+
})();
|
|
178
|
+
export { ACL };
|
|
179
|
+
export function fromMode(mode) {
|
|
180
|
+
const acl = new ACL();
|
|
181
|
+
acl.entries.push(Object.assign(new Entry(), { tag: Tag.UserObj, perm: (mode & S_IRWXU) >> 6 }), Object.assign(new Entry(), { tag: Tag.GroupObj, perm: (mode & S_IRWXG) >> 3 }), Object.assign(new Entry(), { tag: Tag.Other, perm: mode & S_IRWXO }));
|
|
182
|
+
return acl;
|
|
183
|
+
}
|
|
184
|
+
export function toMode(acl) {
|
|
185
|
+
let mode = 0;
|
|
186
|
+
for (const entry of acl.entries) {
|
|
187
|
+
switch (entry.tag) {
|
|
188
|
+
case Tag.UserObj:
|
|
189
|
+
mode |= entry.perm << 6;
|
|
190
|
+
break;
|
|
191
|
+
case Tag.GroupObj:
|
|
192
|
+
mode |= entry.perm << 3;
|
|
193
|
+
break;
|
|
194
|
+
case Tag.Other:
|
|
195
|
+
mode |= entry.perm;
|
|
196
|
+
break;
|
|
197
|
+
case Tag.User:
|
|
198
|
+
case Tag.Group:
|
|
199
|
+
case Tag.Mask:
|
|
200
|
+
case Tag._None:
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return mode;
|
|
205
|
+
}
|
|
206
|
+
export async function get($, path) {
|
|
207
|
+
return new ACL(await xattr.get.call($, path, 'system.posix_acl_access'));
|
|
208
|
+
}
|
|
209
|
+
export function getSync($, path) {
|
|
210
|
+
return new ACL(xattr.getSync.call($, path, 'system.posix_acl_access'));
|
|
211
|
+
}
|
|
212
|
+
export async function set($, path, acl) {
|
|
213
|
+
await xattr.set.call($, path, 'system.posix_acl_access', new Uint8Array(acl.buffer, acl.byteOffset, acl.byteLength));
|
|
214
|
+
}
|
|
215
|
+
export function setSync($, path, acl) {
|
|
216
|
+
xattr.setSync.call($, path, 'system.posix_acl_access', new Uint8Array(acl.buffer, acl.byteOffset, acl.byteLength));
|
|
217
|
+
}
|
|
218
|
+
export let shouldCheck = true;
|
|
219
|
+
export function setChecks(enabled) {
|
|
220
|
+
shouldCheck = enabled;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Checks if a given user/group has access to this item
|
|
224
|
+
* @param access The requested access, combination of `W_OK`, `R_OK`, and `X_OK`
|
|
225
|
+
*/
|
|
226
|
+
export function check($, inode, access) {
|
|
227
|
+
var _a, _b;
|
|
228
|
+
if (!shouldCheck)
|
|
229
|
+
return true;
|
|
230
|
+
(_a = inode.attributes) !== null && _a !== void 0 ? _a : (inode.attributes = new Attributes());
|
|
231
|
+
const { euid, egid } = (_b = $ === null || $ === void 0 ? void 0 : $.credentials) !== null && _b !== void 0 ? _b : defaultContext.credentials;
|
|
232
|
+
const data = inode.attributes.get('system.posix_acl_access');
|
|
233
|
+
if (!data)
|
|
234
|
+
return true;
|
|
235
|
+
const acl = new ACL(data);
|
|
236
|
+
let mask = R_OK | W_OK | X_OK;
|
|
237
|
+
let result = false;
|
|
238
|
+
for (const entry of acl.entries) {
|
|
239
|
+
switch (entry.tag) {
|
|
240
|
+
case Tag.UserObj:
|
|
241
|
+
if (inode.uid == euid && (entry.perm & access) === access)
|
|
242
|
+
result = true;
|
|
243
|
+
break;
|
|
244
|
+
case Tag.User:
|
|
245
|
+
if (entry.id == euid && (entry.perm & mask & access) === access)
|
|
246
|
+
result = true;
|
|
247
|
+
break;
|
|
248
|
+
case Tag.GroupObj:
|
|
249
|
+
if (inode.gid == egid && (entry.perm & mask & access) === access)
|
|
250
|
+
result = true;
|
|
251
|
+
break;
|
|
252
|
+
case Tag.Group:
|
|
253
|
+
if (entry.id == egid && (entry.perm & mask & access) === access)
|
|
254
|
+
result = true;
|
|
255
|
+
break;
|
|
256
|
+
case Tag.Mask:
|
|
257
|
+
mask = entry.perm;
|
|
258
|
+
break;
|
|
259
|
+
case Tag.Other:
|
|
260
|
+
if ((entry.perm & mask & access) === access)
|
|
261
|
+
result = true;
|
|
262
|
+
break;
|
|
263
|
+
case Tag._None:
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return result;
|
|
268
|
+
}
|
package/dist/vfs/async.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type * as fs from 'node:fs';
|
|
2
2
|
import type { V_Context } from '../context.js';
|
|
3
|
-
import type { Stats } from '../stats.js';
|
|
4
3
|
import type { Callback } from '../utils.js';
|
|
5
4
|
import type { Dir, Dirent } from './dir.js';
|
|
5
|
+
import type { Stats } from './stats.js';
|
|
6
6
|
import type { FileContents } from './types.js';
|
|
7
7
|
import { Buffer } from 'buffer';
|
|
8
|
-
import {
|
|
9
|
-
import { BigIntStats } from '
|
|
8
|
+
import { type Exception } from 'kerium';
|
|
9
|
+
import { BigIntStats } from './stats.js';
|
|
10
10
|
import { ReadStream, WriteStream, type ReadStreamOptions, type WriteStreamOptions } from './streams.js';
|
|
11
11
|
import { FSWatcher } from './watchers.js';
|
|
12
12
|
/**
|
|
@@ -16,7 +16,7 @@ export declare function rename(this: V_Context, oldPath: fs.PathLike, newPath: f
|
|
|
16
16
|
/**
|
|
17
17
|
* Test whether or not `path` exists by checking with the file system.
|
|
18
18
|
* Then call the callback argument with either true or false.
|
|
19
|
-
*
|
|
19
|
+
* According to Node.js: deprecated Use {@link stat} or {@link access} instead.
|
|
20
20
|
*/
|
|
21
21
|
export declare function exists(this: V_Context, path: fs.PathLike, cb?: (exists: boolean) => unknown): void;
|
|
22
22
|
export declare function stat(this: V_Context, path: fs.PathLike, callback: Callback<[Stats]>): void;
|
|
@@ -48,25 +48,11 @@ export declare function unlink(this: V_Context, path: fs.PathLike, cb?: Callback
|
|
|
48
48
|
* Exclusive mode ensures that path is newly created.
|
|
49
49
|
* Mode defaults to `0644`
|
|
50
50
|
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* * `'r'` - Open file for reading. An exception occurs if the file does not exist.
|
|
54
|
-
* * `'r+'` - Open file for reading and writing. An exception occurs if the file does not exist.
|
|
55
|
-
* * `'rs'` - Open file for reading in synchronous mode. Instructs the filesystem to not cache writes.
|
|
56
|
-
* * `'rs+'` - Open file for reading and writing, and opens the file in synchronous mode.
|
|
57
|
-
* * `'w'` - Open file for writing. The file is created (if it does not exist) or truncated (if it exists).
|
|
58
|
-
* * `'wx'` - Like 'w' but opens the file in exclusive mode.
|
|
59
|
-
* * `'w+'` - Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists).
|
|
60
|
-
* * `'wx+'` - Like 'w+' but opens the file in exclusive mode.
|
|
61
|
-
* * `'a'` - Open file for appending. The file is created if it does not exist.
|
|
62
|
-
* * `'ax'` - Like 'a' but opens the file in exclusive mode.
|
|
63
|
-
* * `'a+'` - Open file for reading and appending. The file is created if it does not exist.
|
|
64
|
-
* * `'ax+'` - Like 'a+' but opens the file in exclusive mode.
|
|
65
|
-
*
|
|
66
|
-
* @see http://www.manpagez.com/man/2/open/
|
|
51
|
+
* @see https://nodejs.org/api/fs.html#fsopenpath-flags-mode-callback
|
|
52
|
+
* @param flags {@link https://nodejs.org/api/fs.html#file-system-flags}
|
|
67
53
|
*/
|
|
68
|
-
export declare function open(this: V_Context, path: fs.PathLike, flag:
|
|
69
|
-
export declare function open(this: V_Context, path: fs.PathLike, flag:
|
|
54
|
+
export declare function open(this: V_Context, path: fs.PathLike, flag: fs.OpenMode, cb?: Callback<[number]>): void;
|
|
55
|
+
export declare function open(this: V_Context, path: fs.PathLike, flag: fs.OpenMode, mode: number | string, cb?: Callback<[number]>): void;
|
|
70
56
|
/**
|
|
71
57
|
* Asynchronously reads the entire contents of a file.
|
|
72
58
|
* @option encoding The string encoding for the file contents. Defaults to `null`.
|
|
@@ -281,7 +267,7 @@ export declare function statfs(this: V_Context, path: fs.PathLike, options: fs.S
|
|
|
281
267
|
bigint: true;
|
|
282
268
|
}, callback: Callback<[fs.BigIntStatsFs]>): void;
|
|
283
269
|
export declare function openAsBlob(this: V_Context, path: fs.PathLike, options?: fs.OpenAsBlobOptions): Promise<Blob>;
|
|
284
|
-
type GlobCallback<Args extends unknown[]> = (e:
|
|
270
|
+
type GlobCallback<Args extends unknown[]> = (e: Exception | null, ...args: Args) => unknown;
|
|
285
271
|
/**
|
|
286
272
|
* Retrieves the files matching the specified pattern.
|
|
287
273
|
*/
|