Skip to content

Commit 2e1708a

Browse files
committed
runtime.stat: 'other' for what is neither a file nor a folder (FileType.Unknown, a link to nothing); links are made to files only
1 parent 6afd1c5 commit 2e1708a

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎web/shell/src/runtime.js‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ const { forNote, safeMessage, safeGet } = require('./sanitize');
5656

5757
/** vscode.FileType.Directory (a stable bit of the API). */
5858
const DIR = 2;
59+
/** vscode.FileType.File. */
60+
const FILE = 1;
5961
const HOWS = new Set(['exit', 'limit', 'deadline', 'aborted', 'error']);
6062
/** The exit status of a run that did not run to its end, by how it ended. */
6163
const EXIT_FOR_HOW = /** @type {Record<string, number>} */ ({ limit: 126, deadline: 124, aborted: 130, error: 1 });
@@ -1133,19 +1135,22 @@ function createRuntime(deps) {
11331135
function resolve(p) { return resolveIn(currentMounts(), p); }
11341136

11351137
/**
1136-
* What is at an engine path: { type: 'file'|'dir', size } - or null when nothing is, when it is in no mount, or when
1137-
* the file system did not say in `workers.fsMs` or failed. Never throws and never waits longer: a caller that
1138-
* cannot wait that long (a link under the mouse) races its own timer, as the answer is cheap to drop.
1138+
* What is at an engine path: { type: 'file'|'dir'|'other', size } - or null when nothing is, when it is in no mount,
1139+
* or when the file system did not say in `workers.fsMs` or failed. 'other' is what a provider that does not say
1140+
* (FileType.Unknown) or a link to nothing answers: the engine reads it as a file (kindOf), a link is not made to it.
1141+
* Never throws and never waits longer: a caller that cannot wait that long (a link under the mouse) races its own
1142+
* timer, as the answer is cheap to drop.
11391143
* @param {string} p
1140-
* @returns {Promise<{ type: 'file'|'dir', size: number } | null>}
1144+
* @returns {Promise<{ type: 'file'|'dir'|'other', size: number } | null>}
11411145
*/
11421146
async function stat(p) {
11431147
try {
11441148
const uri = resolve(p);
11451149
if (!uri) { return null; }
11461150
const s = await withTimeout(vscode.workspace.fs.stat(uri), limits.workers.fsMs);
11471151
const size = sizeOf(s);
1148-
return { type: kindOf(s.type), size: size === null ? 0 : size };
1152+
const type = (s.type & DIR) !== 0 ? 'dir' : (s.type & FILE) !== 0 ? 'file' : 'other';
1153+
return { type, size: size === null ? 0 : size };
11491154
} catch { return null; }
11501155
}
11511156

‎web/test/unit/shell-runtime.test.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,13 @@ function readsThenDone(/** @type {Array<[string, string]>} */ reads, /** @type {
12271227
const real = r.ws.fs.stat.bind(r.ws.fs);
12281228
r.ws.fs.stat = async (/** @type {any} */ u) => { const x = await real(u); return /a\.txt$/.test(u.path) ? { type: x.type, mtime: x.mtime } : x; };
12291229
assert.deepStrictEqual(await r.rt.stat('/mnt/home/a.txt'), { type: 'file', size: 0 });
1230+
// a provider that answers FileType.Unknown (0), or a link to nothing (64): not a file a link may be made to
1231+
r.ws.fs.stat = async (/** @type {any} */ u) => { const x = await real(u); return /a\.txt$/.test(u.path) ? { type: 0, size: x.size, mtime: x.mtime } : x; };
1232+
assert.deepStrictEqual(await r.rt.stat('/mnt/home/a.txt'), { type: 'other', size: 3 });
1233+
r.ws.fs.stat = async (/** @type {any} */ u) => { const x = await real(u); return /a\.txt$/.test(u.path) ? { type: 64, size: x.size, mtime: x.mtime } : x; };
1234+
assert.deepStrictEqual(await r.rt.stat('/mnt/home/a.txt'), { type: 'other', size: 3 });
1235+
r.ws.fs.stat = async (/** @type {any} */ u) => { const x = await real(u); return /a\.txt$/.test(u.path) ? { type: 65, size: x.size, mtime: x.mtime } : x; };
1236+
assert.deepStrictEqual(await r.rt.stat('/mnt/home/a.txt'), { type: 'file', size: 3 }, 'a link to a file is a file');
12301237
r.ws.fs.stat = real;
12311238
assert.strictEqual(await r.rt.stat('/mnt/home/missing'), null);
12321239
assert.strictEqual(await r.rt.stat('/mnt/home/a.txt/under'), null, 'ENOTDIR is nothing too');

0 commit comments

Comments
 (0)