@zenfs/core 0.12.1 → 0.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/backends/index/fs.d.ts +1 -0
- package/dist/backends/overlay.js +1 -1
- package/dist/backends/port/fs.d.ts +1 -0
- package/dist/browser.min.js +4 -8
- package/dist/browser.min.js.map +3 -3
- package/dist/emulation/async.d.ts +4 -4
- package/dist/emulation/index.d.ts +1 -1
- package/dist/emulation/index.js +1 -1
- package/dist/emulation/promises.d.ts +4 -4
- package/dist/emulation/promises.js +33 -45
- package/dist/emulation/shared.d.ts +6 -0
- package/dist/emulation/shared.js +19 -1
- package/dist/emulation/sync.d.ts +4 -4
- package/dist/emulation/sync.js +86 -60
- package/dist/file.d.ts +5 -10
- package/dist/file.js +30 -47
- package/dist/filesystem.d.ts +23 -1
- package/dist/filesystem.js +2 -2
- package/dist/stats.d.ts +16 -16
- package/dist/stats.js +42 -49
- package/package.json +1 -1
- package/src/backends/overlay.ts +1 -1
- package/src/emulation/async.ts +6 -6
- package/src/emulation/index.ts +1 -1
- package/src/emulation/promises.ts +39 -48
- package/src/emulation/shared.ts +22 -1
- package/src/emulation/sync.ts +89 -71
- package/src/file.ts +30 -49
- package/src/filesystem.ts +29 -2
- package/src/stats.ts +46 -58
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { Buffer } from 'buffer';
|
|
5
5
|
import type * as fs from 'node:fs';
|
|
6
6
|
import type { FileContents } from '../filesystem.js';
|
|
7
|
-
import { BigIntStats, type
|
|
7
|
+
import { BigIntStats, type Stats } from '../stats.js';
|
|
8
8
|
import { type Callback } from '../utils.js';
|
|
9
9
|
import { Dirent, type Dir } from './dir.js';
|
|
10
10
|
import * as promises from './promises.js';
|
|
@@ -441,12 +441,12 @@ export declare function opendir(path: fs.PathLike, cb: Callback<[Dir]>): void;
|
|
|
441
441
|
export declare function opendir(path: fs.PathLike, options: fs.OpenDirOptions, cb: Callback<[Dir]>): void;
|
|
442
442
|
export declare function cp(source: fs.PathLike, destination: fs.PathLike, callback: Callback): void;
|
|
443
443
|
export declare function cp(source: fs.PathLike, destination: fs.PathLike, opts: fs.CopyOptions, callback: Callback): void;
|
|
444
|
-
export declare function statfs(path: fs.PathLike, callback: Callback<[StatsFs]>): void;
|
|
444
|
+
export declare function statfs(path: fs.PathLike, callback: Callback<[fs.StatsFs]>): void;
|
|
445
445
|
export declare function statfs(path: fs.PathLike, options: fs.StatFsOptions & {
|
|
446
446
|
bigint?: false;
|
|
447
|
-
}, callback: Callback<[StatsFs]>): void;
|
|
447
|
+
}, callback: Callback<[fs.StatsFs]>): void;
|
|
448
448
|
export declare function statfs(path: fs.PathLike, options: fs.StatFsOptions & {
|
|
449
449
|
bigint: true;
|
|
450
|
-
}, callback: Callback<[BigIntStatsFs]>): void;
|
|
450
|
+
}, callback: Callback<[fs.BigIntStatsFs]>): void;
|
|
451
451
|
export declare function openAsBlob(path: fs.PathLike, options?: fs.OpenAsBlobOptions): Promise<Blob>;
|
|
452
452
|
export {};
|
|
@@ -5,4 +5,4 @@ export * as constants from './constants.js';
|
|
|
5
5
|
export * from './streams.js';
|
|
6
6
|
export * from './dir.js';
|
|
7
7
|
export { mountObject, mounts, mount, umount } from './shared.js';
|
|
8
|
-
export { Stats,
|
|
8
|
+
export { Stats, StatsFs, BigIntStatsFs } from '../stats.js';
|
package/dist/emulation/index.js
CHANGED
|
@@ -5,4 +5,4 @@ export * as constants from './constants.js';
|
|
|
5
5
|
export * from './streams.js';
|
|
6
6
|
export * from './dir.js';
|
|
7
7
|
export { mountObject, mounts, mount, umount } from './shared.js';
|
|
8
|
-
export { Stats,
|
|
8
|
+
export { Stats, StatsFs, BigIntStatsFs } from '../stats.js';
|
|
@@ -14,7 +14,7 @@ import type { ReadableStream as TReadableStream } from 'node:stream/web';
|
|
|
14
14
|
import type { Interface as ReadlineInterface } from 'readline';
|
|
15
15
|
import { File } from '../file.js';
|
|
16
16
|
import type { FileContents } from '../filesystem.js';
|
|
17
|
-
import { BigIntStats, type
|
|
17
|
+
import { BigIntStats, type Stats } from '../stats.js';
|
|
18
18
|
import { Dir, Dirent } from './dir.js';
|
|
19
19
|
import { ReadStream, WriteStream } from './streams.js';
|
|
20
20
|
export * as constants from './constants.js';
|
|
@@ -437,8 +437,8 @@ export declare function cp(source: fs.PathLike, destination: fs.PathLike, opts?:
|
|
|
437
437
|
*/
|
|
438
438
|
export declare function statfs(path: fs.PathLike, opts?: fs.StatFsOptions & {
|
|
439
439
|
bigint?: false;
|
|
440
|
-
}): Promise<StatsFs>;
|
|
440
|
+
}): Promise<fs.StatsFs>;
|
|
441
441
|
export declare function statfs(path: fs.PathLike, opts: fs.StatFsOptions & {
|
|
442
442
|
bigint: true;
|
|
443
|
-
}): Promise<BigIntStatsFs>;
|
|
444
|
-
export declare function statfs(path: fs.PathLike, opts?: fs.StatFsOptions): Promise<StatsFs | BigIntStatsFs>;
|
|
443
|
+
}): Promise<fs.BigIntStatsFs>;
|
|
444
|
+
export declare function statfs(path: fs.PathLike, opts?: fs.StatFsOptions): Promise<fs.StatsFs | fs.BigIntStatsFs>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
|
-
import {
|
|
2
|
+
import { Errno, ErrnoError } from '../error.js';
|
|
3
3
|
import { ActionType, isAppendable, isReadable, isWriteable, parseFlag, pathExistsAction, pathNotExistsAction } from '../file.js';
|
|
4
4
|
import { BigIntStats, FileType } from '../stats.js';
|
|
5
5
|
import { normalizeMode, normalizeOptions, normalizePath, normalizeTime } from '../utils.js';
|
|
6
6
|
import * as constants from './constants.js';
|
|
7
7
|
import { Dir, Dirent } from './dir.js';
|
|
8
8
|
import { dirname, join, parse } from './path.js';
|
|
9
|
-
import { cred, fd2file, fdMap, file2fd, fixError, mounts, resolveMount } from './shared.js';
|
|
9
|
+
import { _statfs, cred, fd2file, fdMap, file2fd, fixError, mounts, resolveMount } from './shared.js';
|
|
10
10
|
import { ReadStream, WriteStream } from './streams.js';
|
|
11
11
|
export * as constants from './constants.js';
|
|
12
12
|
export class FileHandle {
|
|
@@ -386,54 +386,40 @@ async function _open(path, _flag, _mode = 0o644, resolveSymlinks) {
|
|
|
386
386
|
const mode = normalizeMode(_mode, 0o644), flag = parseFlag(_flag);
|
|
387
387
|
path = resolveSymlinks && (await exists(path)) ? await realpath(path) : path;
|
|
388
388
|
const { fs, path: resolved } = resolveMount(path);
|
|
389
|
-
|
|
390
|
-
switch (
|
|
389
|
+
if (!(await fs.exists(path, cred))) {
|
|
390
|
+
switch (pathNotExistsAction(flag)) {
|
|
391
|
+
case ActionType.CREATE:
|
|
392
|
+
// Ensure parent exists.
|
|
393
|
+
const parentStats = await fs.stat(dirname(resolved), cred);
|
|
394
|
+
if (parentStats && !parentStats.isDirectory()) {
|
|
395
|
+
throw ErrnoError.With('ENOTDIR', dirname(path), '_open');
|
|
396
|
+
}
|
|
397
|
+
return new FileHandle(await fs.createFile(resolved, flag, mode, cred));
|
|
391
398
|
case ActionType.THROW:
|
|
392
|
-
throw ErrnoError.With('
|
|
393
|
-
|
|
394
|
-
|
|
399
|
+
throw ErrnoError.With('ENOENT', path, '_open');
|
|
400
|
+
default:
|
|
401
|
+
throw new ErrnoError(Errno.EINVAL, 'Invalid file flag');
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
switch (pathExistsAction(flag)) {
|
|
405
|
+
case ActionType.THROW:
|
|
406
|
+
throw ErrnoError.With('EEXIST', path, '_open');
|
|
407
|
+
case ActionType.TRUNCATE:
|
|
408
|
+
/*
|
|
395
409
|
In a previous implementation, we deleted the file and
|
|
396
410
|
re-created it. However, this created a race condition if another
|
|
397
411
|
asynchronous request was trying to read the file, as the file
|
|
398
412
|
would not exist for a small period of time.
|
|
399
413
|
*/
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
catch (_) {
|
|
412
|
-
const original = _;
|
|
413
|
-
if (original.code != 'ENOENT') {
|
|
414
|
-
throw original;
|
|
415
|
-
}
|
|
416
|
-
try {
|
|
417
|
-
switch (pathNotExistsAction(flag)) {
|
|
418
|
-
case ActionType.CREATE:
|
|
419
|
-
// Ensure parent exists.
|
|
420
|
-
const parentStats = await fs.stat(dirname(resolved), cred);
|
|
421
|
-
if (parentStats && !parentStats.isDirectory()) {
|
|
422
|
-
throw ErrnoError.With('ENOTDIR', dirname(path), '_open');
|
|
423
|
-
}
|
|
424
|
-
return new FileHandle(await fs.createFile(resolved, flag, mode, cred));
|
|
425
|
-
case ActionType.THROW:
|
|
426
|
-
throw ErrnoError.With('ENOENT', path, '_open');
|
|
427
|
-
default:
|
|
428
|
-
throw new ErrnoError(Errno.EINVAL, 'Invalid file flag');
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
catch (_) {
|
|
432
|
-
const ex = _;
|
|
433
|
-
ex.stack += '\n<original>\n';
|
|
434
|
-
ex.stack += original.stack;
|
|
435
|
-
throw ex;
|
|
436
|
-
}
|
|
414
|
+
const file = await fs.openFile(resolved, flag, cred);
|
|
415
|
+
await file.truncate(0);
|
|
416
|
+
await file.sync();
|
|
417
|
+
return new FileHandle(file);
|
|
418
|
+
case ActionType.NOP:
|
|
419
|
+
// Must await so thrown errors are caught by the catch below
|
|
420
|
+
return new FileHandle(await fs.openFile(resolved, flag, cred));
|
|
421
|
+
default:
|
|
422
|
+
throw new ErrnoError(Errno.EINVAL, 'Invalid file flag');
|
|
437
423
|
}
|
|
438
424
|
}
|
|
439
425
|
/**
|
|
@@ -859,5 +845,7 @@ export async function cp(source, destination, opts) {
|
|
|
859
845
|
}
|
|
860
846
|
cp;
|
|
861
847
|
export async function statfs(path, opts) {
|
|
862
|
-
|
|
848
|
+
path = normalizePath(path);
|
|
849
|
+
const { fs } = resolveMount(path);
|
|
850
|
+
return _statfs(fs, opts?.bigint);
|
|
863
851
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import type { BigIntStatsFs, StatsFs } from 'node:fs';
|
|
1
3
|
import { Cred } from '../cred.js';
|
|
2
4
|
import type { File } from '../file.js';
|
|
3
5
|
import { FileSystem } from '../filesystem.js';
|
|
@@ -35,3 +37,7 @@ export declare function resolveMount(path: string): {
|
|
|
35
37
|
export declare function fixPaths(text: string, paths: Record<string, string>): string;
|
|
36
38
|
export declare function fixError<E extends Error>(e: E, paths: Record<string, string>): E;
|
|
37
39
|
export declare function mountObject(mounts: MountObject): void;
|
|
40
|
+
/**
|
|
41
|
+
* @hidden
|
|
42
|
+
*/
|
|
43
|
+
export declare function _statfs<const T extends boolean>(fs: FileSystem, bigint?: T): T extends true ? BigIntStatsFs : StatsFs;
|
package/dist/emulation/shared.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// Utilities and shared data
|
|
2
|
-
import { ErrnoError, Errno } from '../error.js';
|
|
3
2
|
import { InMemory } from '../backends/memory.js';
|
|
4
3
|
import { rootCred } from '../cred.js';
|
|
4
|
+
import { Errno, ErrnoError } from '../error.js';
|
|
5
|
+
import { size_max } from '../inode.js';
|
|
6
|
+
import { ZenFsType } from '../stats.js';
|
|
5
7
|
import { normalizePath } from '../utils.js';
|
|
6
8
|
import { resolve } from './path.js';
|
|
7
9
|
// credentials
|
|
@@ -100,3 +102,19 @@ export function mountObject(mounts) {
|
|
|
100
102
|
mount(point, fs);
|
|
101
103
|
}
|
|
102
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* @hidden
|
|
107
|
+
*/
|
|
108
|
+
export function _statfs(fs, bigint) {
|
|
109
|
+
const md = fs.metadata();
|
|
110
|
+
const bs = md.blockSize || 4096;
|
|
111
|
+
return {
|
|
112
|
+
type: (bigint ? BigInt : Number)(md.type || ZenFsType),
|
|
113
|
+
bsize: (bigint ? BigInt : Number)(bs),
|
|
114
|
+
ffree: (bigint ? BigInt : Number)(md.freeNodes || size_max),
|
|
115
|
+
files: (bigint ? BigInt : Number)(md.totalNodes || size_max),
|
|
116
|
+
bavail: (bigint ? BigInt : Number)(md.freeSpace / bs),
|
|
117
|
+
bfree: (bigint ? BigInt : Number)(md.freeSpace / bs),
|
|
118
|
+
blocks: (bigint ? BigInt : Number)(md.totalSpace / bs),
|
|
119
|
+
};
|
|
120
|
+
}
|
package/dist/emulation/sync.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { Buffer } from 'buffer';
|
|
5
5
|
import type * as fs from 'node:fs';
|
|
6
6
|
import { FileContents } from '../filesystem.js';
|
|
7
|
-
import { BigIntStats, type
|
|
7
|
+
import { BigIntStats, type Stats } from '../stats.js';
|
|
8
8
|
import { Dir, Dirent } from './dir.js';
|
|
9
9
|
/**
|
|
10
10
|
* Synchronous rename.
|
|
@@ -368,8 +368,8 @@ export declare function cpSync(source: fs.PathLike, destination: fs.PathLike, op
|
|
|
368
368
|
*/
|
|
369
369
|
export declare function statfsSync(path: fs.PathLike, options?: fs.StatFsOptions & {
|
|
370
370
|
bigint?: false;
|
|
371
|
-
}): StatsFs;
|
|
371
|
+
}): fs.StatsFs;
|
|
372
372
|
export declare function statfsSync(path: fs.PathLike, options: fs.StatFsOptions & {
|
|
373
373
|
bigint: true;
|
|
374
|
-
}): BigIntStatsFs;
|
|
375
|
-
export declare function statfsSync(path: fs.PathLike, options?: fs.StatFsOptions): StatsFs | BigIntStatsFs;
|
|
374
|
+
}): fs.BigIntStatsFs;
|
|
375
|
+
export declare function statfsSync(path: fs.PathLike, options?: fs.StatFsOptions): fs.StatsFs | fs.BigIntStatsFs;
|
package/dist/emulation/sync.js
CHANGED
|
@@ -1,23 +1,12 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
|
-
import {
|
|
2
|
+
import { Errno, ErrnoError } from '../error.js';
|
|
3
3
|
import { ActionType, isAppendable, isReadable, isWriteable, parseFlag, pathExistsAction, pathNotExistsAction } from '../file.js';
|
|
4
4
|
import { BigIntStats, FileType } from '../stats.js';
|
|
5
5
|
import { normalizeMode, normalizeOptions, normalizePath, normalizeTime } from '../utils.js';
|
|
6
6
|
import { COPYFILE_EXCL, F_OK, S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, S_IFSOCK } from './constants.js';
|
|
7
7
|
import { Dir, Dirent } from './dir.js';
|
|
8
8
|
import { dirname, join, parse } from './path.js';
|
|
9
|
-
import { cred, fd2file, fdMap,
|
|
10
|
-
function wrap(...[name, resolveSymlinks, path, ...args]) {
|
|
11
|
-
path = normalizePath(path);
|
|
12
|
-
const { fs, path: resolvedPath } = resolveMount(resolveSymlinks && existsSync(path) ? realpathSync(path) : path);
|
|
13
|
-
try {
|
|
14
|
-
// @ts-expect-error 2556 (since ...args is not correctly picked up as being a tuple)
|
|
15
|
-
return fs[name](resolvedPath, ...args);
|
|
16
|
-
}
|
|
17
|
-
catch (e) {
|
|
18
|
-
throw fixError(e, { [resolvedPath]: path });
|
|
19
|
-
}
|
|
20
|
-
}
|
|
9
|
+
import { _statfs, cred, fd2file, fdMap, file2fd, fixError, mounts, resolveMount } from './shared.js';
|
|
21
10
|
/**
|
|
22
11
|
* Synchronous rename.
|
|
23
12
|
* @param oldPath
|
|
@@ -60,13 +49,27 @@ export function existsSync(path) {
|
|
|
60
49
|
}
|
|
61
50
|
existsSync;
|
|
62
51
|
export function statSync(path, options) {
|
|
63
|
-
|
|
64
|
-
|
|
52
|
+
path = normalizePath(path);
|
|
53
|
+
const { fs, path: resolved } = resolveMount(existsSync(path) ? realpathSync(path) : path);
|
|
54
|
+
try {
|
|
55
|
+
const stats = fs.statSync(resolved, cred);
|
|
56
|
+
return options?.bigint ? new BigIntStats(stats) : stats;
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
throw fixError(e, { [resolved]: path });
|
|
60
|
+
}
|
|
65
61
|
}
|
|
66
62
|
statSync;
|
|
67
63
|
export function lstatSync(path, options) {
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
path = normalizePath(path);
|
|
65
|
+
const { fs, path: resolved } = resolveMount(path);
|
|
66
|
+
try {
|
|
67
|
+
const stats = fs.statSync(resolved, cred);
|
|
68
|
+
return options?.bigint ? new BigIntStats(stats) : stats;
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
throw fixError(e, { [resolved]: path });
|
|
72
|
+
}
|
|
70
73
|
}
|
|
71
74
|
lstatSync;
|
|
72
75
|
/**
|
|
@@ -89,44 +92,37 @@ truncateSync;
|
|
|
89
92
|
* @param path
|
|
90
93
|
*/
|
|
91
94
|
export function unlinkSync(path) {
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
unlinkSync;
|
|
95
|
-
function _openSync(_path, _flag, _mode, resolveSymlinks = true) {
|
|
96
|
-
const path = normalizePath(_path), mode = normalizeMode(_mode, 0o644), flag = parseFlag(_flag);
|
|
97
|
-
// Check if the path exists, and is a file.
|
|
98
|
-
let stats;
|
|
95
|
+
path = normalizePath(path);
|
|
96
|
+
const { fs, path: resolved } = resolveMount(path);
|
|
99
97
|
try {
|
|
100
|
-
|
|
98
|
+
return fs.unlinkSync(resolved, cred);
|
|
101
99
|
}
|
|
102
|
-
catch (
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
throw ErrnoError.With('
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
ex.stack += '\n<original>\n';
|
|
126
|
-
ex.stack += original.stack;
|
|
127
|
-
throw ex;
|
|
100
|
+
catch (e) {
|
|
101
|
+
throw fixError(e, { [resolved]: path });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
unlinkSync;
|
|
105
|
+
function _openSync(path, _flag, _mode, resolveSymlinks = true) {
|
|
106
|
+
path = normalizePath(path);
|
|
107
|
+
const mode = normalizeMode(_mode, 0o644), flag = parseFlag(_flag);
|
|
108
|
+
path = resolveSymlinks && existsSync(path) ? realpathSync(path) : path;
|
|
109
|
+
const { fs, path: resolved } = resolveMount(path);
|
|
110
|
+
if (!fs.existsSync(resolved, cred)) {
|
|
111
|
+
switch (pathNotExistsAction(flag)) {
|
|
112
|
+
case ActionType.CREATE:
|
|
113
|
+
// Ensure parent exists.
|
|
114
|
+
const parentStats = fs.statSync(dirname(resolved), cred);
|
|
115
|
+
if (!parentStats.isDirectory()) {
|
|
116
|
+
throw ErrnoError.With('ENOTDIR', dirname(path), '_open');
|
|
117
|
+
}
|
|
118
|
+
return fs.createFileSync(resolved, flag, mode, cred);
|
|
119
|
+
case ActionType.THROW:
|
|
120
|
+
throw ErrnoError.With('ENOENT', path, '_open');
|
|
121
|
+
default:
|
|
122
|
+
throw new ErrnoError(Errno.EINVAL, 'Invalid FileFlag object.');
|
|
128
123
|
}
|
|
129
124
|
}
|
|
125
|
+
const stats = fs.statSync(resolved, cred);
|
|
130
126
|
if (!stats.hasAccess(mode, cred)) {
|
|
131
127
|
throw ErrnoError.With('EACCES', path, '_open');
|
|
132
128
|
}
|
|
@@ -136,16 +132,16 @@ function _openSync(_path, _flag, _mode, resolveSymlinks = true) {
|
|
|
136
132
|
throw ErrnoError.With('EEXIST', path, '_open');
|
|
137
133
|
case ActionType.TRUNCATE:
|
|
138
134
|
// Delete file.
|
|
139
|
-
|
|
135
|
+
fs.unlinkSync(resolved, cred);
|
|
140
136
|
/*
|
|
141
137
|
Create file. Use the same mode as the old file.
|
|
142
138
|
Node itself modifies the ctime when this occurs, so this action
|
|
143
139
|
will preserve that behavior if the underlying file system
|
|
144
140
|
supports those properties.
|
|
145
141
|
*/
|
|
146
|
-
return
|
|
142
|
+
return fs.createFileSync(resolved, flag, stats.mode, cred);
|
|
147
143
|
case ActionType.NOP:
|
|
148
|
-
return
|
|
144
|
+
return fs.openFileSync(resolved, flag, cred);
|
|
149
145
|
default:
|
|
150
146
|
throw new ErrnoError(Errno.EINVAL, 'Invalid FileFlag object.');
|
|
151
147
|
}
|
|
@@ -367,18 +363,39 @@ futimesSync;
|
|
|
367
363
|
* @param path
|
|
368
364
|
*/
|
|
369
365
|
export function rmdirSync(path) {
|
|
370
|
-
|
|
366
|
+
path = normalizePath(path);
|
|
367
|
+
const { fs, path: resolved } = resolveMount(existsSync(path) ? realpathSync(path) : path);
|
|
368
|
+
try {
|
|
369
|
+
fs.rmdirSync(resolved, cred);
|
|
370
|
+
}
|
|
371
|
+
catch (e) {
|
|
372
|
+
throw fixError(e, { [resolved]: path });
|
|
373
|
+
}
|
|
371
374
|
}
|
|
372
375
|
rmdirSync;
|
|
373
376
|
export function mkdirSync(path, options) {
|
|
374
|
-
const mode = typeof options == 'number' || typeof options == 'string' ? options : options?.mode;
|
|
377
|
+
const mode = normalizeMode(typeof options == 'number' || typeof options == 'string' ? options : options?.mode, 0o777);
|
|
375
378
|
const recursive = typeof options == 'object' && options?.recursive;
|
|
376
|
-
|
|
379
|
+
path = normalizePath(path);
|
|
380
|
+
const { fs, path: resolved } = resolveMount(existsSync(path) ? realpathSync(path) : path);
|
|
381
|
+
try {
|
|
382
|
+
return fs.mkdirSync(resolved, mode, cred);
|
|
383
|
+
}
|
|
384
|
+
catch (e) {
|
|
385
|
+
throw fixError(e, { [resolved]: path });
|
|
386
|
+
}
|
|
377
387
|
}
|
|
378
388
|
mkdirSync;
|
|
379
389
|
export function readdirSync(path, options) {
|
|
380
390
|
path = normalizePath(path);
|
|
381
|
-
const
|
|
391
|
+
const { fs, path: resolved } = resolveMount(existsSync(path) ? realpathSync(path) : path);
|
|
392
|
+
let entries;
|
|
393
|
+
try {
|
|
394
|
+
entries = fs.readdirSync(resolved, cred);
|
|
395
|
+
}
|
|
396
|
+
catch (e) {
|
|
397
|
+
throw fixError(e, { [resolved]: path });
|
|
398
|
+
}
|
|
382
399
|
for (const mount of mounts.keys()) {
|
|
383
400
|
if (!mount.startsWith(path)) {
|
|
384
401
|
continue;
|
|
@@ -408,8 +425,15 @@ readdirSync;
|
|
|
408
425
|
* @param newpath
|
|
409
426
|
*/
|
|
410
427
|
export function linkSync(existing, newpath) {
|
|
428
|
+
existing = normalizePath(existing);
|
|
411
429
|
newpath = normalizePath(newpath);
|
|
412
|
-
|
|
430
|
+
const { fs, path: resolved } = resolveMount(existing);
|
|
431
|
+
try {
|
|
432
|
+
return fs.linkSync(resolved, newpath, cred);
|
|
433
|
+
}
|
|
434
|
+
catch (e) {
|
|
435
|
+
throw fixError(e, { [resolved]: existing });
|
|
436
|
+
}
|
|
413
437
|
}
|
|
414
438
|
linkSync;
|
|
415
439
|
/**
|
|
@@ -685,5 +709,7 @@ export function cpSync(source, destination, opts) {
|
|
|
685
709
|
}
|
|
686
710
|
cpSync;
|
|
687
711
|
export function statfsSync(path, options) {
|
|
688
|
-
|
|
712
|
+
path = normalizePath(path);
|
|
713
|
+
const { fs } = resolveMount(path);
|
|
714
|
+
return _statfs(fs, options?.bigint);
|
|
689
715
|
}
|
package/dist/file.d.ts
CHANGED
|
@@ -204,7 +204,7 @@ export declare class PreloadFile<FS extends FileSystem> extends File {
|
|
|
204
204
|
readonly stats: Stats;
|
|
205
205
|
protected _buffer: Uint8Array;
|
|
206
206
|
protected _position: number;
|
|
207
|
-
protected
|
|
207
|
+
protected dirty: boolean;
|
|
208
208
|
/**
|
|
209
209
|
* Creates a file with the given path and, optionally, the given contents. Note
|
|
210
210
|
* that, if contents is specified, it will be mutated by the file!
|
|
@@ -259,14 +259,14 @@ export declare class PreloadFile<FS extends FileSystem> extends File {
|
|
|
259
259
|
statSync(): Stats;
|
|
260
260
|
/**
|
|
261
261
|
* Asynchronous truncate.
|
|
262
|
-
* @param
|
|
262
|
+
* @param length
|
|
263
263
|
*/
|
|
264
|
-
truncate(
|
|
264
|
+
truncate(length: number): Promise<void>;
|
|
265
265
|
/**
|
|
266
266
|
* Synchronous truncate.
|
|
267
|
-
* @param
|
|
267
|
+
* @param length
|
|
268
268
|
*/
|
|
269
|
-
truncateSync(
|
|
269
|
+
truncateSync(length: number): void;
|
|
270
270
|
/**
|
|
271
271
|
* Write buffer to the file.
|
|
272
272
|
* Note that it is unsafe to use fs.write multiple times on the same file
|
|
@@ -345,11 +345,6 @@ export declare class PreloadFile<FS extends FileSystem> extends File {
|
|
|
345
345
|
chownSync(uid: number, gid: number): void;
|
|
346
346
|
utimes(atime: Date, mtime: Date): Promise<void>;
|
|
347
347
|
utimesSync(atime: Date, mtime: Date): void;
|
|
348
|
-
protected isDirty(): boolean;
|
|
349
|
-
/**
|
|
350
|
-
* Resets the dirty bit. Should only be called after a sync has completed successfully.
|
|
351
|
-
*/
|
|
352
|
-
protected resetDirty(): void;
|
|
353
348
|
_setType(type: FileType): Promise<void>;
|
|
354
349
|
_setTypeSync(type: FileType): void;
|
|
355
350
|
}
|