@zenfs/core 2.0.0 → 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.js +6 -5
- package/dist/backends/cow.d.ts +2 -2
- package/dist/backends/cow.js +39 -58
- package/dist/backends/fetch.js +27 -29
- package/dist/backends/passthrough.d.ts +2 -3
- package/dist/backends/passthrough.js +84 -199
- package/dist/backends/port.d.ts +16 -3
- package/dist/backends/port.js +61 -30
- package/dist/backends/single_buffer.d.ts +52 -46
- package/dist/backends/single_buffer.js +462 -219
- package/dist/backends/store/fs.d.ts +16 -10
- package/dist/backends/store/fs.js +227 -242
- package/dist/backends/store/store.d.ts +3 -3
- package/dist/backends/store/store.js +11 -10
- package/dist/config.d.ts +2 -2
- package/dist/config.js +10 -11
- package/dist/internal/devices.d.ts +2 -2
- package/dist/internal/devices.js +39 -49
- 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 +9 -9
- package/dist/internal/filesystem.d.ts +23 -8
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index_fs.d.ts +2 -2
- package/dist/internal/index_fs.js +19 -19
- package/dist/internal/inode.d.ts +81 -103
- package/dist/internal/inode.js +336 -195
- package/dist/mixins/async.js +32 -28
- package/dist/mixins/mutexed.d.ts +4 -4
- package/dist/mixins/mutexed.js +39 -39
- package/dist/mixins/readonly.d.ts +2 -2
- package/dist/mixins/readonly.js +20 -20
- package/dist/mixins/sync.js +2 -2
- package/dist/polyfills.js +1 -1
- package/dist/readline.js +1 -1
- package/dist/utils.d.ts +8 -5
- package/dist/utils.js +14 -17
- package/dist/vfs/acl.d.ts +8 -8
- package/dist/vfs/acl.js +66 -47
- package/dist/vfs/async.d.ts +2 -2
- package/dist/vfs/async.js +6 -8
- package/dist/vfs/dir.d.ts +1 -1
- package/dist/vfs/dir.js +3 -4
- package/dist/vfs/file.js +33 -24
- package/dist/vfs/flags.js +3 -3
- package/dist/vfs/ioctl.d.ts +8 -7
- package/dist/vfs/ioctl.js +132 -27
- package/dist/vfs/promises.d.ts +3 -3
- package/dist/vfs/promises.js +200 -235
- package/dist/vfs/shared.d.ts +1 -12
- package/dist/vfs/shared.js +7 -35
- package/dist/vfs/streams.js +9 -9
- package/dist/vfs/sync.d.ts +1 -2
- package/dist/vfs/sync.js +158 -170
- package/dist/vfs/watchers.js +8 -8
- package/dist/vfs/xattr.js +89 -106
- package/package.json +4 -2
- package/scripts/test.js +2 -2
- package/tests/assignment.ts +1 -1
- package/tests/backend/port.test.ts +4 -4
- package/tests/backend/single-buffer.test.ts +39 -10
- package/tests/backend/single-buffer.worker.js +30 -0
- package/tests/common/context.test.ts +2 -2
- package/tests/common/mutex.test.ts +9 -9
- package/tests/fetch/fetch.ts +1 -1
- 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 +3 -2
- package/tests/fs/open.test.ts +4 -21
- package/tests/fs/permissions.test.ts +8 -13
- package/tests/fs/read.test.ts +10 -9
- package/tests/fs/readFile.test.ts +8 -24
- package/tests/fs/rename.test.ts +4 -9
- package/tests/fs/stat.test.ts +2 -2
- package/tests/fs/times.test.ts +6 -6
- 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 +7 -7
- package/tests/logs.js +2 -2
- package/tests/setup/port.ts +6 -0
- package/dist/internal/log.d.ts +0 -139
- package/dist/internal/log.js +0 -219
- package/tests/fs/writeFile.test.ts +0 -70
package/dist/vfs/sync.js
CHANGED
|
@@ -50,44 +50,60 @@ 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
|
-
import { deleteFD, fromFD, SyncHandle, toFD } from './file.js';
|
|
54
|
-
import { Stats } from './stats.js';
|
|
55
53
|
import { Buffer } from 'buffer';
|
|
54
|
+
import { Errno, Exception, setUVMessage, UV } from 'kerium';
|
|
56
55
|
import { decodeUTF8, encodeUTF8 } from 'utilium';
|
|
57
56
|
import { defaultContext } from '../internal/contexts.js';
|
|
58
|
-
import {
|
|
57
|
+
import { wrap } from '../internal/error.js';
|
|
59
58
|
import { hasAccess, isDirectory, isSymbolicLink } from '../internal/inode.js';
|
|
60
59
|
import { dirname, join, parse, resolve } from '../path.js';
|
|
61
|
-
import { normalizeMode, normalizeOptions, normalizePath, normalizeTime } from '../utils.js';
|
|
60
|
+
import { __assertType, normalizeMode, normalizeOptions, normalizePath, normalizeTime } from '../utils.js';
|
|
62
61
|
import { checkAccess } from './config.js';
|
|
63
62
|
import * as constants from './constants.js';
|
|
64
63
|
import { Dir, Dirent } from './dir.js';
|
|
64
|
+
import { deleteFD, fromFD, SyncHandle, toFD } from './file.js';
|
|
65
65
|
import * as flags from './flags.js';
|
|
66
|
-
import { _statfs,
|
|
67
|
-
import { BigIntStats } from './stats.js';
|
|
66
|
+
import { _statfs, resolveMount } from './shared.js';
|
|
67
|
+
import { BigIntStats, Stats } from './stats.js';
|
|
68
68
|
import { emitChange } from './watchers.js';
|
|
69
69
|
export function renameSync(oldPath, newPath) {
|
|
70
70
|
oldPath = normalizePath(oldPath);
|
|
71
|
+
__assertType(oldPath);
|
|
71
72
|
newPath = normalizePath(newPath);
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
__assertType(newPath);
|
|
74
|
+
const src = resolveMount(oldPath, this);
|
|
75
|
+
const dst = resolveMount(newPath, this);
|
|
76
|
+
const $ex = { syscall: 'rename', path: oldPath, dest: newPath };
|
|
77
|
+
if (src.fs !== dst.fs)
|
|
78
|
+
throw UV('EXDEV', $ex);
|
|
79
|
+
if (dst.path.startsWith(src.path + '/'))
|
|
80
|
+
throw UV('EBUSY', $ex);
|
|
81
|
+
const oldStats = statSync.call(this, oldPath);
|
|
82
|
+
const oldParent = statSync.call(this, dirname(oldPath));
|
|
83
|
+
const newParent = statSync.call(this, dirname(newPath));
|
|
84
|
+
let newStats;
|
|
85
|
+
try {
|
|
86
|
+
newStats = statSync.call(this, newPath);
|
|
76
87
|
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
setUVMessage(Object.assign(e, $ex));
|
|
90
|
+
if (e.code != 'ENOENT')
|
|
91
|
+
throw e;
|
|
92
|
+
}
|
|
93
|
+
if (checkAccess && (!oldParent.hasAccess(constants.R_OK, this) || !newParent.hasAccess(constants.W_OK, this)))
|
|
94
|
+
throw UV('EACCES', $ex);
|
|
95
|
+
if (newStats && !isDirectory(oldStats) && isDirectory(newStats))
|
|
96
|
+
throw UV('EISDIR', $ex);
|
|
97
|
+
if (newStats && isDirectory(oldStats) && !isDirectory(newStats))
|
|
98
|
+
throw UV('ENOTDIR', $ex);
|
|
77
99
|
try {
|
|
78
|
-
|
|
79
|
-
oldMount.fs.renameSync(oldMount.path, newMount.path);
|
|
80
|
-
emitChange(this, 'rename', oldPath.toString());
|
|
81
|
-
emitChange(this, 'change', newPath.toString());
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
writeFileSync.call(this, newPath, readFileSync(oldPath));
|
|
85
|
-
unlinkSync.call(this, oldPath);
|
|
86
|
-
emitChange(this, 'rename', oldPath.toString());
|
|
100
|
+
src.fs.renameSync(src.path, dst.path);
|
|
87
101
|
}
|
|
88
102
|
catch (e) {
|
|
89
|
-
throw
|
|
103
|
+
throw setUVMessage(Object.assign(e, $ex));
|
|
90
104
|
}
|
|
105
|
+
emitChange(this, 'rename', oldPath);
|
|
106
|
+
emitChange(this, 'change', newPath);
|
|
91
107
|
}
|
|
92
108
|
renameSync;
|
|
93
109
|
/**
|
|
@@ -100,9 +116,8 @@ export function existsSync(path) {
|
|
|
100
116
|
return fs.existsSync(resolvedPath);
|
|
101
117
|
}
|
|
102
118
|
catch (e) {
|
|
103
|
-
if (e.errno == Errno.ENOENT)
|
|
119
|
+
if (e.errno == Errno.ENOENT)
|
|
104
120
|
return false;
|
|
105
|
-
}
|
|
106
121
|
throw e;
|
|
107
122
|
}
|
|
108
123
|
}
|
|
@@ -110,31 +125,25 @@ existsSync;
|
|
|
110
125
|
export function statSync(path, options) {
|
|
111
126
|
path = normalizePath(path);
|
|
112
127
|
const { fs, path: resolved } = resolveMount(realpathSync.call(this, path), this);
|
|
128
|
+
let stats;
|
|
113
129
|
try {
|
|
114
|
-
|
|
115
|
-
if (checkAccess && !hasAccess(this, stats, constants.R_OK)) {
|
|
116
|
-
throw ErrnoError.With('EACCES', resolved, 'stat');
|
|
117
|
-
}
|
|
118
|
-
return (options === null || options === void 0 ? void 0 : options.bigint) ? new BigIntStats(stats) : new Stats(stats);
|
|
130
|
+
stats = fs.statSync(resolved);
|
|
119
131
|
}
|
|
120
132
|
catch (e) {
|
|
121
|
-
throw
|
|
133
|
+
throw setUVMessage(Object.assign(e, { path }));
|
|
122
134
|
}
|
|
135
|
+
if (checkAccess && !hasAccess(this, stats, constants.R_OK))
|
|
136
|
+
throw UV('EACCES', { syscall: 'stat', path });
|
|
137
|
+
return (options === null || options === void 0 ? void 0 : options.bigint) ? new BigIntStats(stats) : new Stats(stats);
|
|
123
138
|
}
|
|
124
139
|
statSync;
|
|
125
140
|
export function lstatSync(path, options) {
|
|
126
141
|
path = normalizePath(path);
|
|
127
142
|
const { fs, path: resolved } = resolveMount(path, this);
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
return (options === null || options === void 0 ? void 0 : options.bigint) ? new BigIntStats(stats) : new Stats(stats);
|
|
134
|
-
}
|
|
135
|
-
catch (e) {
|
|
136
|
-
throw fixError(e, { [resolved]: path });
|
|
137
|
-
}
|
|
143
|
+
const stats = wrap(fs, 'statSync', path)(resolved);
|
|
144
|
+
if (checkAccess && !hasAccess(this, stats, constants.R_OK))
|
|
145
|
+
throw UV('EACCES', { syscall: 'lstat', path });
|
|
146
|
+
return (options === null || options === void 0 ? void 0 : options.bigint) ? new BigIntStats(stats) : new Stats(stats);
|
|
138
147
|
}
|
|
139
148
|
lstatSync;
|
|
140
149
|
export function truncateSync(path, len = 0) {
|
|
@@ -142,9 +151,8 @@ export function truncateSync(path, len = 0) {
|
|
|
142
151
|
try {
|
|
143
152
|
const file = __addDisposableResource(env_1, _openSync.call(this, path, { flag: 'r+' }), false);
|
|
144
153
|
len || (len = 0);
|
|
145
|
-
if (len < 0)
|
|
146
|
-
throw
|
|
147
|
-
}
|
|
154
|
+
if (len < 0)
|
|
155
|
+
throw UV('EINVAL', 'truncate', path.toString());
|
|
148
156
|
file.truncate(len);
|
|
149
157
|
}
|
|
150
158
|
catch (e_1) {
|
|
@@ -161,14 +169,14 @@ export function unlinkSync(path) {
|
|
|
161
169
|
const { fs, path: resolved } = resolveMount(path, this);
|
|
162
170
|
try {
|
|
163
171
|
if (checkAccess && !hasAccess(this, fs.statSync(resolved), constants.W_OK)) {
|
|
164
|
-
throw
|
|
172
|
+
throw UV('EACCES', 'unlink');
|
|
165
173
|
}
|
|
166
174
|
fs.unlinkSync(resolved);
|
|
167
|
-
emitChange(this, 'rename', path.toString());
|
|
168
175
|
}
|
|
169
176
|
catch (e) {
|
|
170
|
-
throw
|
|
177
|
+
throw setUVMessage(Object.assign(e, { path }));
|
|
171
178
|
}
|
|
179
|
+
emitChange(this, 'rename', path.toString());
|
|
172
180
|
}
|
|
173
181
|
unlinkSync;
|
|
174
182
|
function _openSync(path, opt) {
|
|
@@ -186,20 +194,20 @@ function _openSync(path, opt) {
|
|
|
186
194
|
}
|
|
187
195
|
if (!stats) {
|
|
188
196
|
if (!(flag & constants.O_CREAT)) {
|
|
189
|
-
throw
|
|
197
|
+
throw UV('ENOENT', 'open', path);
|
|
190
198
|
}
|
|
191
199
|
// Create the file
|
|
192
200
|
const parentStats = fs.statSync(dirname(resolved));
|
|
193
201
|
if (checkAccess && !hasAccess(this, parentStats, constants.W_OK)) {
|
|
194
|
-
throw
|
|
202
|
+
throw UV('EACCES', 'open', path);
|
|
195
203
|
}
|
|
196
204
|
if (!isDirectory(parentStats)) {
|
|
197
|
-
throw
|
|
205
|
+
throw UV('ENOTDIR', 'open', path);
|
|
198
206
|
}
|
|
199
207
|
if (!opt.allowDirectory && mode & constants.S_IFDIR)
|
|
200
|
-
throw
|
|
208
|
+
throw UV('EISDIR', 'open', path);
|
|
201
209
|
if (checkAccess && !hasAccess(this, parentStats, constants.W_OK)) {
|
|
202
|
-
throw
|
|
210
|
+
throw UV('EACCES', 'open', path);
|
|
203
211
|
}
|
|
204
212
|
const { euid: uid, egid: gid } = (_a = this === null || this === void 0 ? void 0 : this.credentials) !== null && _a !== void 0 ? _a : defaultContext.credentials;
|
|
205
213
|
const inode = fs.createFileSync(resolved, {
|
|
@@ -210,15 +218,15 @@ function _openSync(path, opt) {
|
|
|
210
218
|
return new SyncHandle(this, path, fs, resolved, flag, inode);
|
|
211
219
|
}
|
|
212
220
|
if (checkAccess && (!hasAccess(this, stats, mode) || !hasAccess(this, stats, flags.toMode(flag)))) {
|
|
213
|
-
throw
|
|
221
|
+
throw UV('EACCES', 'open', path);
|
|
214
222
|
}
|
|
215
223
|
if (flag & constants.O_EXCL)
|
|
216
|
-
throw
|
|
224
|
+
throw UV('EEXIST', 'open', path);
|
|
217
225
|
const file = new SyncHandle(this, path, fs, resolved, flag, stats);
|
|
226
|
+
if (!opt.allowDirectory && stats.mode & constants.S_IFDIR)
|
|
227
|
+
throw UV('EISDIR', 'open', path);
|
|
218
228
|
if (flag & constants.O_TRUNC)
|
|
219
229
|
file.truncate(0);
|
|
220
|
-
if (!opt.allowDirectory && stats.mode & constants.S_IFDIR)
|
|
221
|
-
throw ErrnoError.With('EISDIR', path, '_open');
|
|
222
230
|
return file;
|
|
223
231
|
}
|
|
224
232
|
/**
|
|
@@ -237,14 +245,20 @@ openSync;
|
|
|
237
245
|
export function lopenSync(path, flag, mode) {
|
|
238
246
|
return toFD(_openSync.call(this, path, { flag, mode, preserveSymlinks: true }));
|
|
239
247
|
}
|
|
240
|
-
function
|
|
248
|
+
export function readFileSync(path, _options = {}) {
|
|
241
249
|
const env_2 = { stack: [], error: void 0, hasError: false };
|
|
242
250
|
try {
|
|
243
|
-
const
|
|
251
|
+
const options = normalizeOptions(_options, null, 'r', 0o644);
|
|
252
|
+
const flag = flags.parse(options.flag);
|
|
253
|
+
if (flag & constants.O_WRONLY)
|
|
254
|
+
throw UV('EBADF', 'read', path.toString());
|
|
255
|
+
const file = __addDisposableResource(env_2, typeof path == 'number'
|
|
256
|
+
? fromFD(this, path)
|
|
257
|
+
: _openSync.call(this, path.toString(), { flag: options.flag, mode: 0o644, preserveSymlinks: false }), false);
|
|
244
258
|
const { size } = file.stat();
|
|
245
|
-
const data =
|
|
259
|
+
const data = Buffer.alloc(size);
|
|
246
260
|
file.read(data, 0, size, 0);
|
|
247
|
-
return data;
|
|
261
|
+
return options.encoding ? data.toString(options.encoding) : data;
|
|
248
262
|
}
|
|
249
263
|
catch (e_2) {
|
|
250
264
|
env_2.error = e_2;
|
|
@@ -254,15 +268,6 @@ function _readFileSync(path, flag, preserveSymlinks) {
|
|
|
254
268
|
__disposeResources(env_2);
|
|
255
269
|
}
|
|
256
270
|
}
|
|
257
|
-
export function readFileSync(path, _options = {}) {
|
|
258
|
-
const options = normalizeOptions(_options, null, 'r', 0o644);
|
|
259
|
-
const flag = flags.parse(options.flag);
|
|
260
|
-
if (flag & constants.O_WRONLY) {
|
|
261
|
-
throw new ErrnoError(Errno.EINVAL, 'Flag passed to readFile must allow for reading');
|
|
262
|
-
}
|
|
263
|
-
const data = Buffer.from(_readFileSync.call(this, path, options.flag, false));
|
|
264
|
-
return options.encoding ? data.toString(options.encoding) : data;
|
|
265
|
-
}
|
|
266
271
|
readFileSync;
|
|
267
272
|
export function writeFileSync(path, data, _options = {}) {
|
|
268
273
|
const env_3 = { stack: [], error: void 0, hasError: false };
|
|
@@ -270,14 +275,14 @@ export function writeFileSync(path, data, _options = {}) {
|
|
|
270
275
|
const options = normalizeOptions(_options, 'utf8', 'w+', 0o644);
|
|
271
276
|
const flag = flags.parse(options.flag);
|
|
272
277
|
if (!(flag & constants.O_WRONLY || flag & constants.O_RDWR)) {
|
|
273
|
-
throw new
|
|
278
|
+
throw new Exception(Errno.EINVAL, 'Flag passed to writeFile must allow for writing');
|
|
274
279
|
}
|
|
275
280
|
if (typeof data != 'string' && !options.encoding) {
|
|
276
|
-
throw new
|
|
281
|
+
throw new Exception(Errno.EINVAL, 'Encoding not specified');
|
|
277
282
|
}
|
|
278
283
|
const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding) : new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
279
284
|
if (!encodedData) {
|
|
280
|
-
throw new
|
|
285
|
+
throw new Exception(Errno.EINVAL, 'Data not specified');
|
|
281
286
|
}
|
|
282
287
|
const file = __addDisposableResource(env_3, typeof path == 'number'
|
|
283
288
|
? fromFD(this, path)
|
|
@@ -310,10 +315,10 @@ export function appendFileSync(filename, data, _options = {}) {
|
|
|
310
315
|
const options = normalizeOptions(_options, 'utf8', 'a+', 0o644);
|
|
311
316
|
const flag = flags.parse(options.flag);
|
|
312
317
|
if (!(flag & constants.O_APPEND)) {
|
|
313
|
-
throw new
|
|
318
|
+
throw new Exception(Errno.EINVAL, 'Flag passed to appendFile must allow for appending');
|
|
314
319
|
}
|
|
315
320
|
if (typeof data != 'string' && !options.encoding) {
|
|
316
|
-
throw new
|
|
321
|
+
throw new Exception(Errno.EINVAL, 'Encoding not specified');
|
|
317
322
|
}
|
|
318
323
|
const encodedData = typeof data == 'string' ? Buffer.from(data, options.encoding) : new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
319
324
|
const file = __addDisposableResource(env_4, _openSync.call(this, typeof filename == 'number' ? fromFD(this, filename).path : filename.toString(), {
|
|
@@ -345,7 +350,7 @@ closeSync;
|
|
|
345
350
|
export function ftruncateSync(fd, len = 0) {
|
|
346
351
|
len || (len = 0);
|
|
347
352
|
if (len < 0) {
|
|
348
|
-
throw new
|
|
353
|
+
throw new Exception(Errno.EINVAL);
|
|
349
354
|
}
|
|
350
355
|
fromFD(this, fd).truncate(len);
|
|
351
356
|
}
|
|
@@ -411,7 +416,7 @@ fchownSync;
|
|
|
411
416
|
export function fchmodSync(fd, mode) {
|
|
412
417
|
const numMode = normalizeMode(mode, -1);
|
|
413
418
|
if (numMode < 0) {
|
|
414
|
-
throw new
|
|
419
|
+
throw new Exception(Errno.EINVAL, `Invalid mode.`);
|
|
415
420
|
}
|
|
416
421
|
fromFD(this, fd).chmod(numMode);
|
|
417
422
|
}
|
|
@@ -426,35 +431,26 @@ futimesSync;
|
|
|
426
431
|
export function rmdirSync(path) {
|
|
427
432
|
path = normalizePath(path);
|
|
428
433
|
const { fs, path: resolved } = resolveMount(realpathSync.call(this, path), this);
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
}
|
|
437
|
-
fs.rmdirSync(resolved);
|
|
438
|
-
emitChange(this, 'rename', path.toString());
|
|
439
|
-
}
|
|
440
|
-
catch (e) {
|
|
441
|
-
throw fixError(e, { [resolved]: path });
|
|
442
|
-
}
|
|
434
|
+
const stats = wrap(fs, 'statSync', path)(resolved);
|
|
435
|
+
if (!isDirectory(stats))
|
|
436
|
+
throw UV('ENOTDIR', 'rmdir', path);
|
|
437
|
+
if (checkAccess && !hasAccess(this, stats, constants.W_OK))
|
|
438
|
+
throw UV('EACCES', 'rmdir', path);
|
|
439
|
+
wrap(fs, 'rmdirSync', path)(resolved);
|
|
440
|
+
emitChange(this, 'rename', path.toString());
|
|
443
441
|
}
|
|
444
442
|
rmdirSync;
|
|
445
443
|
export function mkdirSync(path, options) {
|
|
446
|
-
var _a
|
|
444
|
+
var _a;
|
|
447
445
|
const { euid: uid, egid: gid } = (_a = this === null || this === void 0 ? void 0 : this.credentials) !== null && _a !== void 0 ? _a : defaultContext.credentials;
|
|
448
446
|
options = typeof options === 'object' ? options : { mode: options };
|
|
449
447
|
const mode = normalizeMode(options === null || options === void 0 ? void 0 : options.mode, 0o777);
|
|
450
448
|
path = realpathSync.call(this, path);
|
|
451
|
-
const { fs, path: resolved
|
|
452
|
-
const
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
}
|
|
457
|
-
const inode = fs.mkdirSync(path, {
|
|
449
|
+
const { fs, path: resolved } = resolveMount(path, this);
|
|
450
|
+
const __create = (path, resolved, parent) => {
|
|
451
|
+
if (checkAccess && !hasAccess(this, parent, constants.W_OK))
|
|
452
|
+
throw UV('EACCES', 'mkdir', dirname(path));
|
|
453
|
+
const inode = wrap(fs, 'mkdirSync', path)(resolved, {
|
|
458
454
|
mode,
|
|
459
455
|
uid: parent.mode & constants.S_ISUID ? parent.uid : uid,
|
|
460
456
|
gid: parent.mode & constants.S_ISGID ? parent.gid : gid,
|
|
@@ -462,47 +458,33 @@ export function mkdirSync(path, options) {
|
|
|
462
458
|
emitChange(this, 'rename', path);
|
|
463
459
|
return inode;
|
|
464
460
|
};
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
return;
|
|
469
|
-
}
|
|
470
|
-
const dirs = [];
|
|
471
|
-
for (let dir = resolved, original = path; !fs.existsSync(dir); dir = dirname(dir), original = dirname(original)) {
|
|
472
|
-
dirs.unshift(dir);
|
|
473
|
-
errorPaths[dir] = original;
|
|
474
|
-
}
|
|
475
|
-
if (!dirs.length)
|
|
476
|
-
return;
|
|
477
|
-
const stats = [fs.statSync(dirname(dirs[0]))];
|
|
478
|
-
for (const [i, dir] of dirs.entries()) {
|
|
479
|
-
stats.push(__create(dir, stats[i]));
|
|
480
|
-
}
|
|
481
|
-
return root.length == 1 ? dirs[0] : (_b = dirs[0]) === null || _b === void 0 ? void 0 : _b.slice(root.length);
|
|
461
|
+
if (!(options === null || options === void 0 ? void 0 : options.recursive)) {
|
|
462
|
+
__create(path, resolved, wrap(fs, 'statSync', dirname(path))(dirname(resolved)));
|
|
463
|
+
return;
|
|
482
464
|
}
|
|
483
|
-
|
|
484
|
-
|
|
465
|
+
const dirs = [];
|
|
466
|
+
for (let dir = resolved, original = path; !wrap(fs, 'existsSync', original)(dir); dir = dirname(dir), original = dirname(original)) {
|
|
467
|
+
dirs.unshift({ resolved: dir, original });
|
|
468
|
+
}
|
|
469
|
+
if (!dirs.length)
|
|
470
|
+
return;
|
|
471
|
+
const stats = [wrap(fs, 'statSync', dirname(dirs[0].original))(dirname(dirs[0].resolved))];
|
|
472
|
+
for (const [i, dir] of dirs.entries()) {
|
|
473
|
+
stats.push(__create(dir.original, dir.resolved, stats[i]));
|
|
485
474
|
}
|
|
475
|
+
return dirs[0].original;
|
|
486
476
|
}
|
|
487
477
|
mkdirSync;
|
|
488
478
|
export function readdirSync(path, options) {
|
|
489
479
|
options = typeof options === 'object' ? options : { encoding: options };
|
|
490
480
|
path = normalizePath(path);
|
|
491
481
|
const { fs, path: resolved } = resolveMount(realpathSync.call(this, path), this);
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
if (!isDirectory(stats)) {
|
|
499
|
-
throw ErrnoError.With('ENOTDIR', resolved, 'readdir');
|
|
500
|
-
}
|
|
501
|
-
entries = fs.readdirSync(resolved);
|
|
502
|
-
}
|
|
503
|
-
catch (e) {
|
|
504
|
-
throw fixError(e, { [resolved]: path });
|
|
505
|
-
}
|
|
482
|
+
const stats = wrap(fs, 'statSync', path)(resolved);
|
|
483
|
+
if (checkAccess && !hasAccess(this, stats, constants.R_OK))
|
|
484
|
+
throw UV('EACCES', 'readdir', path);
|
|
485
|
+
if (!isDirectory(stats))
|
|
486
|
+
throw UV('ENOTDIR', 'readdir', path);
|
|
487
|
+
const entries = wrap(fs, 'readdirSync', path)(resolved);
|
|
506
488
|
// Iterate over entries and handle recursive case if needed
|
|
507
489
|
const values = [];
|
|
508
490
|
for (const entry of entries) {
|
|
@@ -543,26 +525,21 @@ readdirSync;
|
|
|
543
525
|
export function linkSync(targetPath, linkPath) {
|
|
544
526
|
targetPath = normalizePath(targetPath);
|
|
545
527
|
if (checkAccess && !statSync(dirname(targetPath)).hasAccess(constants.R_OK, this)) {
|
|
546
|
-
throw
|
|
528
|
+
throw UV('EACCES', 'link', dirname(targetPath));
|
|
547
529
|
}
|
|
548
530
|
linkPath = normalizePath(linkPath);
|
|
549
531
|
if (checkAccess && !statSync(dirname(linkPath)).hasAccess(constants.W_OK, this)) {
|
|
550
|
-
throw
|
|
532
|
+
throw UV('EACCES', 'link', dirname(linkPath));
|
|
551
533
|
}
|
|
552
534
|
const { fs, path } = resolveMount(targetPath, this);
|
|
553
535
|
const link = resolveMount(linkPath, this);
|
|
554
536
|
if (fs != link.fs) {
|
|
555
|
-
throw
|
|
556
|
-
}
|
|
557
|
-
try {
|
|
558
|
-
if (checkAccess && !hasAccess(this, fs.statSync(path), constants.R_OK)) {
|
|
559
|
-
throw ErrnoError.With('EACCES', path, 'link');
|
|
560
|
-
}
|
|
561
|
-
return fs.linkSync(path, link.path);
|
|
562
|
-
}
|
|
563
|
-
catch (e) {
|
|
564
|
-
throw fixError(e, { [path]: targetPath, [link.path]: linkPath });
|
|
537
|
+
throw UV('EXDEV', 'link', linkPath);
|
|
565
538
|
}
|
|
539
|
+
const stats = wrap(fs, 'statSync', targetPath)(path);
|
|
540
|
+
if (checkAccess && !hasAccess(this, stats, constants.R_OK))
|
|
541
|
+
throw UV('EACCES', 'link', path);
|
|
542
|
+
return wrap(fs, 'linkSync', targetPath, linkPath)(path, link.path);
|
|
566
543
|
}
|
|
567
544
|
linkSync;
|
|
568
545
|
/**
|
|
@@ -574,9 +551,8 @@ linkSync;
|
|
|
574
551
|
export function symlinkSync(target, path, type = 'file') {
|
|
575
552
|
const env_5 = { stack: [], error: void 0, hasError: false };
|
|
576
553
|
try {
|
|
577
|
-
if (!['file', 'dir', 'junction'].includes(type))
|
|
578
|
-
throw new
|
|
579
|
-
}
|
|
554
|
+
if (!['file', 'dir', 'junction'].includes(type))
|
|
555
|
+
throw new TypeError('Invalid symlink type: ' + type);
|
|
580
556
|
path = normalizePath(path);
|
|
581
557
|
const file = __addDisposableResource(env_5, _openSync.call(this, path, { flag: 'wx', mode: 0o644 }), false);
|
|
582
558
|
file.write(encodeUTF8(normalizePath(target, true)));
|
|
@@ -592,13 +568,28 @@ export function symlinkSync(target, path, type = 'file') {
|
|
|
592
568
|
}
|
|
593
569
|
symlinkSync;
|
|
594
570
|
export function readlinkSync(path, options) {
|
|
595
|
-
const
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
571
|
+
const env_6 = { stack: [], error: void 0, hasError: false };
|
|
572
|
+
try {
|
|
573
|
+
const handle = __addDisposableResource(env_6, _openSync.call(this, normalizePath(path), { flag: 'r', mode: 0o644, preserveSymlinks: true }), false);
|
|
574
|
+
if (!isSymbolicLink(handle.inode))
|
|
575
|
+
throw new Exception(Errno.EINVAL, 'Not a symbolic link: ' + path);
|
|
576
|
+
const size = handle.inode.size;
|
|
577
|
+
const data = Buffer.alloc(size);
|
|
578
|
+
handle.read(data, 0, size, 0);
|
|
579
|
+
const encoding = typeof options == 'object' ? options === null || options === void 0 ? void 0 : options.encoding : options;
|
|
580
|
+
if (encoding == 'buffer') {
|
|
581
|
+
return data;
|
|
582
|
+
}
|
|
583
|
+
// always defaults to utf-8 to avoid wrangler (cloudflare) worker "unknown encoding" exception
|
|
584
|
+
return data.toString(encoding !== null && encoding !== void 0 ? encoding : 'utf-8');
|
|
585
|
+
}
|
|
586
|
+
catch (e_6) {
|
|
587
|
+
env_6.error = e_6;
|
|
588
|
+
env_6.hasError = true;
|
|
589
|
+
}
|
|
590
|
+
finally {
|
|
591
|
+
__disposeResources(env_6);
|
|
599
592
|
}
|
|
600
|
-
// always defaults to utf-8 to avoid wrangler (cloudflare) worker "unknown encoding" exception
|
|
601
|
-
return value.toString(encoding !== null && encoding !== void 0 ? encoding : 'utf-8');
|
|
602
593
|
}
|
|
603
594
|
readlinkSync;
|
|
604
595
|
export function chownSync(path, uid, gid) {
|
|
@@ -673,20 +664,20 @@ function _resolveSync($, path, preserveSymlinks) {
|
|
|
673
664
|
const realDir = dir == '/' ? '/' : realpathSync.call($, dir);
|
|
674
665
|
const maybePath = join(realDir, base);
|
|
675
666
|
const resolved = resolveMount(maybePath, $);
|
|
667
|
+
let stats;
|
|
676
668
|
try {
|
|
677
|
-
|
|
678
|
-
if (!isSymbolicLink(stats)) {
|
|
679
|
-
return { ...resolved, fullPath: maybePath, stats };
|
|
680
|
-
}
|
|
681
|
-
const target = resolve.call($, realDir, readlinkSync.call($, maybePath).toString());
|
|
682
|
-
return _resolveSync($, target);
|
|
669
|
+
stats = resolved.fs.statSync(resolved.path);
|
|
683
670
|
}
|
|
684
671
|
catch (e) {
|
|
685
|
-
if (e.code
|
|
672
|
+
if (e.code === 'ENOENT')
|
|
686
673
|
return { ...resolved, fullPath: path };
|
|
687
|
-
}
|
|
688
|
-
throw fixError(e, { [resolved.path]: maybePath });
|
|
674
|
+
throw setUVMessage(Object.assign(e, { syscall: 'stat', path: maybePath }));
|
|
689
675
|
}
|
|
676
|
+
if (!isSymbolicLink(stats)) {
|
|
677
|
+
return { ...resolved, fullPath: maybePath, stats };
|
|
678
|
+
}
|
|
679
|
+
const target = resolve.call($, realDir, readlinkSync.call($, maybePath).toString());
|
|
680
|
+
return _resolveSync($, target);
|
|
690
681
|
}
|
|
691
682
|
export function realpathSync(path, options) {
|
|
692
683
|
var _a;
|
|
@@ -705,7 +696,7 @@ export function accessSync(path, mode = 0o600) {
|
|
|
705
696
|
if (!checkAccess)
|
|
706
697
|
return;
|
|
707
698
|
if (!hasAccess(this, statSync.call(this, path), mode)) {
|
|
708
|
-
throw new
|
|
699
|
+
throw new Exception(Errno.EACCES);
|
|
709
700
|
}
|
|
710
701
|
}
|
|
711
702
|
accessSync;
|
|
@@ -743,7 +734,7 @@ export function rmSync(path, options) {
|
|
|
743
734
|
case constants.S_IFIFO:
|
|
744
735
|
case constants.S_IFSOCK:
|
|
745
736
|
default:
|
|
746
|
-
throw
|
|
737
|
+
throw UV('ENOSYS', 'rm', path);
|
|
747
738
|
}
|
|
748
739
|
}
|
|
749
740
|
rmSync;
|
|
@@ -763,9 +754,8 @@ mkdtempSync;
|
|
|
763
754
|
export function copyFileSync(source, destination, flags) {
|
|
764
755
|
source = normalizePath(source);
|
|
765
756
|
destination = normalizePath(destination);
|
|
766
|
-
if (flags && flags & constants.COPYFILE_EXCL && existsSync(destination))
|
|
767
|
-
throw
|
|
768
|
-
}
|
|
757
|
+
if (flags && flags & constants.COPYFILE_EXCL && existsSync(destination))
|
|
758
|
+
throw UV('EEXIST', 'copyFile', destination);
|
|
769
759
|
writeFileSync.call(this, destination, readFileSync(source));
|
|
770
760
|
emitChange(this, 'rename', destination.toString());
|
|
771
761
|
}
|
|
@@ -830,14 +820,12 @@ export function cpSync(source, destination, opts) {
|
|
|
830
820
|
source = normalizePath(source);
|
|
831
821
|
destination = normalizePath(destination);
|
|
832
822
|
const srcStats = lstatSync.call(this, source); // Use lstat to follow symlinks if not dereferencing
|
|
833
|
-
if ((opts === null || opts === void 0 ? void 0 : opts.errorOnExist) && existsSync.call(this, destination))
|
|
834
|
-
throw
|
|
835
|
-
}
|
|
823
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.errorOnExist) && existsSync.call(this, destination))
|
|
824
|
+
throw UV('EEXIST', 'cp', destination);
|
|
836
825
|
switch (srcStats.mode & constants.S_IFMT) {
|
|
837
826
|
case constants.S_IFDIR:
|
|
838
|
-
if (!(opts === null || opts === void 0 ? void 0 : opts.recursive))
|
|
839
|
-
throw
|
|
840
|
-
}
|
|
827
|
+
if (!(opts === null || opts === void 0 ? void 0 : opts.recursive))
|
|
828
|
+
throw UV('EISDIR', 'cp', source);
|
|
841
829
|
mkdirSync.call(this, destination, { recursive: true }); // Ensure the destination directory exists
|
|
842
830
|
for (const dirent of readdirSync.call(this, source, { withFileTypes: true })) {
|
|
843
831
|
if (opts.filter && !opts.filter(join(source, dirent.name), join(destination, dirent.name))) {
|
|
@@ -855,7 +843,7 @@ export function cpSync(source, destination, opts) {
|
|
|
855
843
|
case constants.S_IFIFO:
|
|
856
844
|
case constants.S_IFSOCK:
|
|
857
845
|
default:
|
|
858
|
-
throw
|
|
846
|
+
throw UV('ENOSYS', 'cp', source);
|
|
859
847
|
}
|
|
860
848
|
// Optionally preserve timestamps
|
|
861
849
|
if (opts === null || opts === void 0 ? void 0 : opts.preserveTimestamps) {
|
package/dist/vfs/watchers.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { EventEmitter } from 'eventemitter3';
|
|
2
|
-
import {
|
|
3
|
-
import { isStatsEqual } from './stats.js';
|
|
4
|
-
import { normalizePath } from '../utils.js';
|
|
2
|
+
import { UV } from 'kerium';
|
|
5
3
|
import { basename, dirname, join, relative } from '../path.js';
|
|
4
|
+
import { normalizePath } from '../utils.js';
|
|
5
|
+
import { isStatsEqual } from './stats.js';
|
|
6
6
|
import { statSync } from './sync.js';
|
|
7
7
|
/**
|
|
8
8
|
* Base class for file system watchers.
|
|
@@ -29,19 +29,19 @@ class Watcher extends EventEmitter {
|
|
|
29
29
|
this.path = path;
|
|
30
30
|
}
|
|
31
31
|
setMaxListeners() {
|
|
32
|
-
throw
|
|
32
|
+
throw UV('ENOSYS', 'Watcher.setMaxListeners');
|
|
33
33
|
}
|
|
34
34
|
getMaxListeners() {
|
|
35
|
-
throw
|
|
35
|
+
throw UV('ENOSYS', 'Watcher.getMaxListeners');
|
|
36
36
|
}
|
|
37
37
|
prependListener() {
|
|
38
|
-
throw
|
|
38
|
+
throw UV('ENOSYS', 'Watcher.prependListener');
|
|
39
39
|
}
|
|
40
40
|
prependOnceListener() {
|
|
41
|
-
throw
|
|
41
|
+
throw UV('ENOSYS', 'Watcher.prependOnceListener');
|
|
42
42
|
}
|
|
43
43
|
rawListeners() {
|
|
44
|
-
throw
|
|
44
|
+
throw UV('ENOSYS', 'Watcher.rawListeners');
|
|
45
45
|
}
|
|
46
46
|
ref() {
|
|
47
47
|
return this;
|