@cortexkit/opencode-openai-auth 1.9.5 → 1.10.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.js +8 -8
- package/dist/{codex-request-CZ16goZ6.d.ts → codex-request-BLzSBegI.d.ts} +4 -0
- package/dist/{index-4gnwkw3a.js → index-17rh67pr.js} +1 -1
- package/dist/{index-npj40h62.js → index-29ztc0ay.js} +2 -2
- package/dist/{index-f1cqptqa.js → index-361xxyg2.js} +2 -2
- package/dist/index-3p1tc2e2.js +91 -0
- package/dist/index-3r9thx6n.js +76 -0
- package/dist/{index-mcy24ej8.js → index-95z5dpe1.js} +2 -2
- package/dist/index-dcyhv7eh.js +8 -0
- package/dist/{index-y4j7y8b8.js → index-dkhy2peg.js} +1 -1
- package/dist/{index-7qxa018z.js → index-fd3f8vw2.js} +2 -2
- package/dist/{index-s2vrkdj4.js → index-mf3dqvbn.js} +2 -2
- package/dist/{index-cf0mrvqj.js → index-mkda7acs.js} +1 -1
- package/dist/{index-s52j2h64.js → index-w37815v4.js} +1 -1
- package/dist/index-ya96m6wr.js +64 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/rpc/port-file.js +1 -1
- package/dist/rpc/protocol.js +1 -1
- package/dist/rpc/rpc-client.js +1 -1
- package/dist/rpc/rpc-dir.js +1 -1
- package/dist/sidebar-state.js +1 -1
- package/dist/{token-djwdynff.js → token-pd3t5f20.js} +1 -1
- package/dist/token-util-807rzwws.js +1 -0
- package/dist/tui-preferences.js +1 -1
- package/dist/v2/server.d.ts +1 -2
- package/dist/v2/server.js +3 -3
- package/package.json +6 -6
- package/src/tui-compiled/raw/shared/30f5bc480f31f51c-roster.js +32 -8
- package/src/tui-compiled/raw/shared/5f8cc863449a6c85-limits-namespace.js +19 -7
- package/src/tui-compiled/raw/shared/92e38944b51b2405-file-read-cache.js +10 -5
- package/src/tui-compiled/raw/shared/c852a15cfe489d12-pool.js +1 -1
- package/src/tui-compiled/raw/shared/e8cd4929507508d8-refresh-file-lock.js +47 -3
- package/src/tui-compiled/runtime/shared/30f5bc480f31f51c-roster.js +32 -8
- package/src/tui-compiled/runtime/shared/5f8cc863449a6c85-limits-namespace.js +19 -7
- package/src/tui-compiled/runtime/shared/92e38944b51b2405-file-read-cache.js +10 -5
- package/src/tui-compiled/runtime/shared/c852a15cfe489d12-pool.js +1 -1
- package/src/tui-compiled/runtime/shared/e8cd4929507508d8-refresh-file-lock.js +47 -3
- package/dist/index-1nrre3d8.js +0 -91
- package/dist/index-41yn5c02.js +0 -8
- package/dist/index-8rj2xddq.js +0 -63
- package/dist/index-h3vtzckv.js +0 -76
- package/dist/token-util-0xt1ws82.js +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { stat } from "node:fs/promises";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
|
+
import { FileReadCache } from "./92e38944b51b2405-file-read-cache.js";
|
|
4
5
|
import { acquireRefreshFileLock, LockContentionError, LockOwnershipError, lockPathFor, PrivateFileError, withLock, writeJsonAtomic, } from "./ec971142548df90e-index.js";
|
|
5
6
|
import { readPrivateText, windowsPrivateFiles } from "./375d9cca2def037d-private-files.js";
|
|
6
7
|
import { decodeQuotaMap, isQuotaObservation, mergeQuotaObservation, } from "./d5a8f1061ee2f114-index.js";
|
|
@@ -333,7 +334,18 @@ function decodeRoster(value) {
|
|
|
333
334
|
export function decodedVaultRoster(roster) {
|
|
334
335
|
return decodeRoster(JSON.parse(JSON.stringify(roster)));
|
|
335
336
|
}
|
|
337
|
+
const rosterReadCache = new FileReadCache({
|
|
338
|
+
followSymlinks: true,
|
|
339
|
+
});
|
|
336
340
|
export async function readVaultRoster(path) {
|
|
341
|
+
// Windows permission, owner and ancestry checks must still run on every read.
|
|
342
|
+
if (windowsPrivateFiles)
|
|
343
|
+
return readFreshVaultRoster(path);
|
|
344
|
+
const roster = await rosterReadCache.read([path], ([resolvedPath = path]) => readFreshVaultRoster(resolvedPath));
|
|
345
|
+
// Callers edit rows and nested limits data; none may own the cached objects.
|
|
346
|
+
return structuredClone(roster);
|
|
347
|
+
}
|
|
348
|
+
async function readFreshVaultRoster(path) {
|
|
337
349
|
let text;
|
|
338
350
|
try {
|
|
339
351
|
text = await readPrivateText(path, windowsPrivateFiles);
|
|
@@ -366,7 +378,8 @@ const DISCOVERY_LEASE = { name: 'claustrum-roster', ttlMs: 30_000 };
|
|
|
366
378
|
*/
|
|
367
379
|
export async function mutateVaultRoster(path, change, options = {}) {
|
|
368
380
|
return withLock(path, { ...WRITE_LOCK, signal: options.signal }, async (lock) => {
|
|
369
|
-
|
|
381
|
+
// A read-modify-write always observes the file under its write lock.
|
|
382
|
+
const current = await readFreshVaultRoster(path);
|
|
370
383
|
const { next, result } = await change(current, {
|
|
371
384
|
assertOwned: () => lock.assertOwned(),
|
|
372
385
|
});
|
|
@@ -374,13 +387,24 @@ export async function mutateVaultRoster(path, change, options = {}) {
|
|
|
374
387
|
await lock.assertOwned();
|
|
375
388
|
// Staging the file takes several awaited steps; check both the caller's
|
|
376
389
|
// lease and this lock again at the last moment before the rename.
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
390
|
+
try {
|
|
391
|
+
await writeJsonAtomic(path, next, {
|
|
392
|
+
beforeRename: async () => {
|
|
393
|
+
await options.beforePublish?.();
|
|
394
|
+
options.signal?.throwIfAborted();
|
|
395
|
+
await lock.assertOwned();
|
|
396
|
+
},
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
catch (error) {
|
|
400
|
+
if (error &&
|
|
401
|
+
typeof error === 'object' &&
|
|
402
|
+
'published' in error &&
|
|
403
|
+
error.published === true)
|
|
404
|
+
options.onPublished?.();
|
|
405
|
+
throw error;
|
|
406
|
+
}
|
|
407
|
+
options.onPublished?.();
|
|
384
408
|
}
|
|
385
409
|
return result;
|
|
386
410
|
});
|
|
@@ -2,7 +2,7 @@ import { writeJsonAtomic } from "./7211cfec06a298bc-atomic-write.js";
|
|
|
2
2
|
import { assertLimitsWriteAllowed, runInsideHook } from "./9deae3c4da4fd63b-hooks.js";
|
|
3
3
|
import { notReadyError, readPool, runOperation } from "./458b934e92490331-mutate.js";
|
|
4
4
|
/** A namespace merge and its check of current row bindings share one locked config snapshot. */
|
|
5
|
-
export async function updatePoolLimitsNamespace(rt, mutator) {
|
|
5
|
+
export async function updatePoolLimitsNamespace(rt, mutator, options = {}) {
|
|
6
6
|
assertLimitsWriteAllowed();
|
|
7
7
|
const { ctx } = rt;
|
|
8
8
|
await runOperation(ctx, 'updateLimitsNamespace', undefined, undefined, async (locks, progress) => {
|
|
@@ -22,13 +22,25 @@ export async function updatePoolLimitsNamespace(rt, mutator) {
|
|
|
22
22
|
operation: 'updateLimitsNamespace',
|
|
23
23
|
rowId: undefined,
|
|
24
24
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
try {
|
|
26
|
+
await writeJsonAtomic(ctx.configPath, config, {
|
|
27
|
+
beforeRename: async () => {
|
|
28
|
+
await ctx.onStep?.('before-config-write', info);
|
|
29
|
+
await locks.assertAll();
|
|
30
|
+
options.beforePublish?.();
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (error &&
|
|
36
|
+
typeof error === 'object' &&
|
|
37
|
+
'published' in error &&
|
|
38
|
+
error.published === true)
|
|
39
|
+
options.onPublished?.();
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
31
42
|
progress.writes++;
|
|
43
|
+
options.onPublished?.();
|
|
32
44
|
await ctx.onStep?.('after-config-write', info);
|
|
33
45
|
});
|
|
34
46
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { lstat } from "node:fs/promises";
|
|
1
|
+
import { lstat, stat } from "node:fs/promises";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
|
-
async function identity(path) {
|
|
3
|
+
async function identity(path, followSymlinks) {
|
|
4
4
|
try {
|
|
5
|
-
|
|
6
|
-
//
|
|
5
|
+
// Match the reader: private readers reject links, while readFile follows
|
|
6
|
+
// them and needs the target's identity, not the link's identity.
|
|
7
|
+
const metadata = await (followSymlinks ? stat(path) : lstat(path));
|
|
7
8
|
return metadata.isFile() ? metadata : undefined;
|
|
8
9
|
}
|
|
9
10
|
catch (error) {
|
|
@@ -23,11 +24,15 @@ function sameIdentity(left, right) {
|
|
|
23
24
|
}
|
|
24
25
|
/** Process-local reads, capped at 64 path sets with one value per resolved set. */
|
|
25
26
|
export class FileReadCache {
|
|
27
|
+
#followSymlinks;
|
|
26
28
|
#entries = new Map();
|
|
29
|
+
constructor(options = {}) {
|
|
30
|
+
this.#followSymlinks = options.followSymlinks ?? false;
|
|
31
|
+
}
|
|
27
32
|
async read(paths, read, validateHit) {
|
|
28
33
|
const resolvedPaths = paths.map((path) => resolve(path));
|
|
29
34
|
const key = JSON.stringify(resolvedPaths);
|
|
30
|
-
const probed = await Promise.all(resolvedPaths.map(identity));
|
|
35
|
+
const probed = await Promise.all(resolvedPaths.map((path) => identity(path, this.#followSymlinks)));
|
|
31
36
|
const identities = probed.every((entry) => entry !== undefined)
|
|
32
37
|
? probed
|
|
33
38
|
: undefined;
|
|
@@ -127,7 +127,7 @@ export function openPoolStore(options) {
|
|
|
127
127
|
reorder: (ids, callOptions) => reorderRows(rt, ids, callOptions),
|
|
128
128
|
readSettings: () => readPoolSettings(rt),
|
|
129
129
|
updateSettings: (mutator, callOptions) => updatePoolSettings(rt, mutator, callOptions),
|
|
130
|
-
updateLimitsNamespace: (mutator) => updatePoolLimitsNamespace(rt, mutator),
|
|
130
|
+
updateLimitsNamespace: (mutator, options) => updatePoolLimitsNamespace(rt, mutator, options),
|
|
131
131
|
recordIdentity: (id, identity, attribution, callOptions) => recordRowIdentity(rt, id, identity, attribution, callOptions),
|
|
132
132
|
refresh: (id, provider, callOptions) => refreshRow(rt, id, provider, callOptions),
|
|
133
133
|
recordQuota: record,
|
|
@@ -1,8 +1,50 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { lstat, mkdir, open, readFile, rename, rm, stat, } from "node:fs/promises";
|
|
2
|
+
import { link, lstat, mkdir, open, readFile, rename, rm, stat, } from "node:fs/promises";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
4
|
import { createPrivateBytes, createPrivateDirectoryExclusive, ensurePrivateDirectory, isWindowsSharingViolation, PrivateFileError, privateOperation, readPrivateText, verifyPrivate, windowsPrivateFiles, writePrivateAtomic, } from "./375d9cca2def037d-private-files.js";
|
|
5
5
|
import { LockOwnershipError, lockPathFor } from "./4825e03209d6ae3e-with-lock.js";
|
|
6
|
+
let leaseCreationTestHooks;
|
|
7
|
+
/** Test-only creation faults; not re-exported from the public fs entry point. */
|
|
8
|
+
export function setLeaseCreationTestHooksForTest(hooks) {
|
|
9
|
+
leaseCreationTestHooks = hooks;
|
|
10
|
+
}
|
|
11
|
+
async function createExclusiveText(path, text) {
|
|
12
|
+
// Publish only a complete owner record. A crash before link leaves at most
|
|
13
|
+
// an orphaned staging file, never an ownerless lease at the lock path.
|
|
14
|
+
const tempPath = `${path}.${randomUUID()}.tmp`;
|
|
15
|
+
let handle;
|
|
16
|
+
try {
|
|
17
|
+
handle = await open(tempPath, 'wx', 0o600);
|
|
18
|
+
try {
|
|
19
|
+
if (leaseCreationTestHooks?.beforeWrite)
|
|
20
|
+
await leaseCreationTestHooks.beforeWrite(tempPath);
|
|
21
|
+
await handle.writeFile(text, 'utf8');
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
await handle.close();
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
if (leaseCreationTestHooks?.beforeLink)
|
|
28
|
+
await leaseCreationTestHooks.beforeLink(tempPath, path);
|
|
29
|
+
await link(tempPath, path);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
const code = error.code;
|
|
33
|
+
if (code !== 'EPERM' &&
|
|
34
|
+
code !== 'ENOTSUP' &&
|
|
35
|
+
code !== 'EOPNOTSUPP' &&
|
|
36
|
+
code !== 'EXDEV')
|
|
37
|
+
throw error;
|
|
38
|
+
// Filesystems without hard links still use exclusive create then write.
|
|
39
|
+
// A crash can leave an incomplete lease there, but locking stays available.
|
|
40
|
+
await writeExclusiveText(path, text);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
if (handle)
|
|
45
|
+
await rm(tempPath, { force: true }).catch(() => { });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
6
48
|
/**
|
|
7
49
|
* Create a new owner-only file and write `text` into it, failing with EEXIST if
|
|
8
50
|
* the file already exists. Writing through the handle rather than path-based
|
|
@@ -11,7 +53,7 @@ import { LockOwnershipError, lockPathFor } from "./4825e03209d6ae3e-with-lock.js
|
|
|
11
53
|
* that redundant ftruncate stalls for hundreds of milliseconds, inside every
|
|
12
54
|
* lock acquisition.
|
|
13
55
|
*/
|
|
14
|
-
async function
|
|
56
|
+
async function writeExclusiveText(path, text) {
|
|
15
57
|
const handle = await open(path, 'wx', 0o600);
|
|
16
58
|
let createdStat;
|
|
17
59
|
try {
|
|
@@ -21,6 +63,8 @@ async function createExclusiveText(path, text) {
|
|
|
21
63
|
createdStat = undefined;
|
|
22
64
|
}
|
|
23
65
|
try {
|
|
66
|
+
if (leaseCreationTestHooks?.beforeWrite)
|
|
67
|
+
await leaseCreationTestHooks.beforeWrite(path);
|
|
24
68
|
await handle.writeFile(text, 'utf8');
|
|
25
69
|
}
|
|
26
70
|
catch (error) {
|
|
@@ -491,7 +535,7 @@ export async function acquireRefreshFileLockWithClock(options) {
|
|
|
491
535
|
if (windowsPrivateFiles)
|
|
492
536
|
await createPrivateBytes(evictOwnerPath, bytes);
|
|
493
537
|
else
|
|
494
|
-
await
|
|
538
|
+
await writeExclusiveText(evictOwnerPath, bytes);
|
|
495
539
|
}
|
|
496
540
|
catch (error) {
|
|
497
541
|
// A competing contender can rename our just-created marker directory
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { stat } from "node:fs/promises";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
|
+
import { FileReadCache } from "./92e38944b51b2405-file-read-cache.js";
|
|
4
5
|
import { acquireRefreshFileLock, LockContentionError, LockOwnershipError, lockPathFor, PrivateFileError, withLock, writeJsonAtomic, } from "./ec971142548df90e-index.js";
|
|
5
6
|
import { readPrivateText, windowsPrivateFiles } from "./375d9cca2def037d-private-files.js";
|
|
6
7
|
import { decodeQuotaMap, isQuotaObservation, mergeQuotaObservation, } from "./d5a8f1061ee2f114-index.js";
|
|
@@ -333,7 +334,18 @@ function decodeRoster(value) {
|
|
|
333
334
|
export function decodedVaultRoster(roster) {
|
|
334
335
|
return decodeRoster(JSON.parse(JSON.stringify(roster)));
|
|
335
336
|
}
|
|
337
|
+
const rosterReadCache = new FileReadCache({
|
|
338
|
+
followSymlinks: true,
|
|
339
|
+
});
|
|
336
340
|
export async function readVaultRoster(path) {
|
|
341
|
+
// Windows permission, owner and ancestry checks must still run on every read.
|
|
342
|
+
if (windowsPrivateFiles)
|
|
343
|
+
return readFreshVaultRoster(path);
|
|
344
|
+
const roster = await rosterReadCache.read([path], ([resolvedPath = path]) => readFreshVaultRoster(resolvedPath));
|
|
345
|
+
// Callers edit rows and nested limits data; none may own the cached objects.
|
|
346
|
+
return structuredClone(roster);
|
|
347
|
+
}
|
|
348
|
+
async function readFreshVaultRoster(path) {
|
|
337
349
|
let text;
|
|
338
350
|
try {
|
|
339
351
|
text = await readPrivateText(path, windowsPrivateFiles);
|
|
@@ -366,7 +378,8 @@ const DISCOVERY_LEASE = { name: 'claustrum-roster', ttlMs: 30_000 };
|
|
|
366
378
|
*/
|
|
367
379
|
export async function mutateVaultRoster(path, change, options = {}) {
|
|
368
380
|
return withLock(path, { ...WRITE_LOCK, signal: options.signal }, async (lock) => {
|
|
369
|
-
|
|
381
|
+
// A read-modify-write always observes the file under its write lock.
|
|
382
|
+
const current = await readFreshVaultRoster(path);
|
|
370
383
|
const { next, result } = await change(current, {
|
|
371
384
|
assertOwned: () => lock.assertOwned(),
|
|
372
385
|
});
|
|
@@ -374,13 +387,24 @@ export async function mutateVaultRoster(path, change, options = {}) {
|
|
|
374
387
|
await lock.assertOwned();
|
|
375
388
|
// Staging the file takes several awaited steps; check both the caller's
|
|
376
389
|
// lease and this lock again at the last moment before the rename.
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
390
|
+
try {
|
|
391
|
+
await writeJsonAtomic(path, next, {
|
|
392
|
+
beforeRename: async () => {
|
|
393
|
+
await options.beforePublish?.();
|
|
394
|
+
options.signal?.throwIfAborted();
|
|
395
|
+
await lock.assertOwned();
|
|
396
|
+
},
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
catch (error) {
|
|
400
|
+
if (error &&
|
|
401
|
+
typeof error === 'object' &&
|
|
402
|
+
'published' in error &&
|
|
403
|
+
error.published === true)
|
|
404
|
+
options.onPublished?.();
|
|
405
|
+
throw error;
|
|
406
|
+
}
|
|
407
|
+
options.onPublished?.();
|
|
384
408
|
}
|
|
385
409
|
return result;
|
|
386
410
|
});
|
|
@@ -2,7 +2,7 @@ import { writeJsonAtomic } from "./7211cfec06a298bc-atomic-write.js";
|
|
|
2
2
|
import { assertLimitsWriteAllowed, runInsideHook } from "./9deae3c4da4fd63b-hooks.js";
|
|
3
3
|
import { notReadyError, readPool, runOperation } from "./458b934e92490331-mutate.js";
|
|
4
4
|
/** A namespace merge and its check of current row bindings share one locked config snapshot. */
|
|
5
|
-
export async function updatePoolLimitsNamespace(rt, mutator) {
|
|
5
|
+
export async function updatePoolLimitsNamespace(rt, mutator, options = {}) {
|
|
6
6
|
assertLimitsWriteAllowed();
|
|
7
7
|
const { ctx } = rt;
|
|
8
8
|
await runOperation(ctx, 'updateLimitsNamespace', undefined, undefined, async (locks, progress) => {
|
|
@@ -22,13 +22,25 @@ export async function updatePoolLimitsNamespace(rt, mutator) {
|
|
|
22
22
|
operation: 'updateLimitsNamespace',
|
|
23
23
|
rowId: undefined,
|
|
24
24
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
try {
|
|
26
|
+
await writeJsonAtomic(ctx.configPath, config, {
|
|
27
|
+
beforeRename: async () => {
|
|
28
|
+
await ctx.onStep?.('before-config-write', info);
|
|
29
|
+
await locks.assertAll();
|
|
30
|
+
options.beforePublish?.();
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (error &&
|
|
36
|
+
typeof error === 'object' &&
|
|
37
|
+
'published' in error &&
|
|
38
|
+
error.published === true)
|
|
39
|
+
options.onPublished?.();
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
31
42
|
progress.writes++;
|
|
43
|
+
options.onPublished?.();
|
|
32
44
|
await ctx.onStep?.('after-config-write', info);
|
|
33
45
|
});
|
|
34
46
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { lstat } from "node:fs/promises";
|
|
1
|
+
import { lstat, stat } from "node:fs/promises";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
|
-
async function identity(path) {
|
|
3
|
+
async function identity(path, followSymlinks) {
|
|
4
4
|
try {
|
|
5
|
-
|
|
6
|
-
//
|
|
5
|
+
// Match the reader: private readers reject links, while readFile follows
|
|
6
|
+
// them and needs the target's identity, not the link's identity.
|
|
7
|
+
const metadata = await (followSymlinks ? stat(path) : lstat(path));
|
|
7
8
|
return metadata.isFile() ? metadata : undefined;
|
|
8
9
|
}
|
|
9
10
|
catch (error) {
|
|
@@ -23,11 +24,15 @@ function sameIdentity(left, right) {
|
|
|
23
24
|
}
|
|
24
25
|
/** Process-local reads, capped at 64 path sets with one value per resolved set. */
|
|
25
26
|
export class FileReadCache {
|
|
27
|
+
#followSymlinks;
|
|
26
28
|
#entries = new Map();
|
|
29
|
+
constructor(options = {}) {
|
|
30
|
+
this.#followSymlinks = options.followSymlinks ?? false;
|
|
31
|
+
}
|
|
27
32
|
async read(paths, read, validateHit) {
|
|
28
33
|
const resolvedPaths = paths.map((path) => resolve(path));
|
|
29
34
|
const key = JSON.stringify(resolvedPaths);
|
|
30
|
-
const probed = await Promise.all(resolvedPaths.map(identity));
|
|
35
|
+
const probed = await Promise.all(resolvedPaths.map((path) => identity(path, this.#followSymlinks)));
|
|
31
36
|
const identities = probed.every((entry) => entry !== undefined)
|
|
32
37
|
? probed
|
|
33
38
|
: undefined;
|
|
@@ -127,7 +127,7 @@ export function openPoolStore(options) {
|
|
|
127
127
|
reorder: (ids, callOptions) => reorderRows(rt, ids, callOptions),
|
|
128
128
|
readSettings: () => readPoolSettings(rt),
|
|
129
129
|
updateSettings: (mutator, callOptions) => updatePoolSettings(rt, mutator, callOptions),
|
|
130
|
-
updateLimitsNamespace: (mutator) => updatePoolLimitsNamespace(rt, mutator),
|
|
130
|
+
updateLimitsNamespace: (mutator, options) => updatePoolLimitsNamespace(rt, mutator, options),
|
|
131
131
|
recordIdentity: (id, identity, attribution, callOptions) => recordRowIdentity(rt, id, identity, attribution, callOptions),
|
|
132
132
|
refresh: (id, provider, callOptions) => refreshRow(rt, id, provider, callOptions),
|
|
133
133
|
recordQuota: record,
|
|
@@ -1,8 +1,50 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { lstat, mkdir, open, readFile, rename, rm, stat, } from "node:fs/promises";
|
|
2
|
+
import { link, lstat, mkdir, open, readFile, rename, rm, stat, } from "node:fs/promises";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
4
|
import { createPrivateBytes, createPrivateDirectoryExclusive, ensurePrivateDirectory, isWindowsSharingViolation, PrivateFileError, privateOperation, readPrivateText, verifyPrivate, windowsPrivateFiles, writePrivateAtomic, } from "./375d9cca2def037d-private-files.js";
|
|
5
5
|
import { LockOwnershipError, lockPathFor } from "./4825e03209d6ae3e-with-lock.js";
|
|
6
|
+
let leaseCreationTestHooks;
|
|
7
|
+
/** Test-only creation faults; not re-exported from the public fs entry point. */
|
|
8
|
+
export function setLeaseCreationTestHooksForTest(hooks) {
|
|
9
|
+
leaseCreationTestHooks = hooks;
|
|
10
|
+
}
|
|
11
|
+
async function createExclusiveText(path, text) {
|
|
12
|
+
// Publish only a complete owner record. A crash before link leaves at most
|
|
13
|
+
// an orphaned staging file, never an ownerless lease at the lock path.
|
|
14
|
+
const tempPath = `${path}.${randomUUID()}.tmp`;
|
|
15
|
+
let handle;
|
|
16
|
+
try {
|
|
17
|
+
handle = await open(tempPath, 'wx', 0o600);
|
|
18
|
+
try {
|
|
19
|
+
if (leaseCreationTestHooks?.beforeWrite)
|
|
20
|
+
await leaseCreationTestHooks.beforeWrite(tempPath);
|
|
21
|
+
await handle.writeFile(text, 'utf8');
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
await handle.close();
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
if (leaseCreationTestHooks?.beforeLink)
|
|
28
|
+
await leaseCreationTestHooks.beforeLink(tempPath, path);
|
|
29
|
+
await link(tempPath, path);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
const code = error.code;
|
|
33
|
+
if (code !== 'EPERM' &&
|
|
34
|
+
code !== 'ENOTSUP' &&
|
|
35
|
+
code !== 'EOPNOTSUPP' &&
|
|
36
|
+
code !== 'EXDEV')
|
|
37
|
+
throw error;
|
|
38
|
+
// Filesystems without hard links still use exclusive create then write.
|
|
39
|
+
// A crash can leave an incomplete lease there, but locking stays available.
|
|
40
|
+
await writeExclusiveText(path, text);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
if (handle)
|
|
45
|
+
await rm(tempPath, { force: true }).catch(() => { });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
6
48
|
/**
|
|
7
49
|
* Create a new owner-only file and write `text` into it, failing with EEXIST if
|
|
8
50
|
* the file already exists. Writing through the handle rather than path-based
|
|
@@ -11,7 +53,7 @@ import { LockOwnershipError, lockPathFor } from "./4825e03209d6ae3e-with-lock.js
|
|
|
11
53
|
* that redundant ftruncate stalls for hundreds of milliseconds, inside every
|
|
12
54
|
* lock acquisition.
|
|
13
55
|
*/
|
|
14
|
-
async function
|
|
56
|
+
async function writeExclusiveText(path, text) {
|
|
15
57
|
const handle = await open(path, 'wx', 0o600);
|
|
16
58
|
let createdStat;
|
|
17
59
|
try {
|
|
@@ -21,6 +63,8 @@ async function createExclusiveText(path, text) {
|
|
|
21
63
|
createdStat = undefined;
|
|
22
64
|
}
|
|
23
65
|
try {
|
|
66
|
+
if (leaseCreationTestHooks?.beforeWrite)
|
|
67
|
+
await leaseCreationTestHooks.beforeWrite(path);
|
|
24
68
|
await handle.writeFile(text, 'utf8');
|
|
25
69
|
}
|
|
26
70
|
catch (error) {
|
|
@@ -491,7 +535,7 @@ export async function acquireRefreshFileLockWithClock(options) {
|
|
|
491
535
|
if (windowsPrivateFiles)
|
|
492
536
|
await createPrivateBytes(evictOwnerPath, bytes);
|
|
493
537
|
else
|
|
494
|
-
await
|
|
538
|
+
await writeExclusiveText(evictOwnerPath, bytes);
|
|
495
539
|
}
|
|
496
540
|
catch (error) {
|
|
497
541
|
// A competing contender can rename our just-created marker directory
|