@zenfs/core 2.3.10 → 2.4.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/LICENSE.md +157 -0
- package/dist/backends/backend.js +1 -0
- package/dist/backends/fetch.js +1 -0
- package/dist/backends/index.js +1 -0
- package/dist/backends/passthrough.js +1 -0
- package/dist/backends/single_buffer.js +1 -0
- package/dist/backends/store/fs.js +1 -0
- package/dist/backends/store/store.js +1 -0
- package/dist/config.d.ts +5 -0
- package/dist/config.js +12 -0
- package/dist/context.js +1 -0
- package/dist/index.js +1 -0
- package/dist/internal/devices.js +1 -0
- package/dist/internal/error.js +1 -0
- package/dist/internal/file_index.js +1 -0
- package/dist/internal/filesystem.d.ts +1 -0
- package/dist/internal/index.js +1 -0
- package/dist/internal/index_fs.d.ts +2 -0
- package/dist/internal/index_fs.js +38 -8
- package/dist/internal/inode.js +1 -0
- package/dist/mixins/index.js +1 -0
- package/dist/mixins/mutexed.d.ts +1 -1
- package/dist/mixins/mutexed.js +2 -2
- package/dist/mixins/readonly.js +1 -0
- package/dist/mixins/shared.js +1 -0
- package/dist/path.js +1 -0
- package/dist/polyfills.js +1 -0
- package/dist/readline.js +1 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +7 -0
- package/dist/vfs/acl.js +1 -0
- package/dist/vfs/config.js +1 -0
- package/dist/vfs/constants.js +1 -0
- package/dist/vfs/dir.js +5 -1
- package/dist/vfs/file.js +1 -0
- package/dist/vfs/flags.js +1 -0
- package/dist/vfs/index.js +1 -0
- package/dist/vfs/ioctl.js +1 -0
- package/dist/vfs/promises.d.ts +15 -3
- package/dist/vfs/promises.js +19 -7
- package/dist/vfs/shared.js +1 -0
- package/dist/vfs/sync.d.ts +14 -2
- package/dist/vfs/sync.js +17 -5
- package/dist/vfs/xattr.js +1 -0
- package/package.json +6 -4
- package/tests/assignment.ts +1 -0
- package/tests/backend/fetch.test.ts +1 -0
- package/tests/backend/port.test.ts +2 -1
- package/tests/backend/single-buffer.test.ts +1 -0
- package/tests/common/casefold.test.ts +1 -0
- package/tests/common/context.test.ts +1 -0
- package/tests/common/devices.test.ts +1 -0
- package/tests/common/handle.test.ts +1 -0
- package/tests/common/inode.test.ts +1 -0
- package/tests/common/mounts.test.ts +1 -0
- package/tests/common/mutex.test.ts +4 -3
- package/tests/common/path.test.ts +1 -0
- package/tests/common/readline.test.ts +1 -0
- package/tests/common.ts +1 -0
- package/{license.md → tests/data-license.md} +0 -2
- package/tests/fs/append.test.ts +1 -0
- package/tests/fs/dir.test.ts +1 -0
- package/tests/fs/directory.test.ts +1 -0
- package/tests/fs/errors.test.ts +1 -0
- package/tests/fs/exists.test.ts +1 -0
- package/tests/fs/links.test.ts +1 -0
- package/tests/fs/open.test.ts +1 -0
- package/tests/fs/permissions.test.ts +1 -0
- package/tests/fs/read.test.ts +1 -0
- package/tests/fs/readFile.test.ts +1 -0
- package/tests/fs/rename.test.ts +1 -0
- package/tests/fs/scaling.test.ts +1 -0
- package/tests/fs/stat.test.ts +1 -0
- package/tests/fs/streams.test.ts +1 -0
- package/tests/fs/tempdir.test.ts +41 -0
- package/tests/fs/times.test.ts +1 -0
- package/tests/fs/truncate.test.ts +1 -0
- package/tests/fs/watch.test.ts +1 -0
- package/tests/fs/write.test.ts +1 -0
- package/tests/fs/xattr.test.ts +1 -0
- package/tests/setup.ts +1 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
|
|
3
|
+
Version 3, 29 June 2007
|
|
4
|
+
|
|
5
|
+
Copyright (C) 2007 Free Software Foundation, Inc.
|
|
6
|
+
<https://fsf.org/>
|
|
7
|
+
|
|
8
|
+
Everyone is permitted to copy and distribute verbatim copies of this
|
|
9
|
+
license document, but changing it is not allowed.
|
|
10
|
+
|
|
11
|
+
This version of the GNU Lesser General Public License incorporates the
|
|
12
|
+
terms and conditions of version 3 of the GNU General Public License,
|
|
13
|
+
supplemented by the additional permissions listed below.
|
|
14
|
+
|
|
15
|
+
## 0. Additional Definitions.
|
|
16
|
+
|
|
17
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
18
|
+
General Public License, and the "GNU GPL" refers to version 3 of the
|
|
19
|
+
GNU General Public License.
|
|
20
|
+
|
|
21
|
+
"The Library" refers to a covered work governed by this License, other
|
|
22
|
+
than an Application or a Combined Work as defined below.
|
|
23
|
+
|
|
24
|
+
An "Application" is any work that makes use of an interface provided
|
|
25
|
+
by the Library, but which is not otherwise based on the Library.
|
|
26
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
27
|
+
of using an interface provided by the Library.
|
|
28
|
+
|
|
29
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
30
|
+
Application with the Library. The particular version of the Library
|
|
31
|
+
with which the Combined Work was made is also called the "Linked
|
|
32
|
+
Version".
|
|
33
|
+
|
|
34
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
35
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
36
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
37
|
+
based on the Application, and not on the Linked Version.
|
|
38
|
+
|
|
39
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
40
|
+
object code and/or source code for the Application, including any data
|
|
41
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
42
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
43
|
+
|
|
44
|
+
## 1. Exception to Section 3 of the GNU GPL.
|
|
45
|
+
|
|
46
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
47
|
+
without being bound by section 3 of the GNU GPL.
|
|
48
|
+
|
|
49
|
+
## 2. Conveying Modified Versions.
|
|
50
|
+
|
|
51
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
52
|
+
facility refers to a function or data to be supplied by an Application
|
|
53
|
+
that uses the facility (other than as an argument passed when the
|
|
54
|
+
facility is invoked), then you may convey a copy of the modified
|
|
55
|
+
version:
|
|
56
|
+
|
|
57
|
+
- a) under this License, provided that you make a good faith effort
|
|
58
|
+
to ensure that, in the event an Application does not supply the
|
|
59
|
+
function or data, the facility still operates, and performs
|
|
60
|
+
whatever part of its purpose remains meaningful, or
|
|
61
|
+
- b) under the GNU GPL, with none of the additional permissions of
|
|
62
|
+
this License applicable to that copy.
|
|
63
|
+
|
|
64
|
+
## 3. Object Code Incorporating Material from Library Header Files.
|
|
65
|
+
|
|
66
|
+
The object code form of an Application may incorporate material from a
|
|
67
|
+
header file that is part of the Library. You may convey such object
|
|
68
|
+
code under terms of your choice, provided that, if the incorporated
|
|
69
|
+
material is not limited to numerical parameters, data structure
|
|
70
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
71
|
+
(ten or fewer lines in length), you do both of the following:
|
|
72
|
+
|
|
73
|
+
- a) Give prominent notice with each copy of the object code that
|
|
74
|
+
the Library is used in it and that the Library and its use are
|
|
75
|
+
covered by this License.
|
|
76
|
+
- b) Accompany the object code with a copy of the GNU GPL and this
|
|
77
|
+
license document.
|
|
78
|
+
|
|
79
|
+
## 4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that, taken
|
|
82
|
+
together, effectively do not restrict modification of the portions of
|
|
83
|
+
the Library contained in the Combined Work and reverse engineering for
|
|
84
|
+
debugging such modifications, if you also do each of the following:
|
|
85
|
+
|
|
86
|
+
- a) Give prominent notice with each copy of the Combined Work that
|
|
87
|
+
the Library is used in it and that the Library and its use are
|
|
88
|
+
covered by this License.
|
|
89
|
+
- b) Accompany the Combined Work with a copy of the GNU GPL and this
|
|
90
|
+
license document.
|
|
91
|
+
- c) For a Combined Work that displays copyright notices during
|
|
92
|
+
execution, include the copyright notice for the Library among
|
|
93
|
+
these notices, as well as a reference directing the user to the
|
|
94
|
+
copies of the GNU GPL and this license document.
|
|
95
|
+
- d) Do one of the following:
|
|
96
|
+
- 0) Convey the Minimal Corresponding Source under the terms of
|
|
97
|
+
this License, and the Corresponding Application Code in a form
|
|
98
|
+
suitable for, and under terms that permit, the user to
|
|
99
|
+
recombine or relink the Application with a modified version of
|
|
100
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
101
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
102
|
+
Corresponding Source.
|
|
103
|
+
- 1) Use a suitable shared library mechanism for linking with
|
|
104
|
+
the Library. A suitable mechanism is one that (a) uses at run
|
|
105
|
+
time a copy of the Library already present on the user's
|
|
106
|
+
computer system, and (b) will operate properly with a modified
|
|
107
|
+
version of the Library that is interface-compatible with the
|
|
108
|
+
Linked Version.
|
|
109
|
+
- e) Provide Installation Information, but only if you would
|
|
110
|
+
otherwise be required to provide such information under section 6
|
|
111
|
+
of the GNU GPL, and only to the extent that such information is
|
|
112
|
+
necessary to install and execute a modified version of the
|
|
113
|
+
Combined Work produced by recombining or relinking the Application
|
|
114
|
+
with a modified version of the Linked Version. (If you use option
|
|
115
|
+
4d0, the Installation Information must accompany the Minimal
|
|
116
|
+
Corresponding Source and Corresponding Application Code. If you
|
|
117
|
+
use option 4d1, you must provide the Installation Information in
|
|
118
|
+
the manner specified by section 6 of the GNU GPL for conveying
|
|
119
|
+
Corresponding Source.)
|
|
120
|
+
|
|
121
|
+
## 5. Combined Libraries.
|
|
122
|
+
|
|
123
|
+
You may place library facilities that are a work based on the Library
|
|
124
|
+
side by side in a single library together with other library
|
|
125
|
+
facilities that are not Applications and are not covered by this
|
|
126
|
+
License, and convey such a combined library under terms of your
|
|
127
|
+
choice, if you do both of the following:
|
|
128
|
+
|
|
129
|
+
- a) Accompany the combined library with a copy of the same work
|
|
130
|
+
based on the Library, uncombined with any other library
|
|
131
|
+
facilities, conveyed under the terms of this License.
|
|
132
|
+
- b) Give prominent notice with the combined library that part of it
|
|
133
|
+
is a work based on the Library, and explaining where to find the
|
|
134
|
+
accompanying uncombined form of the same work.
|
|
135
|
+
|
|
136
|
+
## 6. Revised Versions of the GNU Lesser General Public License.
|
|
137
|
+
|
|
138
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
139
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
140
|
+
versions will be similar in spirit to the present version, but may
|
|
141
|
+
differ in detail to address new problems or concerns.
|
|
142
|
+
|
|
143
|
+
Each version is given a distinguishing version number. If the Library
|
|
144
|
+
as you received it specifies that a certain numbered version of the
|
|
145
|
+
GNU Lesser General Public License "or any later version" applies to
|
|
146
|
+
it, you have the option of following the terms and conditions either
|
|
147
|
+
of that published version or of any later version published by the
|
|
148
|
+
Free Software Foundation. If the Library as you received it does not
|
|
149
|
+
specify a version number of the GNU Lesser General Public License, you
|
|
150
|
+
may choose any version of the GNU Lesser General Public License ever
|
|
151
|
+
published by the Free Software Foundation.
|
|
152
|
+
|
|
153
|
+
If the Library as you received it specifies that a proxy can decide
|
|
154
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
155
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
156
|
+
permanent authorization for you to choose that version for the
|
|
157
|
+
Library.
|
package/dist/backends/backend.js
CHANGED
package/dist/backends/fetch.js
CHANGED
package/dist/backends/index.js
CHANGED
|
@@ -50,6 +50,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
50
50
|
var e = new Error(message);
|
|
51
51
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
52
|
});
|
|
53
|
+
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
53
54
|
import { err, warn } from 'kerium/log';
|
|
54
55
|
import { FileSystem } from '../internal/filesystem.js';
|
|
55
56
|
import { isDirectory } from '../internal/inode.js';
|
|
@@ -84,6 +84,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
84
84
|
var e = new Error(message);
|
|
85
85
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
86
86
|
});
|
|
87
|
+
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
87
88
|
import { withErrno } from 'kerium';
|
|
88
89
|
import { alert, crit, err, warn } from 'kerium/log';
|
|
89
90
|
import { array, offsetof, packed, sizeof } from 'memium';
|
|
@@ -50,6 +50,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
50
50
|
var e = new Error(message);
|
|
51
51
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
52
|
});
|
|
53
|
+
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
53
54
|
import { withErrno } from 'kerium';
|
|
54
55
|
import { crit, debug, err, notice, warn } from 'kerium/log';
|
|
55
56
|
import { sizeof } from 'memium';
|
package/dist/config.d.ts
CHANGED
|
@@ -51,6 +51,11 @@ export interface Configuration<T extends ConfigMounts> extends SharedConfig {
|
|
|
51
51
|
* @default false
|
|
52
52
|
*/
|
|
53
53
|
addDevices: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Whether to automatically create some directories (e.g. /tmp)
|
|
56
|
+
* @default false
|
|
57
|
+
*/
|
|
58
|
+
defaultDirectories: boolean;
|
|
54
59
|
/**
|
|
55
60
|
* If true, disables *all* permissions checking.
|
|
56
61
|
*
|
package/dist/config.js
CHANGED
|
@@ -101,6 +101,7 @@ export function addDevice(driver, options) {
|
|
|
101
101
|
throw log.crit(withErrno('ENOTSUP', '/dev does not exist or is not a device file system'));
|
|
102
102
|
return devfs._createDevice(driver, options);
|
|
103
103
|
}
|
|
104
|
+
const _defaultDirectories = ['/tmp', '/var', '/etc'];
|
|
104
105
|
/**
|
|
105
106
|
* Configures ZenFS with `configuration`
|
|
106
107
|
* @category Backends and Configuration
|
|
@@ -136,6 +137,17 @@ export async function configure(configuration) {
|
|
|
136
137
|
await devfs.ready();
|
|
137
138
|
await mount('/dev', devfs);
|
|
138
139
|
}
|
|
140
|
+
if (configuration.defaultDirectories) {
|
|
141
|
+
for (const dir of _defaultDirectories) {
|
|
142
|
+
if (await fs.promises.exists(dir)) {
|
|
143
|
+
const stats = await fs.promises.stat(dir);
|
|
144
|
+
if (!stats.isDirectory())
|
|
145
|
+
log.warn('Default directory exists but is not a directory: ' + dir);
|
|
146
|
+
}
|
|
147
|
+
else
|
|
148
|
+
await fs.promises.mkdir(dir);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
139
151
|
}
|
|
140
152
|
export async function sync() {
|
|
141
153
|
for (const fs of mounts.values())
|
package/dist/context.js
CHANGED
package/dist/index.js
CHANGED
package/dist/internal/devices.js
CHANGED
package/dist/internal/error.js
CHANGED
package/dist/internal/index.js
CHANGED
|
@@ -30,6 +30,8 @@ export declare abstract class IndexFS extends FileSystem {
|
|
|
30
30
|
protected create(path: string, options: CreationOptions): Inode;
|
|
31
31
|
createFile(path: string, options: CreationOptions): Promise<InodeLike>;
|
|
32
32
|
createFileSync(path: string, options: CreationOptions): InodeLike;
|
|
33
|
+
protected _mkdir?(path: string, options: CreationOptions): Promise<void>;
|
|
34
|
+
protected _mkdirSync?(path: string, options: CreationOptions): void;
|
|
33
35
|
mkdir(path: string, options: CreationOptions): Promise<InodeLike>;
|
|
34
36
|
mkdirSync(path: string, options: CreationOptions): InodeLike;
|
|
35
37
|
link(target: string, link: string): Promise<void>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
1
2
|
/* eslint-disable @typescript-eslint/require-await */
|
|
2
3
|
import { withErrno } from 'kerium';
|
|
3
4
|
import { _throw } from 'utilium';
|
|
@@ -38,31 +39,56 @@ export class IndexFS extends FileSystem {
|
|
|
38
39
|
to = to.slice(0, -1);
|
|
39
40
|
toRename.push({ from, to, inode });
|
|
40
41
|
}
|
|
42
|
+
toRename.sort((a, b) => b.from.length - a.from.length);
|
|
41
43
|
return toRename;
|
|
42
44
|
}
|
|
43
45
|
async rename(oldPath, newPath) {
|
|
44
46
|
if (oldPath == newPath)
|
|
45
47
|
return;
|
|
46
|
-
|
|
48
|
+
const toRename = this.pathsForRename(oldPath, newPath);
|
|
49
|
+
const contents = new Map();
|
|
50
|
+
for (const { from, to, inode } of toRename) {
|
|
47
51
|
const data = new Uint8Array(inode.size);
|
|
48
52
|
await this.read(from, data, 0, inode.size);
|
|
53
|
+
contents.set(to, data);
|
|
49
54
|
this.index.delete(from);
|
|
55
|
+
await this.remove(from);
|
|
56
|
+
if (this.index.has(to))
|
|
57
|
+
await this.remove(to);
|
|
58
|
+
}
|
|
59
|
+
toRename.reverse();
|
|
60
|
+
for (const { to, inode } of toRename) {
|
|
61
|
+
const data = contents.get(to);
|
|
50
62
|
this.index.set(to, inode);
|
|
51
|
-
|
|
63
|
+
if ((inode.mode & S_IFMT) == S_IFDIR)
|
|
64
|
+
await this._mkdir?.(to, inode);
|
|
65
|
+
else
|
|
66
|
+
await this.write(to, data, 0);
|
|
52
67
|
}
|
|
53
|
-
await this.remove(oldPath);
|
|
54
68
|
}
|
|
55
69
|
renameSync(oldPath, newPath) {
|
|
56
70
|
if (oldPath == newPath)
|
|
57
71
|
return;
|
|
58
|
-
|
|
72
|
+
const toRename = this.pathsForRename(oldPath, newPath);
|
|
73
|
+
const contents = new Map();
|
|
74
|
+
for (const { from, to, inode } of toRename) {
|
|
59
75
|
const data = new Uint8Array(inode.size);
|
|
60
76
|
this.readSync(from, data, 0, inode.size);
|
|
77
|
+
contents.set(to, data);
|
|
61
78
|
this.index.delete(from);
|
|
79
|
+
this.removeSync(from);
|
|
80
|
+
if (this.index.has(to))
|
|
81
|
+
this.removeSync(to);
|
|
82
|
+
}
|
|
83
|
+
toRename.reverse();
|
|
84
|
+
for (const { to, inode } of toRename) {
|
|
85
|
+
const data = contents.get(to);
|
|
62
86
|
this.index.set(to, inode);
|
|
63
|
-
|
|
87
|
+
if ((inode.mode & S_IFMT) == S_IFDIR)
|
|
88
|
+
this._mkdirSync?.(to, inode);
|
|
89
|
+
else
|
|
90
|
+
this.writeSync(to, data, 0);
|
|
64
91
|
}
|
|
65
|
-
this.removeSync(oldPath);
|
|
66
92
|
}
|
|
67
93
|
async stat(path) {
|
|
68
94
|
const inode = this.index.get(path);
|
|
@@ -148,11 +174,15 @@ export class IndexFS extends FileSystem {
|
|
|
148
174
|
}
|
|
149
175
|
async mkdir(path, options) {
|
|
150
176
|
options.mode |= S_IFDIR;
|
|
151
|
-
|
|
177
|
+
const inode = this.create(path, options);
|
|
178
|
+
await this._mkdir?.(path, options);
|
|
179
|
+
return inode;
|
|
152
180
|
}
|
|
153
181
|
mkdirSync(path, options) {
|
|
154
182
|
options.mode |= S_IFDIR;
|
|
155
|
-
|
|
183
|
+
const inode = this.create(path, options);
|
|
184
|
+
this._mkdirSync?.(path, options);
|
|
185
|
+
return inode;
|
|
156
186
|
}
|
|
157
187
|
link(target, link) {
|
|
158
188
|
throw withErrno('ENOSYS');
|
package/dist/internal/inode.js
CHANGED
|
@@ -32,6 +32,7 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
|
|
|
32
32
|
}
|
|
33
33
|
return useValue ? value : void 0;
|
|
34
34
|
};
|
|
35
|
+
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
35
36
|
import { withErrno } from 'kerium';
|
|
36
37
|
import { crit, warn } from 'kerium/log';
|
|
37
38
|
import { sizeof } from 'memium';
|
package/dist/mixins/index.js
CHANGED
package/dist/mixins/mutexed.d.ts
CHANGED
|
@@ -49,7 +49,7 @@ export declare class _MutexedFS<T extends FileSystem> implements FileSystem {
|
|
|
49
49
|
* If the path is currently locked, waits for it to be unlocked.
|
|
50
50
|
* @internal
|
|
51
51
|
*/
|
|
52
|
-
lock(): Promise<MutexLock>;
|
|
52
|
+
lock(timeout?: number): Promise<MutexLock>;
|
|
53
53
|
/**
|
|
54
54
|
* Locks `path` asynchronously.
|
|
55
55
|
* If the path is currently locked, an error will be thrown
|
package/dist/mixins/mutexed.js
CHANGED
|
@@ -135,7 +135,7 @@ export class _MutexedFS {
|
|
|
135
135
|
* If the path is currently locked, waits for it to be unlocked.
|
|
136
136
|
* @internal
|
|
137
137
|
*/
|
|
138
|
-
async lock() {
|
|
138
|
+
async lock(timeout = 5000) {
|
|
139
139
|
const previous = this.currentLock;
|
|
140
140
|
const lock = this.addLock();
|
|
141
141
|
const stack = new Error().stack;
|
|
@@ -145,7 +145,7 @@ export class _MutexedFS {
|
|
|
145
145
|
error.stack += stack?.slice('Error'.length);
|
|
146
146
|
throw err(error);
|
|
147
147
|
}
|
|
148
|
-
},
|
|
148
|
+
}, timeout);
|
|
149
149
|
await previous?.done();
|
|
150
150
|
return lock;
|
|
151
151
|
}
|
package/dist/mixins/readonly.js
CHANGED
package/dist/mixins/shared.js
CHANGED
package/dist/path.js
CHANGED
package/dist/polyfills.js
CHANGED
package/dist/readline.js
CHANGED
package/dist/utils.d.ts
CHANGED
|
@@ -59,3 +59,7 @@ export declare function normalizeOptions(options: fs.WriteFileOptions | (fs.Enco
|
|
|
59
59
|
*/
|
|
60
60
|
export declare function globToRegex(pattern: string): RegExp;
|
|
61
61
|
export declare function waitOnline(worker: NodeWorker): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* @internal @hidden
|
|
64
|
+
*/
|
|
65
|
+
export declare function _tempDirName(prefix: fs.PathLike): string;
|
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
1
2
|
import { withErrno } from 'kerium';
|
|
2
3
|
import { decodeUTF8, encodeUTF8 } from 'utilium';
|
|
3
4
|
import { resolve } from './path.js';
|
|
@@ -114,3 +115,9 @@ export async function waitOnline(worker) {
|
|
|
114
115
|
worker.on('online', online.resolve);
|
|
115
116
|
await online.promise;
|
|
116
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* @internal @hidden
|
|
120
|
+
*/
|
|
121
|
+
export function _tempDirName(prefix) {
|
|
122
|
+
return `/tmp/${normalizePath(prefix, true)}${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
123
|
+
}
|
package/dist/vfs/acl.js
CHANGED
|
@@ -32,6 +32,7 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
|
|
|
32
32
|
}
|
|
33
33
|
return useValue ? value : void 0;
|
|
34
34
|
};
|
|
35
|
+
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
35
36
|
/*
|
|
36
37
|
Access Control Lists.
|
|
37
38
|
At the moment, they are only intended for internal use.
|
package/dist/vfs/config.js
CHANGED
package/dist/vfs/constants.js
CHANGED
package/dist/vfs/dir.js
CHANGED
|
@@ -35,7 +35,7 @@ var __runInitializers = (this && this.__runInitializers) || function (thisArg, i
|
|
|
35
35
|
import { Buffer } from 'buffer';
|
|
36
36
|
import { withErrno } from 'kerium';
|
|
37
37
|
import { warn } from 'kerium/log';
|
|
38
|
-
import {
|
|
38
|
+
import { sizeof } from 'memium';
|
|
39
39
|
import { $from, struct, types as t } from 'memium/decorators';
|
|
40
40
|
import { encodeUTF8 } from 'utilium';
|
|
41
41
|
import { BufferView } from 'utilium/buffer.js';
|
|
@@ -252,9 +252,13 @@ export class Dir {
|
|
|
252
252
|
return this;
|
|
253
253
|
}
|
|
254
254
|
[Symbol.dispose]() {
|
|
255
|
+
if (this.closed)
|
|
256
|
+
return;
|
|
255
257
|
this.closeSync();
|
|
256
258
|
}
|
|
257
259
|
async [Symbol.asyncDispose]() {
|
|
260
|
+
if (this.closed)
|
|
261
|
+
return;
|
|
258
262
|
await this.close();
|
|
259
263
|
}
|
|
260
264
|
}
|
package/dist/vfs/file.js
CHANGED
package/dist/vfs/flags.js
CHANGED
package/dist/vfs/index.js
CHANGED
package/dist/vfs/ioctl.js
CHANGED
package/dist/vfs/promises.d.ts
CHANGED
|
@@ -359,9 +359,9 @@ export declare function lutimes(this: V_Context, path: fs.PathLike, atime: fs.Ti
|
|
|
359
359
|
*/
|
|
360
360
|
export declare function realpath(this: V_Context, path: fs.PathLike, options: fs.BufferEncodingOption): Promise<Buffer>;
|
|
361
361
|
export declare function realpath(this: V_Context, path: fs.PathLike, options?: fs.EncodingOption | BufferEncoding): Promise<string>;
|
|
362
|
-
export declare function watch(this: V_Context, filename: fs.PathLike, options?: fs.WatchOptions | BufferEncoding): AsyncIteratorObject<promises.FileChangeInfo<string
|
|
363
|
-
export declare function watch(this: V_Context, filename: fs.PathLike, options: fs.WatchOptions | fs.BufferEncodingOption): AsyncIteratorObject<promises.FileChangeInfo<Buffer
|
|
364
|
-
export declare function watch(this: V_Context, filename: fs.PathLike, options?: fs.WatchOptions | string): AsyncIteratorObject<promises.FileChangeInfo<string
|
|
362
|
+
export declare function watch(this: V_Context, filename: fs.PathLike, options?: fs.WatchOptions | BufferEncoding): AsyncIteratorObject<promises.FileChangeInfo<string>, undefined>;
|
|
363
|
+
export declare function watch(this: V_Context, filename: fs.PathLike, options: fs.WatchOptions | fs.BufferEncodingOption): AsyncIteratorObject<promises.FileChangeInfo<Buffer>, undefined>;
|
|
364
|
+
export declare function watch(this: V_Context, filename: fs.PathLike, options?: fs.WatchOptions | string): AsyncIteratorObject<promises.FileChangeInfo<string>, undefined> | AsyncIteratorObject<promises.FileChangeInfo<Buffer>, undefined>;
|
|
365
365
|
export declare function access(this: V_Context, path: fs.PathLike, mode?: number): Promise<void>;
|
|
366
366
|
/**
|
|
367
367
|
* Asynchronous `rm`. Removes files or directories (recursively).
|
|
@@ -376,6 +376,18 @@ export declare function rm(this: V_Context, path: fs.PathLike, options?: fs.RmOp
|
|
|
376
376
|
*/
|
|
377
377
|
export declare function mkdtemp(this: V_Context, prefix: string, options?: fs.EncodingOption): Promise<string>;
|
|
378
378
|
export declare function mkdtemp(this: V_Context, prefix: string, options?: fs.BufferEncodingOption): Promise<Buffer>;
|
|
379
|
+
/**
|
|
380
|
+
* The resulting Promise holds an async-disposable object whose `path` property holds the created directory path.
|
|
381
|
+
* When the object is disposed, the directory and its contents will be removed asynchronously if it still exists.
|
|
382
|
+
* If the directory cannot be deleted, disposal will throw an error.
|
|
383
|
+
* The object has an async `remove()` method which will perform the same task.
|
|
384
|
+
* @todo Add `satisfies` and maybe change return type once @types/node adds this.
|
|
385
|
+
*/
|
|
386
|
+
export declare function mkdtempDisposable(this: V_Context, prefix: fs.PathLike, options?: fs.EncodingOption | fs.BufferEncodingOption): Promise<{
|
|
387
|
+
path: string;
|
|
388
|
+
remove(): Promise<void>;
|
|
389
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
390
|
+
}>;
|
|
379
391
|
/**
|
|
380
392
|
* Asynchronous `copyFile`. Copies a file.
|
|
381
393
|
* @param src The source file.
|
package/dist/vfs/promises.js
CHANGED
|
@@ -57,7 +57,7 @@ import { hasAccess, InodeFlags, isBlockDevice, isCharacterDevice, isDirectory, i
|
|
|
57
57
|
import { basename, dirname, join, matchesGlob, parse, resolve } from '../path.js';
|
|
58
58
|
import '../polyfills.js';
|
|
59
59
|
import { createInterface } from '../readline.js';
|
|
60
|
-
import { __assertType, globToRegex, normalizeMode, normalizeOptions, normalizePath, normalizeTime } from '../utils.js';
|
|
60
|
+
import { __assertType, _tempDirName, globToRegex, normalizeMode, normalizeOptions, normalizePath, normalizeTime } from '../utils.js';
|
|
61
61
|
import { checkAccess } from './config.js';
|
|
62
62
|
import * as constants from './constants.js';
|
|
63
63
|
import { Dir, Dirent } from './dir.js';
|
|
@@ -1062,12 +1062,12 @@ export function watch(filename, options = {}) {
|
|
|
1062
1062
|
resolve({ value: null, done });
|
|
1063
1063
|
}
|
|
1064
1064
|
eventQueue.length = 0; // Clear the queue
|
|
1065
|
-
return Promise.resolve({ value:
|
|
1065
|
+
return Promise.resolve({ value: undefined, done: true });
|
|
1066
1066
|
}
|
|
1067
1067
|
return {
|
|
1068
1068
|
async next() {
|
|
1069
1069
|
if (done)
|
|
1070
|
-
return Promise.resolve({ value:
|
|
1070
|
+
return Promise.resolve({ value: undefined, done });
|
|
1071
1071
|
const { promise, resolve } = Promise.withResolvers();
|
|
1072
1072
|
eventQueue.push(resolve);
|
|
1073
1073
|
return promise;
|
|
@@ -1128,12 +1128,24 @@ export async function rm(path, options) {
|
|
|
1128
1128
|
rm;
|
|
1129
1129
|
export async function mkdtemp(prefix, options) {
|
|
1130
1130
|
const encoding = typeof options === 'object' ? options?.encoding : options || 'utf8';
|
|
1131
|
-
const
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
return encoding == 'buffer' ? Buffer.from(resolvedPath) : resolvedPath;
|
|
1131
|
+
const path = _tempDirName(prefix);
|
|
1132
|
+
await mkdir.call(this, path);
|
|
1133
|
+
return encoding == 'buffer' ? Buffer.from(path) : path;
|
|
1135
1134
|
}
|
|
1136
1135
|
mkdtemp;
|
|
1136
|
+
/**
|
|
1137
|
+
* The resulting Promise holds an async-disposable object whose `path` property holds the created directory path.
|
|
1138
|
+
* When the object is disposed, the directory and its contents will be removed asynchronously if it still exists.
|
|
1139
|
+
* If the directory cannot be deleted, disposal will throw an error.
|
|
1140
|
+
* The object has an async `remove()` method which will perform the same task.
|
|
1141
|
+
* @todo Add `satisfies` and maybe change return type once @types/node adds this.
|
|
1142
|
+
*/
|
|
1143
|
+
export async function mkdtempDisposable(prefix, options) {
|
|
1144
|
+
const path = _tempDirName(prefix);
|
|
1145
|
+
await mkdir.call(this, path);
|
|
1146
|
+
const remove = () => rm(path, { recursive: true, force: true });
|
|
1147
|
+
return { path, remove, [Symbol.asyncDispose]: remove };
|
|
1148
|
+
}
|
|
1137
1149
|
/**
|
|
1138
1150
|
* Asynchronous `copyFile`. Copies a file.
|
|
1139
1151
|
* @param src The source file.
|
package/dist/vfs/shared.js
CHANGED
package/dist/vfs/sync.d.ts
CHANGED
|
@@ -173,8 +173,20 @@ export declare function rmSync(this: V_Context, path: fs.PathLike, options?: fs.
|
|
|
173
173
|
* @param options The encoding (or an object including `encoding`).
|
|
174
174
|
* @returns The path to the created temporary directory, encoded as a string or buffer.
|
|
175
175
|
*/
|
|
176
|
-
export declare function mkdtempSync(this: V_Context, prefix:
|
|
177
|
-
export declare function mkdtempSync(this: V_Context, prefix:
|
|
176
|
+
export declare function mkdtempSync(this: V_Context, prefix: fs.PathLike, options: fs.BufferEncodingOption): Buffer;
|
|
177
|
+
export declare function mkdtempSync(this: V_Context, prefix: fs.PathLike, options?: fs.EncodingOption): string;
|
|
178
|
+
/**
|
|
179
|
+
* Returns a disposable object whose `path` property holds the created directory path.
|
|
180
|
+
* When the object is disposed, the directory and its contents will be removed if it still exists.
|
|
181
|
+
* If the directory cannot be deleted, disposal will throw an error.
|
|
182
|
+
* The object has a `remove()` method which will perform the same task.
|
|
183
|
+
* @todo Add `satisfies` and maybe change return type once @types/node adds this.
|
|
184
|
+
*/
|
|
185
|
+
export declare function mkdtempDisposableSync(this: V_Context, prefix: fs.PathLike, options?: fs.EncodingOption | fs.BufferEncodingOption): {
|
|
186
|
+
path: string;
|
|
187
|
+
remove(): void;
|
|
188
|
+
[Symbol.dispose](): void;
|
|
189
|
+
};
|
|
178
190
|
/**
|
|
179
191
|
* Synchronous `copyFile`. Copies a file.
|
|
180
192
|
* @param flags Optional flags for the copy operation. Currently supports these flags:
|
package/dist/vfs/sync.js
CHANGED
|
@@ -57,7 +57,7 @@ import { defaultContext } from '../internal/contexts.js';
|
|
|
57
57
|
import { wrap } from '../internal/error.js';
|
|
58
58
|
import { hasAccess, isDirectory, isSymbolicLink } from '../internal/inode.js';
|
|
59
59
|
import { basename, dirname, join, matchesGlob, parse, resolve } from '../path.js';
|
|
60
|
-
import { __assertType, globToRegex, normalizeMode, normalizeOptions, normalizePath, normalizeTime } from '../utils.js';
|
|
60
|
+
import { __assertType, _tempDirName, globToRegex, normalizeMode, normalizeOptions, normalizePath, normalizeTime } from '../utils.js';
|
|
61
61
|
import { checkAccess } from './config.js';
|
|
62
62
|
import * as constants from './constants.js';
|
|
63
63
|
import { Dir, Dirent } from './dir.js';
|
|
@@ -733,12 +733,24 @@ export function rmSync(path, options) {
|
|
|
733
733
|
rmSync;
|
|
734
734
|
export function mkdtempSync(prefix, options) {
|
|
735
735
|
const encoding = typeof options === 'object' ? options?.encoding : options || 'utf8';
|
|
736
|
-
const
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
return encoding == 'buffer' ? Buffer.from(resolvedPath) : resolvedPath;
|
|
736
|
+
const path = _tempDirName(prefix);
|
|
737
|
+
mkdirSync.call(this, path);
|
|
738
|
+
return encoding == 'buffer' ? Buffer.from(path) : path;
|
|
740
739
|
}
|
|
741
740
|
mkdtempSync;
|
|
741
|
+
/**
|
|
742
|
+
* Returns a disposable object whose `path` property holds the created directory path.
|
|
743
|
+
* When the object is disposed, the directory and its contents will be removed if it still exists.
|
|
744
|
+
* If the directory cannot be deleted, disposal will throw an error.
|
|
745
|
+
* The object has a `remove()` method which will perform the same task.
|
|
746
|
+
* @todo Add `satisfies` and maybe change return type once @types/node adds this.
|
|
747
|
+
*/
|
|
748
|
+
export function mkdtempDisposableSync(prefix, options) {
|
|
749
|
+
const path = _tempDirName(prefix);
|
|
750
|
+
mkdirSync.call(this, path);
|
|
751
|
+
const remove = () => rmSync(path, { recursive: true, force: true });
|
|
752
|
+
return { path, remove, [Symbol.dispose]: remove };
|
|
753
|
+
}
|
|
742
754
|
/**
|
|
743
755
|
* Synchronous `copyFile`. Copies a file.
|
|
744
756
|
* @param flags Optional flags for the copy operation. Currently supports these flags:
|
package/dist/vfs/xattr.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenfs/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "A filesystem, anywhere",
|
|
5
5
|
"funding": {
|
|
6
6
|
"type": "individual",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"contributors": [
|
|
32
32
|
"John Vilk <jvilk@cs.umass.edu>"
|
|
33
33
|
],
|
|
34
|
-
"license": "
|
|
34
|
+
"license": "LGPL-3.0-or-later",
|
|
35
35
|
"repository": {
|
|
36
36
|
"type": "git",
|
|
37
37
|
"url": "git+https://github.com/zen-fs/core.git"
|
|
@@ -59,8 +59,10 @@
|
|
|
59
59
|
"scripts": {
|
|
60
60
|
"format": "prettier --write .",
|
|
61
61
|
"format:check": "prettier --check .",
|
|
62
|
+
"spdx:check": "npx lice -a src tests/*.ts tests/**/*.test.ts",
|
|
63
|
+
"spdx:fix": "npx lice -aw src tests/*.ts tests/**/*.test.ts",
|
|
62
64
|
"lint": "eslint src tests",
|
|
63
|
-
"test": "npx zenfs-test --clean; npx zenfs-test -
|
|
65
|
+
"test": "npx zenfs-test --clean; npx zenfs-test -abcp; tests/fetch/run.sh; npx zenfs-test --report",
|
|
64
66
|
"build": "tsc -p tsconfig.json",
|
|
65
67
|
"build:docs": "typedoc",
|
|
66
68
|
"dev": "npm run build -- --watch",
|
|
@@ -73,7 +75,7 @@
|
|
|
73
75
|
"kerium": "^1.3.4",
|
|
74
76
|
"memium": "^0.3.7",
|
|
75
77
|
"readable-stream": "^4.5.2",
|
|
76
|
-
"utilium": "^2.
|
|
78
|
+
"utilium": "^2.5.0"
|
|
77
79
|
},
|
|
78
80
|
"devDependencies": {
|
|
79
81
|
"@eslint/js": "^9.8.0",
|
package/tests/assignment.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
1
2
|
import assert from 'node:assert/strict';
|
|
2
3
|
import { after, suite, test } from 'node:test';
|
|
3
4
|
import { MessageChannel, Worker } from 'node:worker_threads';
|
|
@@ -12,7 +13,7 @@ setupLogs();
|
|
|
12
13
|
const timeoutChannel = new MessageChannel();
|
|
13
14
|
timeoutChannel.port2.unref();
|
|
14
15
|
|
|
15
|
-
await suite('Timeout',
|
|
16
|
+
await suite('Timeout', () => {
|
|
16
17
|
test('Misconfiguration', async () => {
|
|
17
18
|
const configured = configure({
|
|
18
19
|
mounts: {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
1
2
|
import assert from 'node:assert/strict';
|
|
2
3
|
import { suite, test } from 'node:test';
|
|
3
4
|
import { wait } from 'utilium';
|
|
@@ -20,11 +21,11 @@ suite('Mutexed FS', () => {
|
|
|
20
21
|
let lock1Resolved = false;
|
|
21
22
|
let lock2Resolved = false;
|
|
22
23
|
|
|
23
|
-
const lock1 = fs.lock().then(lock => {
|
|
24
|
+
const lock1 = fs.lock(100).then(lock => {
|
|
24
25
|
lock1Resolved = true;
|
|
25
26
|
lock.unlock();
|
|
26
27
|
});
|
|
27
|
-
const lock2 = fs.lock().then(lock => {
|
|
28
|
+
const lock2 = fs.lock(100).then(lock => {
|
|
28
29
|
lock2Resolved = true;
|
|
29
30
|
lock.unlock();
|
|
30
31
|
});
|
|
@@ -50,7 +51,7 @@ suite('Mutexed FS', () => {
|
|
|
50
51
|
let x = 1;
|
|
51
52
|
|
|
52
53
|
async function foo() {
|
|
53
|
-
const lock = await fs.lock();
|
|
54
|
+
const lock = await fs.lock(100);
|
|
54
55
|
await wait(25);
|
|
55
56
|
x++;
|
|
56
57
|
lock.unlock();
|
package/tests/common.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
Copyright (c) James Prevett and other ZenFS contributors.
|
|
2
|
-
Copyright (c) 2013-2023 John Vilk and other BrowserFS contributors.
|
|
3
1
|
Copyright (c) Joyent, Inc. and other Node contributors for `test/data`.
|
|
4
2
|
|
|
5
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
package/tests/fs/append.test.ts
CHANGED
package/tests/fs/dir.test.ts
CHANGED
package/tests/fs/errors.test.ts
CHANGED
package/tests/fs/exists.test.ts
CHANGED
package/tests/fs/links.test.ts
CHANGED
package/tests/fs/open.test.ts
CHANGED
package/tests/fs/read.test.ts
CHANGED
package/tests/fs/rename.test.ts
CHANGED
package/tests/fs/scaling.test.ts
CHANGED
package/tests/fs/stat.test.ts
CHANGED
package/tests/fs/streams.test.ts
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
2
|
+
import { test, suite } from 'node:test';
|
|
3
|
+
import { fs } from '../common.js';
|
|
4
|
+
import assert from 'node:assert/strict';
|
|
5
|
+
import { basename } from 'node:path/posix';
|
|
6
|
+
|
|
7
|
+
await fs.promises.mkdir('/tmp');
|
|
8
|
+
|
|
9
|
+
suite('Temporary Directories', () => {
|
|
10
|
+
test('mkdtempSync', () => {
|
|
11
|
+
const path = fs.mkdtempSync('test-', { encoding: 'utf8' });
|
|
12
|
+
|
|
13
|
+
assert.deepEqual(fs.readdirSync('/tmp'), [basename(path)]);
|
|
14
|
+
|
|
15
|
+
fs.rmdirSync(path);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('mkdtemp', async () => {
|
|
19
|
+
const path = await fs.promises.mkdtemp('test-', { encoding: 'utf8' });
|
|
20
|
+
|
|
21
|
+
assert.deepEqual(await fs.promises.readdir('/tmp'), [basename(path)]);
|
|
22
|
+
|
|
23
|
+
await fs.promises.rmdir(path);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('mkdtempDisposableSync', () => {
|
|
27
|
+
using result = fs.mkdtempDisposableSync('test-', { encoding: 'utf8' });
|
|
28
|
+
|
|
29
|
+
assert.deepEqual(fs.readdirSync('/tmp'), [basename(result.path)]);
|
|
30
|
+
|
|
31
|
+
fs.rmdirSync(result.path);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('mkdtempDisposable', async () => {
|
|
35
|
+
await using result = await fs.promises.mkdtempDisposable('test-', { encoding: 'utf8' });
|
|
36
|
+
|
|
37
|
+
assert.deepEqual(await fs.promises.readdir('/tmp'), [basename(result.path)]);
|
|
38
|
+
|
|
39
|
+
await fs.promises.rmdir(result.path);
|
|
40
|
+
});
|
|
41
|
+
});
|
package/tests/fs/times.test.ts
CHANGED
package/tests/fs/watch.test.ts
CHANGED
package/tests/fs/write.test.ts
CHANGED
package/tests/fs/xattr.test.ts
CHANGED
package/tests/setup.ts
CHANGED