javascript-solid-server 0.0.202 → 0.0.203
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/package.json
CHANGED
|
@@ -181,6 +181,13 @@ export async function listContainer(urlPath) {
|
|
|
181
181
|
};
|
|
182
182
|
try {
|
|
183
183
|
const stat = await fs.stat(path.join(filePath, entry.name));
|
|
184
|
+
// Dirent.isDirectory() uses lstat semantics, so it is false for
|
|
185
|
+
// *any* symlink — even one targeting a directory. Reclassify from
|
|
186
|
+
// the dereferenced stat so symlinked directories list as containers
|
|
187
|
+
// (trailing slash + ldp:BasicContainer), matching how they behave
|
|
188
|
+
// on a direct GET. A dangling symlink throws here and keeps the
|
|
189
|
+
// lstat-based isDirectory: false. (#531)
|
|
190
|
+
if (entry.isSymbolicLink()) result.isDirectory = stat.isDirectory();
|
|
184
191
|
result.size = stat.size;
|
|
185
192
|
result.modified = stat.mtime.toISOString();
|
|
186
193
|
} catch { /* stat failed, skip metadata */ }
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Regression tests for #531 — listContainer misclassified symlinked
|
|
3
|
+
* directories as plain resources.
|
|
4
|
+
*
|
|
5
|
+
* `fs.readdir(dir, { withFileTypes: true })` returns Dirents with lstat
|
|
6
|
+
* semantics, so `Dirent.isDirectory()` is false for ANY symlink — even one
|
|
7
|
+
* pointing at a directory. listContainer relied on that flag, so a symlinked
|
|
8
|
+
* sub-directory was listed without a trailing slash and typed ldp:Resource
|
|
9
|
+
* instead of ldp:BasicContainer, making it unbrowsable in container listings
|
|
10
|
+
* (while a direct GET, which dereferences, worked fine).
|
|
11
|
+
*
|
|
12
|
+
* The fix reclassifies symlink entries from the dereferenced fs.stat() that
|
|
13
|
+
* listContainer already performs for size/mtime.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, it, before, after } from 'node:test';
|
|
17
|
+
import assert from 'node:assert';
|
|
18
|
+
import fs from 'fs-extra';
|
|
19
|
+
import os from 'os';
|
|
20
|
+
import path from 'path';
|
|
21
|
+
import { listContainer } from '../src/storage/filesystem.js';
|
|
22
|
+
|
|
23
|
+
let TEST_ROOT;
|
|
24
|
+
let originalDataRoot;
|
|
25
|
+
|
|
26
|
+
describe('listContainer — symlink classification (#531)', () => {
|
|
27
|
+
before(async () => {
|
|
28
|
+
originalDataRoot = process.env.DATA_ROOT;
|
|
29
|
+
TEST_ROOT = await fs.mkdtemp(path.join(os.tmpdir(), 'jss-symlink-'));
|
|
30
|
+
process.env.DATA_ROOT = TEST_ROOT;
|
|
31
|
+
|
|
32
|
+
// The container being listed.
|
|
33
|
+
const box = path.join(TEST_ROOT, 'box');
|
|
34
|
+
await fs.ensureDir(box);
|
|
35
|
+
|
|
36
|
+
// Real entries.
|
|
37
|
+
await fs.ensureDir(path.join(box, 'realdir'));
|
|
38
|
+
await fs.writeFile(path.join(box, 'realfile.txt'), 'hi');
|
|
39
|
+
|
|
40
|
+
// Symlink targets live outside the container (and outside DATA_ROOT) to
|
|
41
|
+
// mirror the real-world case of linking external content into a pod.
|
|
42
|
+
const targetDir = path.join(TEST_ROOT, 'external-dir');
|
|
43
|
+
const targetFile = path.join(TEST_ROOT, 'external-file.txt');
|
|
44
|
+
await fs.ensureDir(targetDir);
|
|
45
|
+
await fs.writeFile(targetFile, 'external');
|
|
46
|
+
|
|
47
|
+
await fs.symlink(targetDir, path.join(box, 'linkdir'));
|
|
48
|
+
await fs.symlink(targetFile, path.join(box, 'linkfile.txt'));
|
|
49
|
+
// Dangling symlink — target does not exist.
|
|
50
|
+
await fs.symlink(path.join(TEST_ROOT, 'nope'), path.join(box, 'broken'));
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
after(async () => {
|
|
54
|
+
if (originalDataRoot === undefined) delete process.env.DATA_ROOT;
|
|
55
|
+
else process.env.DATA_ROOT = originalDataRoot;
|
|
56
|
+
await fs.remove(TEST_ROOT);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('classifies a symlink-to-directory as a directory', async () => {
|
|
60
|
+
const entries = await listContainer('box');
|
|
61
|
+
const byName = Object.fromEntries(entries.map((e) => [e.name, e]));
|
|
62
|
+
|
|
63
|
+
assert.strictEqual(byName.linkdir.isDirectory, true,
|
|
64
|
+
'symlinked directory should be listed as a container');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('keeps a symlink-to-file as a non-directory', async () => {
|
|
68
|
+
const entries = await listContainer('box');
|
|
69
|
+
const byName = Object.fromEntries(entries.map((e) => [e.name, e]));
|
|
70
|
+
|
|
71
|
+
assert.strictEqual(byName['linkfile.txt'].isDirectory, false,
|
|
72
|
+
'symlinked file should remain a resource');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('does not regress real directories and files', async () => {
|
|
76
|
+
const entries = await listContainer('box');
|
|
77
|
+
const byName = Object.fromEntries(entries.map((e) => [e.name, e]));
|
|
78
|
+
|
|
79
|
+
assert.strictEqual(byName.realdir.isDirectory, true);
|
|
80
|
+
assert.strictEqual(byName['realfile.txt'].isDirectory, false);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('treats a dangling symlink as a non-directory (stat throws)', async () => {
|
|
84
|
+
const entries = await listContainer('box');
|
|
85
|
+
const byName = Object.fromEntries(entries.map((e) => [e.name, e]));
|
|
86
|
+
|
|
87
|
+
assert.strictEqual(byName.broken.isDirectory, false,
|
|
88
|
+
'a dangling symlink keeps the lstat-based isDirectory: false');
|
|
89
|
+
});
|
|
90
|
+
});
|