@zenfs/devel 0.0.1 → 1.0.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/bin/make-index.js +37 -74
- package/dist/bin/node-compat.d.ts +2 -0
- package/dist/bin/node-compat.js +337 -0
- package/dist/bin/zci.js +33 -44
- package/dist/bin/zenfs-test.js +48 -80
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/make_index.d.ts +20 -0
- package/dist/make_index.js +49 -0
- package/dist/node_compat/analysis.d.ts +53 -0
- package/dist/node_compat/analysis.js +60 -0
- package/dist/node_compat/changelog.d.ts +25 -0
- package/dist/node_compat/changelog.js +60 -0
- package/dist/node_compat/commits.d.ts +26 -0
- package/dist/node_compat/commits.js +66 -0
- package/dist/node_compat/config.d.ts +6 -0
- package/dist/node_compat/config.js +18 -0
- package/dist/node_compat/docs.d.ts +58 -0
- package/dist/node_compat/docs.js +213 -0
- package/dist/node_compat/git.d.ts +22 -0
- package/dist/node_compat/git.js +74 -0
- package/dist/node_compat/index.d.ts +10 -0
- package/dist/node_compat/index.js +11 -0
- package/dist/node_compat/node.d.ts +42 -0
- package/dist/node_compat/node.js +84 -0
- package/dist/node_compat/output.d.ts +29 -0
- package/dist/node_compat/output.js +95 -0
- package/dist/node_compat/pr.d.ts +59 -0
- package/dist/node_compat/pr.js +125 -0
- package/dist/node_compat/state.d.ts +18 -0
- package/dist/node_compat/state.js +12 -0
- package/dist/node_compat/versions.d.ts +5 -0
- package/dist/node_compat/versions.js +13 -0
- package/dist/node_compat/zenfs.d.ts +3 -0
- package/dist/node_compat/zenfs.js +108 -0
- package/dist/tests/common.js +1 -1
- package/dist/tests/fs/append.test.d.ts +1 -0
- package/dist/tests/fs/append.test.js +27 -0
- package/dist/tests/fs/concurrency.test.d.ts +1 -0
- package/dist/tests/fs/concurrency.test.js +76 -0
- package/dist/tests/fs/dir.test.d.ts +1 -0
- package/dist/tests/fs/dir.test.js +83 -0
- package/dist/tests/fs/directory.test.d.ts +1 -0
- package/dist/tests/fs/directory.test.js +151 -0
- package/dist/tests/fs/errors.test.d.ts +1 -0
- package/dist/tests/fs/errors.test.js +141 -0
- package/dist/tests/fs/exists.test.d.ts +1 -0
- package/dist/tests/fs/exists.test.js +19 -0
- package/dist/tests/fs/links.test.d.ts +1 -0
- package/dist/tests/fs/links.test.js +248 -0
- package/dist/tests/fs/open.test.d.ts +1 -0
- package/dist/tests/fs/open.test.js +95 -0
- package/dist/tests/fs/permissions.test.d.ts +1 -0
- package/dist/tests/fs/permissions.test.js +346 -0
- package/dist/tests/fs/read.test.d.ts +1 -0
- package/dist/tests/fs/read.test.js +149 -0
- package/dist/tests/fs/readFile.test.d.ts +1 -0
- package/dist/tests/fs/readFile.test.js +110 -0
- package/dist/tests/fs/rename.test.d.ts +1 -0
- package/dist/tests/fs/rename.test.js +70 -0
- package/dist/tests/fs/scaling.test.d.ts +1 -0
- package/dist/tests/fs/scaling.test.js +27 -0
- package/dist/tests/fs/stat.test.d.ts +1 -0
- package/dist/tests/fs/stat.test.js +93 -0
- package/dist/tests/fs/streams.test.d.ts +1 -0
- package/dist/tests/fs/streams.test.js +161 -0
- package/dist/tests/fs/tempdir.test.d.ts +1 -0
- package/dist/tests/fs/tempdir.test.js +118 -0
- package/dist/tests/fs/times.test.d.ts +7 -0
- package/dist/tests/fs/times.test.js +134 -0
- package/dist/tests/fs/truncate.test.d.ts +1 -0
- package/dist/tests/fs/truncate.test.js +62 -0
- package/dist/tests/fs/watch.test.d.ts +1 -0
- package/dist/tests/fs/watch.test.js +320 -0
- package/dist/tests/fs/write.test.d.ts +1 -0
- package/dist/tests/fs/write.test.js +83 -0
- package/dist/tests/fs/xattr.test.d.ts +1 -0
- package/dist/tests/fs/xattr.test.js +137 -0
- package/dist/tests/setup/memory.d.ts +1 -0
- package/dist/tests/setup/memory.js +3 -0
- package/package.json +11 -6
- package/tests/readme.md +2 -2
- package/tests/fs/append.test.ts +0 -34
- package/tests/fs/concurrency.test.ts +0 -113
- package/tests/fs/dir.test.ts +0 -103
- package/tests/fs/directory.test.ts +0 -189
- package/tests/fs/errors.test.ts +0 -159
- package/tests/fs/exists.test.ts +0 -23
- package/tests/fs/links.test.ts +0 -308
- package/tests/fs/open.test.ts +0 -23
- package/tests/fs/permissions.test.ts +0 -344
- package/tests/fs/read.test.ts +0 -94
- package/tests/fs/readFile.test.ts +0 -58
- package/tests/fs/rename.test.ts +0 -93
- package/tests/fs/scaling.test.ts +0 -35
- package/tests/fs/stat.test.ts +0 -115
- package/tests/fs/streams.test.ts +0 -204
- package/tests/fs/tempdir.test.ts +0 -64
- package/tests/fs/times.test.ts +0 -85
- package/tests/fs/truncate.test.ts +0 -89
- package/tests/fs/watch.test.ts +0 -246
- package/tests/fs/write.test.ts +0 -118
- package/tests/fs/xattr.test.ts +0 -96
- package/tests/setup/memory.ts +0 -3
- package/tests/tsconfig.json +0 -8
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { parseSubject } from './commits.js';
|
|
2
|
+
import { compareVersions } from './versions.js';
|
|
3
|
+
export class PR {
|
|
4
|
+
number;
|
|
5
|
+
title = '';
|
|
6
|
+
subsystems = [];
|
|
7
|
+
author = '';
|
|
8
|
+
semver = 'unreleased';
|
|
9
|
+
revert = false;
|
|
10
|
+
/** Commits on the tracked ref, oldest first */
|
|
11
|
+
commits = [];
|
|
12
|
+
/** Every release that lists the PR, ascending */
|
|
13
|
+
releases = [];
|
|
14
|
+
/** Affected APIs, by ID */
|
|
15
|
+
apis = { added: [], removed: [], changed: [] };
|
|
16
|
+
constructor(number) {
|
|
17
|
+
this.number = number;
|
|
18
|
+
}
|
|
19
|
+
get url() {
|
|
20
|
+
return `https://github.com/nodejs/node/pull/${this.number}`;
|
|
21
|
+
}
|
|
22
|
+
/** Key for marks */
|
|
23
|
+
get key() {
|
|
24
|
+
return '#' + this.number;
|
|
25
|
+
}
|
|
26
|
+
/** Earliest version in each release line, ascending */
|
|
27
|
+
get versions() {
|
|
28
|
+
const earliest = new Map();
|
|
29
|
+
for (const release of this.releases)
|
|
30
|
+
if (!earliest.has(release.line))
|
|
31
|
+
earliest.set(release.line, release.version);
|
|
32
|
+
return [...earliest.values()];
|
|
33
|
+
}
|
|
34
|
+
/** Top-level directories touched */
|
|
35
|
+
get areas() {
|
|
36
|
+
return [...new Set(this.commits.flatMap(commit => commit.files.map(file => file.split('/')[0])))].sort();
|
|
37
|
+
}
|
|
38
|
+
/** Heuristic labels derived from the title and touched areas */
|
|
39
|
+
get tags() {
|
|
40
|
+
const tags = [];
|
|
41
|
+
const title = this.title.toLowerCase();
|
|
42
|
+
const { areas } = this;
|
|
43
|
+
if (this.revert)
|
|
44
|
+
tags.push('revert');
|
|
45
|
+
if (!this.commits.length)
|
|
46
|
+
tags.push('backport');
|
|
47
|
+
if (areas.length) {
|
|
48
|
+
if (!areas.includes('lib'))
|
|
49
|
+
tags.push(areas.includes('src') ? 'native' : areas.every(area => area == 'doc') ? 'docs' : 'internal');
|
|
50
|
+
if (areas.every(area => area == 'test' || area == 'doc'))
|
|
51
|
+
tags.push('test');
|
|
52
|
+
}
|
|
53
|
+
if (/\bwin(dows|32)?\b/.test(title) || this.subsystems.includes('win'))
|
|
54
|
+
tags.push('windows');
|
|
55
|
+
if (/\b(perf|performance|faster|optimi[sz]e|speed up|allocations?)\b/.test(title))
|
|
56
|
+
tags.push('perf');
|
|
57
|
+
if (/\b(experimental|stabilize|stable)\b/.test(title))
|
|
58
|
+
tags.push('stability');
|
|
59
|
+
if (/\b(deprecat|eol|end-of-life)/.test(title))
|
|
60
|
+
tags.push('deprecation');
|
|
61
|
+
return tags;
|
|
62
|
+
}
|
|
63
|
+
/** ISO date the PR landed on the tracked ref, or of its first release */
|
|
64
|
+
get date() {
|
|
65
|
+
return this.commits[0]?.date ?? this.releases[0]?.date ?? '';
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Adds a commit in chronological order, along with the APIs it added or removed.
|
|
69
|
+
*/
|
|
70
|
+
addCommit(commit, history) {
|
|
71
|
+
this.commits.push(commit);
|
|
72
|
+
const subject = parseSubject(commit.subject);
|
|
73
|
+
if (!this.title && subject) {
|
|
74
|
+
this.title = subject.title;
|
|
75
|
+
this.subsystems = subject.subsystems;
|
|
76
|
+
this.revert = subject.revert;
|
|
77
|
+
this.author = commit.author;
|
|
78
|
+
}
|
|
79
|
+
for (const id of history?.added ?? [])
|
|
80
|
+
toggle(this.apis.added, this.apis.removed, id);
|
|
81
|
+
for (const id of history?.removed ?? [])
|
|
82
|
+
toggle(this.apis.removed, this.apis.added, id);
|
|
83
|
+
}
|
|
84
|
+
addRelease(entry) {
|
|
85
|
+
if (!this.releases.some(release => release.version == entry.release.version)) {
|
|
86
|
+
this.releases.push(entry.release);
|
|
87
|
+
this.releases.sort((left, right) => compareVersions(left.version, right.version));
|
|
88
|
+
}
|
|
89
|
+
if (this.semver == 'unreleased' || entry.semver == 'major' || (entry.semver == 'minor' && this.semver == 'patch'))
|
|
90
|
+
this.semver = entry.semver;
|
|
91
|
+
if (this.title)
|
|
92
|
+
return;
|
|
93
|
+
this.title = entry.title;
|
|
94
|
+
this.subsystems = entry.subsystems;
|
|
95
|
+
this.revert = entry.revert;
|
|
96
|
+
this.author = entry.author;
|
|
97
|
+
}
|
|
98
|
+
toJSON() {
|
|
99
|
+
return {
|
|
100
|
+
number: this.number,
|
|
101
|
+
url: this.url,
|
|
102
|
+
title: this.title,
|
|
103
|
+
subsystems: this.subsystems,
|
|
104
|
+
author: this.author,
|
|
105
|
+
semver: this.semver,
|
|
106
|
+
revert: this.revert,
|
|
107
|
+
commits: this.commits.map(({ hash, date, author, subject, files }) => ({ hash, date, author, subject, files })),
|
|
108
|
+
releases: this.releases,
|
|
109
|
+
versions: this.versions,
|
|
110
|
+
areas: this.areas,
|
|
111
|
+
tags: this.tags,
|
|
112
|
+
apis: this.apis,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Adds `id` to `target`, unless it is in `opposite`, in which case the two cancel out.
|
|
118
|
+
*/
|
|
119
|
+
function toggle(target, opposite, id) {
|
|
120
|
+
const index = opposite.indexOf(id);
|
|
121
|
+
if (index != -1)
|
|
122
|
+
opposite.splice(index, 1);
|
|
123
|
+
else if (!target.includes(id))
|
|
124
|
+
target.push(id);
|
|
125
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { JSONFileMap } from 'utilium/fs';
|
|
2
|
+
export type Mark = 'resolved' | 'ignored';
|
|
3
|
+
export type MarkEntry = {
|
|
4
|
+
status: Mark;
|
|
5
|
+
note?: string;
|
|
6
|
+
/** ISO date */
|
|
7
|
+
date: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Manual marks on PRs (`#<number>`) and APIs (by ID), backed by a JSON file.
|
|
11
|
+
*/
|
|
12
|
+
export type Marks = Map<string, MarkEntry>;
|
|
13
|
+
export declare const defaultMarksPath = ".node-compat.json";
|
|
14
|
+
/**
|
|
15
|
+
* Opens a marks file, creating it if needed.
|
|
16
|
+
*/
|
|
17
|
+
export declare function openMarks(path?: string): JSONFileMap<MarkEntry>;
|
|
18
|
+
export declare function createMark(status: Mark, note?: string): MarkEntry;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
2
|
+
import { JSONFileMap } from 'utilium/fs';
|
|
3
|
+
export const defaultMarksPath = '.node-compat.json';
|
|
4
|
+
/**
|
|
5
|
+
* Opens a marks file, creating it if needed.
|
|
6
|
+
*/
|
|
7
|
+
export function openMarks(path = defaultMarksPath) {
|
|
8
|
+
return new JSONFileMap(path, { overwrite_invalid: false });
|
|
9
|
+
}
|
|
10
|
+
export function createMark(status, note) {
|
|
11
|
+
return { status, ...(note && { note }), date: new Date().toISOString().slice(0, 10) };
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
2
|
+
/**
|
|
3
|
+
* @param version A full or partial version, optionally prefixed with `v`
|
|
4
|
+
*/
|
|
5
|
+
export function parseVersion(version) {
|
|
6
|
+
const [major = 0, minor = 0, patch = 0] = version.replace(/^v/, '').split('.').map(Number);
|
|
7
|
+
return [major, minor, patch];
|
|
8
|
+
}
|
|
9
|
+
export function compareVersions(left, right) {
|
|
10
|
+
const [leftMajor, leftMinor, leftPatch] = parseVersion(left);
|
|
11
|
+
const [rightMajor, rightMinor, rightPatch] = parseVersion(right);
|
|
12
|
+
return leftMajor - rightMajor || leftMinor - rightMinor || leftPatch - rightPatch;
|
|
13
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
2
|
+
if (value !== null && value !== void 0) {
|
|
3
|
+
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
4
|
+
var dispose, inner;
|
|
5
|
+
if (async) {
|
|
6
|
+
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
7
|
+
dispose = value[Symbol.asyncDispose];
|
|
8
|
+
}
|
|
9
|
+
if (dispose === void 0) {
|
|
10
|
+
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
11
|
+
dispose = value[Symbol.dispose];
|
|
12
|
+
if (async) inner = dispose;
|
|
13
|
+
}
|
|
14
|
+
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
15
|
+
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
16
|
+
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
17
|
+
}
|
|
18
|
+
else if (async) {
|
|
19
|
+
env.stack.push({ async: true });
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
};
|
|
23
|
+
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
24
|
+
return function (env) {
|
|
25
|
+
function fail(e) {
|
|
26
|
+
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
27
|
+
env.hasError = true;
|
|
28
|
+
}
|
|
29
|
+
var r, s = 0;
|
|
30
|
+
function next() {
|
|
31
|
+
while (r = env.stack.pop()) {
|
|
32
|
+
try {
|
|
33
|
+
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
34
|
+
if (r.dispose) {
|
|
35
|
+
var result = r.dispose.call(r.value);
|
|
36
|
+
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
37
|
+
}
|
|
38
|
+
else s |= 1;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
fail(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
45
|
+
if (env.hasError) throw env.error;
|
|
46
|
+
}
|
|
47
|
+
return next();
|
|
48
|
+
};
|
|
49
|
+
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
50
|
+
var e = new Error(message);
|
|
51
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
52
|
+
});
|
|
53
|
+
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
54
|
+
import * as zenfs from '@zenfs/core';
|
|
55
|
+
function attempt(create) {
|
|
56
|
+
try {
|
|
57
|
+
return create();
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export const version = zenfs._version;
|
|
64
|
+
export function has(api) {
|
|
65
|
+
let target = targets[api.owner];
|
|
66
|
+
if (target == null)
|
|
67
|
+
return false;
|
|
68
|
+
for (const key of api.path) {
|
|
69
|
+
if ((typeof target != 'object' && typeof target != 'function') || target === null || !(key in target))
|
|
70
|
+
return false;
|
|
71
|
+
target = target[key];
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
var stack, dir, file, targets;
|
|
76
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
77
|
+
try {
|
|
78
|
+
stack = __addDisposableResource(env_1, new AsyncDisposableStack(), true);
|
|
79
|
+
dir = '/.node-compat-probe';
|
|
80
|
+
file = dir + '/file';
|
|
81
|
+
zenfs.rmSync(dir, { recursive: true, force: true });
|
|
82
|
+
zenfs.mkdirSync(dir, { recursive: true });
|
|
83
|
+
stack.defer(() => zenfs.rmSync(dir, { recursive: true, force: true }));
|
|
84
|
+
zenfs.writeFileSync(file, 'probe');
|
|
85
|
+
targets = {
|
|
86
|
+
fs: zenfs,
|
|
87
|
+
fsPromises: zenfs.promises,
|
|
88
|
+
FileHandle: stack.use(await zenfs.promises.open(file).catch(() => undefined)),
|
|
89
|
+
Dir: stack.use(attempt(() => zenfs.opendirSync(dir))),
|
|
90
|
+
Dirent: attempt(() => zenfs.readdirSync(dir, { withFileTypes: true })[0]),
|
|
91
|
+
FSWatcher: stack.adopt(attempt(() => zenfs.watch(dir)), watcher => watcher?.close()),
|
|
92
|
+
StatWatcher: stack.adopt(attempt(() => zenfs.watchFile(file, () => { })), () => zenfs.unwatchFile(file)),
|
|
93
|
+
ReadStream: stack.use(attempt(() => zenfs.createReadStream(file))),
|
|
94
|
+
WriteStream: stack.use(attempt(() => zenfs.createWriteStream(dir + '/write'))),
|
|
95
|
+
Stats: attempt(() => zenfs.statSync(file)),
|
|
96
|
+
StatFs: attempt(() => zenfs.statfsSync(dir)),
|
|
97
|
+
Utf8Stream: stack.use(attempt(() => new zenfs.Utf8Stream({ dest: dir + '/utf8', sync: true }))),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
catch (e_1) {
|
|
101
|
+
env_1.error = e_1;
|
|
102
|
+
env_1.hasError = true;
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
const result_1 = __disposeResources(env_1);
|
|
106
|
+
if (result_1)
|
|
107
|
+
await result_1;
|
|
108
|
+
}
|
package/dist/tests/common.js
CHANGED
|
@@ -4,7 +4,7 @@ import { join, resolve } from 'node:path';
|
|
|
4
4
|
import { styleText } from 'node:util';
|
|
5
5
|
import { setupLogs } from './logs.js';
|
|
6
6
|
setupLogs();
|
|
7
|
-
const setupPath = resolve(process.env.SETUP || join(import.meta.dirname, '
|
|
7
|
+
const setupPath = resolve(process.env.SETUP || join(import.meta.dirname, 'setup/memory.js'));
|
|
8
8
|
process.on('unhandledRejection', (reason) => {
|
|
9
9
|
console.error('Unhandled rejection:', styleText('red', reason.stack || reason.message));
|
|
10
10
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { suite, test } from 'node:test';
|
|
4
|
+
import { fs, config } from '../common.js';
|
|
5
|
+
const content = 'Sample content', original = 'ABCD';
|
|
6
|
+
suite('Appends', config('appends'), () => {
|
|
7
|
+
test('Create an empty file and add content', config('async'), async () => {
|
|
8
|
+
const filename = 'append.txt';
|
|
9
|
+
await fs.promises.appendFile(filename, content);
|
|
10
|
+
const data = await fs.promises.readFile(filename, 'utf8');
|
|
11
|
+
assert.equal(data, content);
|
|
12
|
+
});
|
|
13
|
+
test('Append data to a non-empty file', config('async'), async () => {
|
|
14
|
+
const filename = 'append2.txt';
|
|
15
|
+
await fs.promises.writeFile(filename, original);
|
|
16
|
+
await fs.promises.appendFile(filename, content);
|
|
17
|
+
const data = await fs.promises.readFile(filename, 'utf8');
|
|
18
|
+
assert.equal(data, original + content);
|
|
19
|
+
});
|
|
20
|
+
test('Append a buffer to the file', config('async'), async () => {
|
|
21
|
+
const filename = 'append3.txt';
|
|
22
|
+
await fs.promises.writeFile(filename, original);
|
|
23
|
+
await fs.promises.appendFile(filename, content);
|
|
24
|
+
const data = await fs.promises.readFile(filename, 'utf8');
|
|
25
|
+
assert.equal(data, original + content);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { suite, test } from 'node:test';
|
|
4
|
+
import { config, fs } from '../common.js';
|
|
5
|
+
suite('Concurrency', config('write', 'async'), () => {
|
|
6
|
+
test('parallel writeFile in the same directory does not lose entries #256', async () => {
|
|
7
|
+
await fs.promises.mkdir('/issue-256');
|
|
8
|
+
await Promise.all([fs.promises.writeFile('/issue-256/a1.txt', 'a1'), fs.promises.writeFile('/issue-256/a2.txt', 'a2')]);
|
|
9
|
+
const files = await fs.promises.readdir('/issue-256');
|
|
10
|
+
assert.deepEqual(files.sort(), ['a1.txt', 'a2.txt']);
|
|
11
|
+
});
|
|
12
|
+
test('concurrent file creation does not lose directory entries #298', async () => {
|
|
13
|
+
await fs.promises.mkdir('/issue-298');
|
|
14
|
+
const names = Array.from({ length: 32 }, (_, i) => `file-${i}.txt`);
|
|
15
|
+
await Promise.all(names.map(name => fs.promises.writeFile(`/issue-298/${name}`, name)));
|
|
16
|
+
const files = await fs.promises.readdir('/issue-298');
|
|
17
|
+
assert.deepEqual(files.sort(), names.sort());
|
|
18
|
+
});
|
|
19
|
+
test('open handles for the same file share metadata #287', async () => {
|
|
20
|
+
await fs.promises.writeFile('/issue-287.txt', 'Hello World');
|
|
21
|
+
const a = await fs.promises.open('/issue-287.txt', 'r+');
|
|
22
|
+
const b = await fs.promises.open('/issue-287.txt', 'r+');
|
|
23
|
+
await a.truncate(5); // contents are now "Hello"
|
|
24
|
+
const { size } = await b.stat();
|
|
25
|
+
assert.equal(size, 5);
|
|
26
|
+
await a.close();
|
|
27
|
+
await b.close();
|
|
28
|
+
});
|
|
29
|
+
test('writes are visible to other open handles before syncing', async () => {
|
|
30
|
+
const a = await fs.promises.open('/shared-write.txt', 'w+');
|
|
31
|
+
const b = await fs.promises.open('/shared-write.txt', 'r');
|
|
32
|
+
await a.write('some shared data');
|
|
33
|
+
const { buffer } = await b.read(new Uint8Array(16), 0, 16, 0);
|
|
34
|
+
assert.equal(new TextDecoder().decode(buffer), 'some shared data');
|
|
35
|
+
await a.close();
|
|
36
|
+
await b.close();
|
|
37
|
+
});
|
|
38
|
+
test('reads concurrent with an overwrite of the same file do not fail #303', async () => {
|
|
39
|
+
await fs.promises.writeFile('/issue-303.txt', 'original contents');
|
|
40
|
+
/* Every handle for a file shares one vnode, so closing any of these flushes whatever is dirty.
|
|
41
|
+
Syncing took a shared lock, letting several of these run at once and corrupt each other. */
|
|
42
|
+
for (let round = 0; round < 20; round++) {
|
|
43
|
+
const contents = `rewritten contents for round ${round}`;
|
|
44
|
+
const results = await Promise.allSettled([
|
|
45
|
+
...Array.from({ length: 4 }, () => fs.promises.readFile('/issue-303.txt', 'utf8')),
|
|
46
|
+
fs.promises.writeFile('/issue-303.txt', contents),
|
|
47
|
+
...Array.from({ length: 4 }, () => fs.promises.readFile('/issue-303.txt', 'utf8')),
|
|
48
|
+
]);
|
|
49
|
+
const rejected = results.filter(r => r.status === 'rejected');
|
|
50
|
+
assert.deepEqual(rejected.map(r => r.reason.code ?? r.reason.message), []);
|
|
51
|
+
assert.equal(await fs.promises.readFile('/issue-303.txt', 'utf8'), contents);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
test('closing a handle does not fail because another handle has unsynced writes #303', async () => {
|
|
55
|
+
await fs.promises.writeFile('/issue-303-close.txt', 'original');
|
|
56
|
+
const reader = await fs.promises.open('/issue-303-close.txt', 'r');
|
|
57
|
+
const writer = await fs.promises.open('/issue-303-close.txt', 'r+');
|
|
58
|
+
// The reader wrote nothing, so its close must not report the writer's dirty data as EBUSY
|
|
59
|
+
const [closed] = await Promise.allSettled([reader.close(), writer.write(new TextEncoder().encode('DIRTY'), 0, 5, 0)]);
|
|
60
|
+
assert.equal(closed.status, 'fulfilled');
|
|
61
|
+
await writer.close();
|
|
62
|
+
assert.equal(await fs.promises.readFile('/issue-303-close.txt', 'utf8'), 'DIRTYnal');
|
|
63
|
+
});
|
|
64
|
+
test('concurrent recursive mkdir of overlapping trees does not fail #308', async () => {
|
|
65
|
+
const paths = ['/308/a', '/308/a', '/308/a/b', '/308/a/b', '/308/c', '/308/c', '/308-2', '/308-2'];
|
|
66
|
+
const results = await Promise.allSettled(paths.map(path => fs.promises.mkdir(path, { recursive: true })));
|
|
67
|
+
const rejected = results.filter(r => r.status == 'rejected');
|
|
68
|
+
assert.deepEqual(rejected.map(r => r.reason.code ?? r.reason.message), []);
|
|
69
|
+
for (const path of paths)
|
|
70
|
+
assert((await fs.promises.stat(path)).isDirectory());
|
|
71
|
+
});
|
|
72
|
+
test('parallel recursive mkdir of the same path creates it once #308', async () => {
|
|
73
|
+
const results = await Promise.all(Array.from({ length: 8 }, () => fs.promises.mkdir('/308-same/nested', { recursive: true })));
|
|
74
|
+
assert.deepEqual(results.filter(result => result !== undefined), ['/308-same']);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
2
|
+
import { sync } from '@zenfs/core';
|
|
3
|
+
import assert, { rejects } from 'node:assert/strict';
|
|
4
|
+
import { suite, test } from 'node:test';
|
|
5
|
+
import { config, fs } from '../common.js';
|
|
6
|
+
const testFile = 'test-file.txt';
|
|
7
|
+
fs.writeFileSync(testFile, 'Sample content');
|
|
8
|
+
fs.mkdirSync('test-directory');
|
|
9
|
+
fs.symlinkSync(testFile, 'test-symlink');
|
|
10
|
+
const testDirPath = 'test-dir';
|
|
11
|
+
const testFiles = ['file1.txt', 'file2.txt'];
|
|
12
|
+
fs.mkdirSync(testDirPath);
|
|
13
|
+
for (const file of testFiles) {
|
|
14
|
+
fs.writeFileSync(`${testDirPath}/${file}`, 'Sample content');
|
|
15
|
+
}
|
|
16
|
+
await sync();
|
|
17
|
+
suite('Dir', config('directories'), () => {
|
|
18
|
+
test('read()', config('async'), async () => {
|
|
19
|
+
const dir = fs.opendirSync(testDirPath);
|
|
20
|
+
const dirent1 = await dir.read();
|
|
21
|
+
assert(dirent1 instanceof fs.Dirent);
|
|
22
|
+
assert(testFiles.includes(dirent1?.name));
|
|
23
|
+
const dirent2 = await dir.read();
|
|
24
|
+
assert(dirent2 instanceof fs.Dirent);
|
|
25
|
+
assert(testFiles.includes(dirent2?.name));
|
|
26
|
+
const dirent3 = await dir.read();
|
|
27
|
+
assert.equal(dirent3, null);
|
|
28
|
+
await dir.close();
|
|
29
|
+
});
|
|
30
|
+
test('readSync()', config('sync'), () => {
|
|
31
|
+
const dir = fs.opendirSync(testDirPath);
|
|
32
|
+
const dirent1 = dir.readSync();
|
|
33
|
+
assert(dirent1 instanceof fs.Dirent);
|
|
34
|
+
assert(testFiles.includes(dirent1?.name));
|
|
35
|
+
const dirent2 = dir.readSync();
|
|
36
|
+
assert(dirent2 instanceof fs.Dirent);
|
|
37
|
+
assert(testFiles.includes(dirent2?.name));
|
|
38
|
+
const dirent3 = dir.readSync();
|
|
39
|
+
assert.equal(dirent3, null);
|
|
40
|
+
dir.closeSync();
|
|
41
|
+
});
|
|
42
|
+
test('close()', config('async'), async () => {
|
|
43
|
+
const dir = fs.opendirSync(testDirPath);
|
|
44
|
+
await dir.close();
|
|
45
|
+
rejects(dir.read());
|
|
46
|
+
});
|
|
47
|
+
test('closeSync()', config('sync'), () => {
|
|
48
|
+
const dir = fs.opendirSync(testDirPath);
|
|
49
|
+
dir.closeSync();
|
|
50
|
+
assert.throws(() => dir.readSync());
|
|
51
|
+
});
|
|
52
|
+
test('asynchronous iteration', config('async'), async () => {
|
|
53
|
+
const dir = fs.opendirSync(testDirPath);
|
|
54
|
+
const dirents = [];
|
|
55
|
+
for await (const dirent of dir) {
|
|
56
|
+
dirents.push(dirent);
|
|
57
|
+
}
|
|
58
|
+
assert.equal(dirents.length, 2);
|
|
59
|
+
assert(dirents[0] instanceof fs.Dirent);
|
|
60
|
+
assert(testFiles.includes(dirents[0].name));
|
|
61
|
+
assert(testFiles.includes(dirents[1].name));
|
|
62
|
+
});
|
|
63
|
+
test('read after directory is closed', config('async'), async () => {
|
|
64
|
+
const dir = fs.opendirSync(testDirPath);
|
|
65
|
+
await dir.close();
|
|
66
|
+
await assert.rejects(dir.read());
|
|
67
|
+
});
|
|
68
|
+
test('readSync after directory is closed', config('sync'), () => {
|
|
69
|
+
const dir = fs.opendirSync(testDirPath);
|
|
70
|
+
dir.closeSync();
|
|
71
|
+
assert.throws(() => dir.readSync());
|
|
72
|
+
});
|
|
73
|
+
test('close multiple times', config('async'), async () => {
|
|
74
|
+
const dir = fs.opendirSync(testDirPath);
|
|
75
|
+
await dir.close();
|
|
76
|
+
await assert.rejects(dir.close(), { code: 'ERR_DIR_CLOSED' });
|
|
77
|
+
});
|
|
78
|
+
test('closeSync multiple times', config('sync'), () => {
|
|
79
|
+
const dir = fs.opendirSync(testDirPath);
|
|
80
|
+
dir.closeSync();
|
|
81
|
+
assert.throws(() => dir.closeSync(), { code: 'ERR_DIR_CLOSED' });
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { join } from 'node:path/posix';
|
|
4
|
+
import { suite, test } from 'node:test';
|
|
5
|
+
import { config, fs } from '../common.js';
|
|
6
|
+
const testDir = 'test-dir';
|
|
7
|
+
const testFiles = ['file1.txt', 'file2.txt', 'file3.txt'];
|
|
8
|
+
const testDirectories = ['subdir1', 'subdir2'];
|
|
9
|
+
await fs.promises.mkdir(testDir);
|
|
10
|
+
for (const file of testFiles) {
|
|
11
|
+
await fs.promises.writeFile(`${testDir}/${file}`, 'Sample content');
|
|
12
|
+
}
|
|
13
|
+
for (const dir of testDirectories) {
|
|
14
|
+
await fs.promises.mkdir(`${testDir}/${dir}`);
|
|
15
|
+
for (const file of ['file4.txt', 'file5.txt']) {
|
|
16
|
+
await fs.promises.writeFile(`${testDir}/${dir}/${file}`, 'Sample content');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
suite('Directories', config('directories'), () => {
|
|
20
|
+
test('mkdir', config('async'), async () => {
|
|
21
|
+
await fs.promises.mkdir('/one', 0o755);
|
|
22
|
+
assert(await fs.promises.stat('/one', { throwIfNoEntry: false }));
|
|
23
|
+
await assert.rejects(fs.promises.mkdir('/one', 0o755), { code: 'EEXIST' });
|
|
24
|
+
});
|
|
25
|
+
test('mkdirSync', config('sync'), () => fs.mkdirSync('/two', 0o000));
|
|
26
|
+
test('mkdir, nested', config('async'), async () => {
|
|
27
|
+
await assert.rejects(fs.promises.mkdir('/nested/dir'), { code: 'ENOENT', path: '/nested/dir' });
|
|
28
|
+
assert(!(await fs.promises.stat('/nested/dir', { throwIfNoEntry: false })));
|
|
29
|
+
});
|
|
30
|
+
test('mkdir, recursive', config('async'), async () => {
|
|
31
|
+
assert.equal(await fs.promises.mkdir('/recursiveP/A/B', { recursive: true, mode: 0o755 }), '/recursiveP');
|
|
32
|
+
assert.equal(await fs.promises.mkdir('/recursiveP/A/B/C/D', { recursive: true, mode: 0o777 }), '/recursiveP/A/B/C');
|
|
33
|
+
assert.equal(await fs.promises.mkdir('/recursiveP/A/B/C/D', { recursive: true, mode: 0o700 }), undefined);
|
|
34
|
+
assert.equal((await fs.promises.stat('/recursiveP')).mode, fs.constants.S_IFDIR | 0o755);
|
|
35
|
+
assert.equal((await fs.promises.stat('/recursiveP/A')).mode, fs.constants.S_IFDIR | 0o755);
|
|
36
|
+
assert.equal((await fs.promises.stat('/recursiveP/A/B')).mode, fs.constants.S_IFDIR | 0o755);
|
|
37
|
+
assert.equal((await fs.promises.stat('/recursiveP/A/B/C')).mode, fs.constants.S_IFDIR | 0o777);
|
|
38
|
+
assert.equal((await fs.promises.stat('/recursiveP/A/B/C/D')).mode, fs.constants.S_IFDIR | 0o777);
|
|
39
|
+
});
|
|
40
|
+
test('mkdir, recursive with a file in the way', config('async'), async () => {
|
|
41
|
+
await fs.promises.writeFile('/recursiveF', 'Sample content');
|
|
42
|
+
await assert.rejects(fs.promises.mkdir('/recursiveF', { recursive: true }), { code: 'EEXIST', path: '/recursiveF' });
|
|
43
|
+
await assert.rejects(fs.promises.mkdir('/recursiveF/A/B', { recursive: true }), { code: 'ENOTDIR', path: '/recursiveF/A/B' });
|
|
44
|
+
});
|
|
45
|
+
test('mkdirSync, recursive', config('sync'), () => {
|
|
46
|
+
assert.equal(fs.mkdirSync('/recursiveS/A/B', { recursive: true, mode: 0o755 }), '/recursiveS');
|
|
47
|
+
assert.equal(fs.mkdirSync('/recursiveS/A/B/C/D', { recursive: true, mode: 0o777 }), '/recursiveS/A/B/C');
|
|
48
|
+
assert.equal(fs.mkdirSync('/recursiveS/A/B/C/D', { recursive: true, mode: 0o700 }), undefined);
|
|
49
|
+
assert.equal(fs.statSync('/recursiveS').mode, fs.constants.S_IFDIR | 0o755);
|
|
50
|
+
assert.equal(fs.statSync('/recursiveS/A').mode, fs.constants.S_IFDIR | 0o755);
|
|
51
|
+
assert.equal(fs.statSync('/recursiveS/A/B').mode, fs.constants.S_IFDIR | 0o755);
|
|
52
|
+
assert.equal(fs.statSync('/recursiveS/A/B/C').mode, fs.constants.S_IFDIR | 0o777);
|
|
53
|
+
assert.equal(fs.statSync('/recursiveS/A/B/C/D').mode, fs.constants.S_IFDIR | 0o777);
|
|
54
|
+
});
|
|
55
|
+
test('mkdirSync, recursive with a file in the way', config('sync'), () => {
|
|
56
|
+
fs.writeFileSync('/recursiveSF', 'Sample content');
|
|
57
|
+
assert.throws(() => fs.mkdirSync('/recursiveSF', { recursive: true }), { code: 'EEXIST', path: '/recursiveSF' });
|
|
58
|
+
assert.throws(() => fs.mkdirSync('/recursiveSF/A/B', { recursive: true }), { code: 'ENOTDIR', path: '/recursiveSF/A/B' });
|
|
59
|
+
});
|
|
60
|
+
test('rmdir (non-empty)', config('async'), async () => {
|
|
61
|
+
await fs.promises.mkdir('/rmdirTest');
|
|
62
|
+
await fs.promises.mkdir('/rmdirTest/rmdirTest2');
|
|
63
|
+
await assert.rejects(fs.promises.rmdir('/rmdirTest'), { code: 'ENOTEMPTY' });
|
|
64
|
+
});
|
|
65
|
+
test('readdirSync on file', config('sync'), () => {
|
|
66
|
+
assert.throws(() => fs.readdirSync('a.js'), { code: 'ENOTDIR' });
|
|
67
|
+
});
|
|
68
|
+
test('readdir on file', config('async'), async () => {
|
|
69
|
+
await assert.rejects(fs.promises.readdir('a.js'), { code: 'ENOTDIR' });
|
|
70
|
+
});
|
|
71
|
+
test('readdirSync on non-existent directory', config('sync'), () => {
|
|
72
|
+
assert.throws(() => fs.readdirSync('/does/not/exist'), { code: 'ENOENT' });
|
|
73
|
+
});
|
|
74
|
+
test('readdir on non-existent directory', config('async'), async () => {
|
|
75
|
+
await assert.rejects(fs.promises.readdir('/does/not/exist'), { code: 'ENOENT' });
|
|
76
|
+
});
|
|
77
|
+
test('rm recursively', config('async'), async () => {
|
|
78
|
+
await fs.promises.mkdir('/rmDirRecursively');
|
|
79
|
+
await fs.promises.mkdir('/rmDirRecursively/rmDirNested');
|
|
80
|
+
await fs.promises.writeFile('/rmDirRecursively/rmDirNested/test.txt', 'hello world!');
|
|
81
|
+
await fs.promises.rm('/rmDirRecursively', { recursive: true });
|
|
82
|
+
});
|
|
83
|
+
test('rmSync recursively', config('sync'), () => {
|
|
84
|
+
fs.mkdirSync('/rmDirRecursively');
|
|
85
|
+
fs.mkdirSync('/rmDirRecursively/rmDirNested');
|
|
86
|
+
fs.writeFileSync('/rmDirRecursively/rmDirNested/test.txt', 'hello world!');
|
|
87
|
+
fs.rmSync('/rmDirRecursively', { recursive: true });
|
|
88
|
+
});
|
|
89
|
+
test('readdir returns files and directories', config('async'), async () => {
|
|
90
|
+
const dirents = await fs.promises.readdir(testDir, { withFileTypes: true });
|
|
91
|
+
const files = dirents.filter(dirent => dirent.isFile()).map(dirent => dirent.name);
|
|
92
|
+
const dirs = dirents.filter(dirent => dirent.isDirectory()).map(dirent => dirent.name);
|
|
93
|
+
assert(testFiles.every(file => files.includes(file)));
|
|
94
|
+
assert(testDirectories.every(dir => dirs.includes(dir)));
|
|
95
|
+
});
|
|
96
|
+
test('readdirSync returns files and directories', config('sync'), () => {
|
|
97
|
+
const dirents = fs.readdirSync(testDir, { withFileTypes: true });
|
|
98
|
+
const files = dirents.filter(dirent => dirent.isFile()).map(dirent => dirent.name);
|
|
99
|
+
const dirs = dirents.filter(dirent => dirent.isDirectory()).map(dirent => dirent.name);
|
|
100
|
+
assert(testFiles.every(file => files.includes(file)));
|
|
101
|
+
assert(testDirectories.every(dir => dirs.includes(dir)));
|
|
102
|
+
});
|
|
103
|
+
test('readdir returns Dirent objects', config('async'), async () => {
|
|
104
|
+
const dirents = await fs.promises.readdir(testDir, { withFileTypes: true });
|
|
105
|
+
assert(dirents[0] instanceof fs.Dirent);
|
|
106
|
+
});
|
|
107
|
+
test('readdirSync returns Dirent objects', config('sync'), () => {
|
|
108
|
+
const dirents = fs.readdirSync(testDir, { withFileTypes: true });
|
|
109
|
+
assert(dirents[0] instanceof fs.Dirent);
|
|
110
|
+
});
|
|
111
|
+
test('readdir works without withFileTypes option', config('async'), async () => {
|
|
112
|
+
const files = await fs.promises.readdir(testDir);
|
|
113
|
+
assert(testFiles.every(entry => files.includes(entry)));
|
|
114
|
+
assert(testDirectories.every(entry => files.includes(entry)));
|
|
115
|
+
});
|
|
116
|
+
test('readdirSync works without withFileTypes option', config('sync'), () => {
|
|
117
|
+
const files = fs.readdirSync(testDir);
|
|
118
|
+
assert(testFiles.every(entry => files.includes(entry)));
|
|
119
|
+
assert(testDirectories.every(entry => files.includes(entry)));
|
|
120
|
+
});
|
|
121
|
+
test('readdir returns files recursively', config('async'), async () => {
|
|
122
|
+
const entries = await fs.promises.readdir(testDir, { recursive: true });
|
|
123
|
+
assert(entries.includes('file1.txt'));
|
|
124
|
+
assert(entries.includes('subdir1/file4.txt'));
|
|
125
|
+
assert(entries.includes('subdir2/file5.txt'));
|
|
126
|
+
});
|
|
127
|
+
test('readdir returns Dirent recursively', config('async'), async () => {
|
|
128
|
+
const entries = await fs.promises.readdir(testDir, { recursive: true, withFileTypes: true });
|
|
129
|
+
entries.sort((a, b) => join(a.parentPath, a.name).localeCompare(join(b.parentPath, b.name)));
|
|
130
|
+
const values = entries.map(entry => [entry.parentPath, entry.name]);
|
|
131
|
+
// `parentPath` is resolved against the directory that was read
|
|
132
|
+
assert.deepEqual(values[0], ['/' + testDir, 'file1.txt']);
|
|
133
|
+
assert.deepEqual(values[4], ['/' + testDir + '/subdir1', 'file4.txt']);
|
|
134
|
+
assert.deepEqual(values[8], ['/' + testDir + '/subdir2', 'file5.txt']);
|
|
135
|
+
});
|
|
136
|
+
test('readdirSync returns files recursively', config('sync'), () => {
|
|
137
|
+
const entries = fs.readdirSync(testDir, { recursive: true }).sort();
|
|
138
|
+
assert.equal(entries[0], 'file1.txt');
|
|
139
|
+
assert.equal(entries[4], 'subdir1/file4.txt');
|
|
140
|
+
assert.equal(entries[8], 'subdir2/file5.txt');
|
|
141
|
+
});
|
|
142
|
+
test('Cyrillic file names', config('sync'), () => {
|
|
143
|
+
fs.writeFileSync('/мой-файл.txt', 'HELLO!', 'utf-8');
|
|
144
|
+
assert(fs.readdirSync('/').includes('мой-файл.txt'));
|
|
145
|
+
});
|
|
146
|
+
test('re-creating a deleted path still shows up in readdir #305', config('sync'), () => {
|
|
147
|
+
fs.unlinkSync('/elipses.txt');
|
|
148
|
+
fs.writeFileSync('/elipses.txt', '...');
|
|
149
|
+
assert(fs.readdirSync('/').includes('elipses.txt'));
|
|
150
|
+
});
|
|
151
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|