@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
package/tests/fs/watch.test.ts
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
2
|
-
import type { Stats } from '@zenfs/core';
|
|
3
|
-
import assert from 'node:assert/strict';
|
|
4
|
-
import { suite, test } from 'node:test';
|
|
5
|
-
import { config, fs } from '@zenfs/devel/tests/common';
|
|
6
|
-
|
|
7
|
-
const testDir = '/test-watch-dir';
|
|
8
|
-
const testFile = testDir + '/test.txt';
|
|
9
|
-
|
|
10
|
-
await fs.promises.mkdir(testDir);
|
|
11
|
-
await fs.promises.writeFile(testFile, 'Initial content');
|
|
12
|
-
|
|
13
|
-
/** Fail instead of hanging the suite if an expected event is never emitted */
|
|
14
|
-
async function withTimeout<T>(promise: Promise<T>, ms: number = 1000): Promise<T> {
|
|
15
|
-
const { promise: timedOut, reject } = Promise.withResolvers<never>();
|
|
16
|
-
const timer = setTimeout(() => reject(new Error(`Timed out after ${ms} ms waiting for an event`)), ms);
|
|
17
|
-
timer.unref?.();
|
|
18
|
-
try {
|
|
19
|
-
return await Promise.race([promise, timedOut]);
|
|
20
|
-
} finally {
|
|
21
|
-
clearTimeout(timer);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @todo convert `using watcher = ...` to void discards pending ES proposal
|
|
27
|
-
*/
|
|
28
|
-
suite('Watch', config('watch'), () => {
|
|
29
|
-
test('Events emitted on file change', async () => {
|
|
30
|
-
const { promise, resolve } = Promise.withResolvers<[string, string]>();
|
|
31
|
-
|
|
32
|
-
using watcher = fs.watch(testFile, (eventType, filename) => {
|
|
33
|
-
resolve([eventType, filename]);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
// Modify the file to trigger the event
|
|
37
|
-
await fs.promises.writeFile(testFile, 'Updated content');
|
|
38
|
-
|
|
39
|
-
const [eventType, filename] = await withTimeout(promise);
|
|
40
|
-
assert.equal(eventType, 'change');
|
|
41
|
-
assert.equal(filename, 'test.txt');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('Events emitted on metadata change', async () => {
|
|
45
|
-
const { promise, resolve } = Promise.withResolvers<[string, string]>();
|
|
46
|
-
|
|
47
|
-
using watcher = fs.watch(testFile, (eventType, filename) => {
|
|
48
|
-
resolve([eventType, filename]);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
fs.chmodSync(testFile, 0o600);
|
|
52
|
-
|
|
53
|
-
const [eventType, filename] = await withTimeout(promise);
|
|
54
|
-
assert.equal(eventType, 'change');
|
|
55
|
-
assert.equal(filename, 'test.txt');
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test('Events are emitted on delete', async () => {
|
|
59
|
-
const { promise, resolve } = Promise.withResolvers<string>();
|
|
60
|
-
|
|
61
|
-
/* Only wait for the 'rename'. Deleting a watched file changes its link count,
|
|
62
|
-
which some implementations report as a 'change' event first. */
|
|
63
|
-
using watcher = fs.watch(testFile, (eventType, filename) => {
|
|
64
|
-
if (eventType == 'rename') resolve(filename);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// Delete the file to trigger the event
|
|
68
|
-
await fs.promises.unlink(testFile);
|
|
69
|
-
|
|
70
|
-
assert.equal(await withTimeout(promise), 'test.txt');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test('Changes are detected with watchFile()', async () => {
|
|
74
|
-
// The previous test deleted the file, and watching a non-existent file is its own can of worms
|
|
75
|
-
await fs.promises.writeFile(testFile, 'Restored');
|
|
76
|
-
|
|
77
|
-
// Timestamps have millisecond resolution, so make sure the two writes can not share one
|
|
78
|
-
await new Promise(resolve => setImmediate(resolve));
|
|
79
|
-
|
|
80
|
-
const { promise, resolve } = Promise.withResolvers<[Stats, Stats]>();
|
|
81
|
-
const listener = (curr: Stats, prev: Stats) => resolve([curr, prev]);
|
|
82
|
-
|
|
83
|
-
fs.watchFile(testFile, { interval: 50 }, listener);
|
|
84
|
-
|
|
85
|
-
try {
|
|
86
|
-
// Modify the file to trigger the event
|
|
87
|
-
await fs.promises.writeFile(testFile, 'Changed content');
|
|
88
|
-
|
|
89
|
-
const [curr, prev] = await withTimeout(promise, 2000);
|
|
90
|
-
assert(curr.mtimeMs != prev.mtimeMs);
|
|
91
|
-
} finally {
|
|
92
|
-
fs.unwatchFile(testFile, listener);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
test('unwatchFile() works', async () => {
|
|
97
|
-
let changeDetected = false;
|
|
98
|
-
|
|
99
|
-
const listener = () => {
|
|
100
|
-
changeDetected = true;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
fs.watchFile(testFile, listener);
|
|
104
|
-
fs.unwatchFile(testFile, listener);
|
|
105
|
-
|
|
106
|
-
// Modify the file to see if the listener is called
|
|
107
|
-
await fs.promises.writeFile(testFile, 'Another change');
|
|
108
|
-
|
|
109
|
-
// Wait to see if any change is detected
|
|
110
|
-
assert(!changeDetected);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
test('Directories can be watched', async () => {
|
|
114
|
-
const { promise, resolve } = Promise.withResolvers<[string, string]>();
|
|
115
|
-
|
|
116
|
-
using watcher = fs.watch(testDir, (eventType, filename) => {
|
|
117
|
-
resolve([eventType, filename]);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
await fs.promises.writeFile(testDir + '/newFile.txt', 'Content');
|
|
121
|
-
|
|
122
|
-
const [eventType, filename] = await withTimeout(promise);
|
|
123
|
-
// Creating the file adds an entry to the directory, which is a 'rename' event
|
|
124
|
-
assert.equal(eventType, 'rename');
|
|
125
|
-
assert.equal(filename, 'newFile.txt');
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
test('File renames are detected', async () => {
|
|
129
|
-
const oldFileName = 'oldFile.txt';
|
|
130
|
-
const newFileName = 'newFile.txt';
|
|
131
|
-
const oldFile = testDir + '/' + oldFileName;
|
|
132
|
-
const newFile = testDir + '/' + newFileName;
|
|
133
|
-
|
|
134
|
-
await fs.promises.writeFile(oldFile, 'Some content');
|
|
135
|
-
|
|
136
|
-
const events: Record<string, string> = {};
|
|
137
|
-
const { promise, resolve } = Promise.withResolvers<void>();
|
|
138
|
-
|
|
139
|
-
using watcher = fs.watch(testDir, (eventType, filename) => {
|
|
140
|
-
events[filename] ??= eventType;
|
|
141
|
-
if (oldFileName in events && newFileName in events) resolve();
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
// Rename the file to trigger the events
|
|
145
|
-
await fs.promises.rename(oldFile, newFile);
|
|
146
|
-
|
|
147
|
-
await withTimeout(promise);
|
|
148
|
-
// Both names are 'rename': one entry disappears and another appears
|
|
149
|
-
assert.equal(events[oldFileName], 'rename');
|
|
150
|
-
assert.equal(events[newFileName], 'rename');
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
test('File deletions are detected', async () => {
|
|
154
|
-
const tempFile = `${testDir}/tempFile.txt`;
|
|
155
|
-
|
|
156
|
-
await fs.promises.writeFile(tempFile, 'Temporary content');
|
|
157
|
-
|
|
158
|
-
const { promise, resolve } = Promise.withResolvers<string>();
|
|
159
|
-
|
|
160
|
-
// Only wait for the 'rename', see 'Events are emitted on delete'
|
|
161
|
-
using watcher = fs.watch(tempFile, (eventType, filename) => {
|
|
162
|
-
if (eventType == 'rename') resolve(filename);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
await fs.promises.unlink(tempFile);
|
|
166
|
-
|
|
167
|
-
assert.equal(await withTimeout(promise), 'tempFile.txt');
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
test('File deletions are detected by promises API', async () => {
|
|
171
|
-
const tempFile = `${testDir}/tempFile.txt`;
|
|
172
|
-
|
|
173
|
-
await fs.promises.writeFile(tempFile, 'Temporary content');
|
|
174
|
-
|
|
175
|
-
const ac = new AbortController();
|
|
176
|
-
const watcher = fs.promises.watch(tempFile, { signal: ac.signal });
|
|
177
|
-
|
|
178
|
-
// Only wait for the 'rename', see 'Events are emitted on delete'
|
|
179
|
-
const promise = (async () => {
|
|
180
|
-
for await (const event of watcher) if (event.eventType == 'rename') return event;
|
|
181
|
-
})().catch((e: Error) => {
|
|
182
|
-
if (e.name != 'AbortError') throw e;
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
try {
|
|
186
|
-
await fs.promises.unlink(tempFile);
|
|
187
|
-
|
|
188
|
-
const event = await withTimeout(promise);
|
|
189
|
-
assert.equal(event?.eventType, 'rename');
|
|
190
|
-
assert.equal(event?.filename, 'tempFile.txt');
|
|
191
|
-
} finally {
|
|
192
|
-
/* Abort before return(): a native iterator suspended awaiting an event
|
|
193
|
-
queues return() behind that await, which never resolves */
|
|
194
|
-
ac.abort();
|
|
195
|
-
await watcher.return?.();
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
test('File creations are detected recursively', async () => {
|
|
200
|
-
const subDir = `${testDir}/sub-dir`;
|
|
201
|
-
const tempFile = `${subDir}/tempFile.txt`;
|
|
202
|
-
await fs.promises.mkdir(subDir);
|
|
203
|
-
|
|
204
|
-
const ac = new AbortController();
|
|
205
|
-
const watcher = fs.promises.watch('/', { recursive: true, signal: ac.signal });
|
|
206
|
-
|
|
207
|
-
// Create the file before consuming the iterator, so the first observed event is the unlink
|
|
208
|
-
await fs.promises.writeFile(tempFile, 'Temporary content');
|
|
209
|
-
|
|
210
|
-
const promise = (async () => {
|
|
211
|
-
for await (const event of watcher) return event;
|
|
212
|
-
})().catch((e: Error) => {
|
|
213
|
-
if (e.name != 'AbortError') throw e;
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
try {
|
|
217
|
-
await fs.promises.unlink(tempFile);
|
|
218
|
-
|
|
219
|
-
const event = await withTimeout(promise);
|
|
220
|
-
assert.equal(event?.eventType, 'rename');
|
|
221
|
-
assert.equal(event?.filename, tempFile.slice(1));
|
|
222
|
-
} finally {
|
|
223
|
-
/* Abort before return(): a native iterator suspended awaiting an event
|
|
224
|
-
queues return() behind that await, which never resolves */
|
|
225
|
-
ac.abort();
|
|
226
|
-
await watcher.return?.();
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
test('watch("/") receives events for files under root #293', async () => {
|
|
231
|
-
// Regression: emitChange previously exited its parent-walk before
|
|
232
|
-
// checking watchers.get('/'), so a watcher registered on '/' never fired.
|
|
233
|
-
const { promise, resolve } = Promise.withResolvers<[string, string]>();
|
|
234
|
-
|
|
235
|
-
using watcher = fs.watch('/', (eventType, filename) => {
|
|
236
|
-
resolve([eventType, filename]);
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
await fs.promises.writeFile('/watch-root-file.txt', 'x');
|
|
240
|
-
|
|
241
|
-
const [eventType, filename] = await withTimeout(promise);
|
|
242
|
-
// Creating the file adds an entry to the root directory, which is a 'rename' event
|
|
243
|
-
assert.equal(eventType, 'rename');
|
|
244
|
-
assert.equal(filename, 'watch-root-file.txt');
|
|
245
|
-
});
|
|
246
|
-
});
|
package/tests/fs/write.test.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import { readFileSync } from 'node:fs';
|
|
4
|
-
import { join } from 'node:path/posix';
|
|
5
|
-
import { suite, test } from 'node:test';
|
|
6
|
-
import { config, fs } from '@zenfs/devel/tests/common';
|
|
7
|
-
import { data as dataPath } from '@zenfs/devel/tests/setup';
|
|
8
|
-
|
|
9
|
-
const fileName = 'write.txt';
|
|
10
|
-
const utf8example = readFileSync(join(dataPath, 'utf8.txt'), 'utf8');
|
|
11
|
-
|
|
12
|
-
suite('Writes', config('write'), () => {
|
|
13
|
-
test('Using FileHandle and UTF-8', config('async'), async () => {
|
|
14
|
-
const expected = 'ümlaut.';
|
|
15
|
-
|
|
16
|
-
const handle = await fs.promises.open(fileName, 'w', 0o644);
|
|
17
|
-
await handle.write('', 0, 'utf8');
|
|
18
|
-
const { bytesWritten } = await handle.write(expected, 0, 'utf8');
|
|
19
|
-
assert.equal(bytesWritten, Buffer.from(expected).length);
|
|
20
|
-
await handle.close();
|
|
21
|
-
|
|
22
|
-
const data = await fs.promises.readFile(fileName, 'utf8');
|
|
23
|
-
assert.equal(data, expected);
|
|
24
|
-
|
|
25
|
-
await fs.promises.unlink(fileName);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('Using FileHandle with buffer', config('async'), async () => {
|
|
29
|
-
const expected = Buffer.from('hello');
|
|
30
|
-
|
|
31
|
-
const handle = await fs.promises.open(fileName, 'w', 0o644);
|
|
32
|
-
|
|
33
|
-
const written = await handle.write(expected, 0, expected.length, null);
|
|
34
|
-
|
|
35
|
-
assert.equal(expected.length, written.bytesWritten);
|
|
36
|
-
|
|
37
|
-
await handle.close();
|
|
38
|
-
|
|
39
|
-
assert.deepEqual(await fs.promises.readFile(fileName), expected);
|
|
40
|
-
|
|
41
|
-
await fs.promises.unlink(fileName);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('Using sync path functions', config('sync'), () => {
|
|
45
|
-
const fd = fs.openSync(fileName, 'w');
|
|
46
|
-
|
|
47
|
-
let written = fs.writeSync(fd, '');
|
|
48
|
-
assert.equal(written, 0);
|
|
49
|
-
|
|
50
|
-
fs.writeSync(fd, 'foo');
|
|
51
|
-
|
|
52
|
-
const data = Buffer.from('bár');
|
|
53
|
-
written = fs.writeSync(fd, data, 0, data.length);
|
|
54
|
-
assert.equal(written, 4);
|
|
55
|
-
|
|
56
|
-
fs.closeSync(fd);
|
|
57
|
-
|
|
58
|
-
assert.equal(fs.readFileSync(fileName, 'utf8'), 'foobár');
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test('Using promises API', config('async'), async () => {
|
|
62
|
-
const filename = 'test.txt';
|
|
63
|
-
await fs.promises.writeFile(filename, utf8example);
|
|
64
|
-
const data = await fs.promises.readFile(filename);
|
|
65
|
-
assert.equal(data.length, Buffer.from(utf8example).length);
|
|
66
|
-
await fs.promises.unlink(filename);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test('Using promises API with buffer', config('async'), async () => {
|
|
70
|
-
const filename = 'test2.txt';
|
|
71
|
-
const expected = Buffer.from(utf8example, 'utf8');
|
|
72
|
-
|
|
73
|
-
await fs.promises.writeFile(filename, expected);
|
|
74
|
-
const actual = await fs.promises.readFile(filename);
|
|
75
|
-
assert.equal(actual.length, expected.length);
|
|
76
|
-
|
|
77
|
-
await fs.promises.unlink(filename);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test('Promises API with base64 data', config('async'), async () => {
|
|
81
|
-
const data = readFileSync(join(dataPath, 'image.jpg'), 'base64');
|
|
82
|
-
|
|
83
|
-
const buffer = Buffer.from(data, 'base64');
|
|
84
|
-
const filePath = 'test.jpg';
|
|
85
|
-
|
|
86
|
-
await fs.promises.writeFile(filePath, buffer);
|
|
87
|
-
|
|
88
|
-
const read = await fs.promises.readFile(filePath, 'base64');
|
|
89
|
-
assert.equal(read, data);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test('Using sync path functions with custom mode', config('sync', 'permissions'), () => {
|
|
93
|
-
const file = 'testWriteFileSync.txt';
|
|
94
|
-
const mode = 0o755;
|
|
95
|
-
|
|
96
|
-
fs.writeFileSync(file, '123', { mode });
|
|
97
|
-
|
|
98
|
-
const content = fs.readFileSync(file, 'utf8');
|
|
99
|
-
assert.equal(content, '123');
|
|
100
|
-
assert.equal(fs.statSync(file).mode & 0o777, mode);
|
|
101
|
-
|
|
102
|
-
fs.unlinkSync(file);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test('Appending to a file synchronously with custom mode', config('sync', 'appends', 'permissions'), () => {
|
|
106
|
-
const file = 'testAppendFileSync.txt';
|
|
107
|
-
const mode = 0o755;
|
|
108
|
-
|
|
109
|
-
fs.appendFileSync(file, 'abc', { mode });
|
|
110
|
-
|
|
111
|
-
const content = fs.readFileSync(file, { encoding: 'utf8' });
|
|
112
|
-
assert.equal(content, 'abc');
|
|
113
|
-
|
|
114
|
-
assert.equal(fs.statSync(file).mode & 0o777, mode);
|
|
115
|
-
|
|
116
|
-
fs.unlinkSync(file);
|
|
117
|
-
});
|
|
118
|
-
});
|
package/tests/fs/xattr.test.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
2
|
-
import { Buffer } from 'buffer';
|
|
3
|
-
import assert from 'node:assert/strict';
|
|
4
|
-
import { suite, test } from 'node:test';
|
|
5
|
-
import { config, fs } from '@zenfs/devel/tests/common';
|
|
6
|
-
|
|
7
|
-
suite('Extended Attributes', config('xattr'), () => {
|
|
8
|
-
const testFile = 'xattr-test.txt';
|
|
9
|
-
const testValue = 'test value';
|
|
10
|
-
const testName = 'user.test';
|
|
11
|
-
|
|
12
|
-
test.before(() => fs.promises.writeFile(testFile, 'test content'));
|
|
13
|
-
test.after(() => fs.promises.unlink(testFile));
|
|
14
|
-
|
|
15
|
-
test('Non-user attribute set fails', async () => {
|
|
16
|
-
await assert.rejects(fs.xattr.set(testFile, 'system.test', 'value'), { code: 'ENOTSUP' });
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test('set and get attributes', async () => {
|
|
20
|
-
await fs.xattr.set(testFile, testName, testValue);
|
|
21
|
-
const value = await fs.xattr.get(testFile, testName, { encoding: 'utf8' });
|
|
22
|
-
assert.equal(value, testValue);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('set is kept when an open handle with unsynced changes is synced', async () => {
|
|
26
|
-
await using handle = await fs.promises.open(testFile, 'r');
|
|
27
|
-
await handle.chmod(0o640);
|
|
28
|
-
await fs.xattr.set(testFile, 'user.unsynced', 'value');
|
|
29
|
-
await handle.sync();
|
|
30
|
-
|
|
31
|
-
assert.equal(await fs.xattr.get(testFile, 'user.unsynced', { encoding: 'utf8' }), 'value');
|
|
32
|
-
assert.equal((await fs.promises.stat(testFile)).mode & 0o777, 0o640);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('get attributes with buffer encoding', async () => {
|
|
36
|
-
await fs.xattr.set(testFile, 'user.buffer', 'buffer value');
|
|
37
|
-
const buffer = await fs.xattr.get(testFile, 'user.buffer', { encoding: 'buffer' });
|
|
38
|
-
assert(buffer instanceof Uint8Array);
|
|
39
|
-
assert.equal(Buffer.from(buffer).toString(), 'buffer value');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test('remove attributes', async () => {
|
|
43
|
-
await fs.xattr.set(testFile, 'user.to-remove', testValue);
|
|
44
|
-
await fs.xattr.remove(testFile, 'user.to-remove');
|
|
45
|
-
|
|
46
|
-
await assert.rejects(fs.xattr.get(testFile, 'user.to-remove', { encoding: 'utf8' }), { code: 'ENODATA' });
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
test('list attributes', async () => {
|
|
50
|
-
await fs.xattr.set(testFile, 'user.list1', 'value1');
|
|
51
|
-
await fs.xattr.set(testFile, 'user.list2', 'value2');
|
|
52
|
-
|
|
53
|
-
const attrs = await fs.xattr.list(testFile);
|
|
54
|
-
assert(attrs.includes('user.list1'));
|
|
55
|
-
assert(attrs.includes('user.list2'));
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test('handle create and replace options', async () => {
|
|
59
|
-
const flagTestName = 'user.flag-test';
|
|
60
|
-
|
|
61
|
-
await fs.xattr.set(testFile, flagTestName, 'original', { create: true });
|
|
62
|
-
|
|
63
|
-
await assert.rejects(fs.xattr.set(testFile, flagTestName, 'new value', { create: true }), { code: 'EEXIST' });
|
|
64
|
-
|
|
65
|
-
await fs.xattr.set(testFile, flagTestName, 'updated', { replace: true });
|
|
66
|
-
const value = await fs.xattr.get(testFile, flagTestName, { encoding: 'utf8' });
|
|
67
|
-
assert.equal(value, 'updated');
|
|
68
|
-
|
|
69
|
-
await assert.rejects(fs.xattr.set(testFile, 'user.nonexistent', 'value', { replace: true }), { code: 'ENODATA' });
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
test('file must exist', async () => {
|
|
73
|
-
await assert.rejects(fs.xattr.set('nonexistent-file.txt', testName, 'value'), { code: 'ENOENT' });
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test('synchronous operations', config('sync'), () => {
|
|
77
|
-
const syncAttrName = 'user.sync-test';
|
|
78
|
-
|
|
79
|
-
fs.xattr.setSync(testFile, syncAttrName, testValue);
|
|
80
|
-
const value = fs.xattr.getSync(testFile, syncAttrName, { encoding: 'utf8' });
|
|
81
|
-
assert.equal(value, testValue);
|
|
82
|
-
|
|
83
|
-
fs.xattr.removeSync(testFile, syncAttrName);
|
|
84
|
-
|
|
85
|
-
assert.throws(() => fs.xattr.getSync(testFile, syncAttrName, { encoding: 'utf8' }), { code: 'ENODATA' });
|
|
86
|
-
|
|
87
|
-
const syncList1 = 'user.sync-list1';
|
|
88
|
-
const syncList2 = 'user.sync-list2';
|
|
89
|
-
fs.xattr.setSync(testFile, syncList1, 'value1');
|
|
90
|
-
fs.xattr.setSync(testFile, syncList2, 'value2');
|
|
91
|
-
|
|
92
|
-
const attrs = fs.xattr.listSync(testFile);
|
|
93
|
-
assert(attrs.includes(syncList1));
|
|
94
|
-
assert(attrs.includes(syncList2));
|
|
95
|
-
});
|
|
96
|
-
});
|
package/tests/setup/memory.ts
DELETED