@cortexkit/opencode-magic-context 0.49.84 → 0.49.85
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/{announcement-p41dde4h.js → announcement-fnyxaahs.js} +3 -1
- package/dist/auto-search-worker.js +3 -3
- package/dist/chunk-embedding-write-worker.js +5 -4
- package/dist/{context-3sajdysh.js → context-bjfwzbts.js} +27 -26
- package/dist/{derive-budgets-0kcek5ex.js → derive-budgets-90869322.js} +3 -1
- package/dist/{embedding-backfill-k994xdas.js → embedding-backfill-v6sw58m8.js} +7 -5
- package/dist/embedding-worker.js +15 -27
- package/dist/features/magic-context/memory/embedding-worker-boundary.test-support.d.ts +24 -0
- package/dist/features/magic-context/memory/embedding-worker-boundary.test-support.d.ts.map +1 -0
- package/dist/features/magic-context/memory/embedding-worker-client.d.ts +35 -1
- package/dist/features/magic-context/memory/embedding-worker-client.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-worker-loop.d.ts +57 -0
- package/dist/features/magic-context/memory/embedding-worker-loop.d.ts.map +1 -0
- package/dist/features/magic-context/project-embedding-registry.d.ts +6 -1
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/features/magic-context/storage-db.d.ts.map +1 -1
- package/dist/hooks/magic-context/lkg-recovery-fence.d.ts.map +1 -1
- package/dist/{index-tvbkemec.js → index-08jfpny9.js} +1 -1
- package/dist/{index-k0jnsjcp.js → index-0rge5rkh.js} +6 -6
- package/dist/{index-0wehkw71.js → index-1pf5qrx4.js} +4 -4
- package/dist/{index-98qy103c.js → index-2kf73btc.js} +1 -1
- package/dist/{index-vpw46557.js → index-3dtzyred.js} +1 -1
- package/dist/{index-bd34njzg.js → index-4ntnt8ee.js} +1 -1
- package/dist/{index-w2wpx7t5.js → index-4w5rx7de.js} +1 -1
- package/dist/{index-xd0ww0ns.js → index-798s7c8s.js} +1 -1
- package/dist/{index-fpqdbb67.js → index-7svecf3m.js} +3 -3
- package/dist/{index-tqnvn9pa.js → index-9fsxmjs6.js} +3 -3
- package/dist/{v2/server-fvnzcnww.js → index-c5tmzym6.js} +192 -11
- package/dist/{index-w8dcjt7f.js → index-k0tb2z28.js} +1 -1
- package/dist/{index-zb4h9nrk.js → index-k50xhjw1.js} +202 -14
- package/dist/{index-qybp04ff.js → index-kqnef2tg.js} +3 -3
- package/dist/{index-szwrpyac.js → index-nny4gm06.js} +1 -1
- package/dist/{index-fgy6hnr3.js → index-pw279hmt.js} +2 -2
- package/dist/{index-xjfan0za.js → index-qvn3q9f1.js} +37 -37
- package/dist/{index-shpyv8gq.js → index-s8ks5nz4.js} +16 -9
- package/dist/{index-cfy5k1pa.js → index-sbr58jaf.js} +5 -5
- package/dist/{index-d028gmgp.js → index-tzbcb8yt.js} +14 -14
- package/dist/{index-skwwbcnv.js → index-w6v4dw5f.js} +24 -24
- package/dist/{index-5wjv4c41.js → index-xccywqdj.js} +15 -15
- package/dist/{index-kthfyf45.js → index-zmqx48vt.js} +3 -3
- package/dist/index.js +33 -33
- package/dist/migration-worker.js +4 -3
- package/dist/{project-embedding-registry-y3z36mjy.js → project-embedding-registry-q80scexh.js} +6 -4
- package/dist/raw-ordinal-warmup-worker.js +2 -2
- package/dist/{recomp-orchestrator-m2s3jpvj.js → recomp-orchestrator-xzs0a455.js} +16 -15
- package/dist/{render-p2j7rn9a.js → render-yqp7q79f.js} +8 -7
- package/dist/{search-archive-hz9xh7nh.js → search-archive-r4h96j2z.js} +2 -2
- package/dist/{search-ksx0f1qd.js → search-ztgy3ya6.js} +12 -10
- package/dist/shared/storage-file-mutex.d.ts.map +1 -1
- package/dist/shared/storage-permissions.d.ts +5 -3
- package/dist/shared/storage-permissions.d.ts.map +1 -1
- package/dist/{store-x0swqb5c.js → store-n4yz3n66.js} +2 -2
- package/dist/{store-reader-tsv1w4vt.js → store-reader-nf8z86n9.js} +1 -1
- package/dist/{transform-postprocess-phase-1wb2rrr1.js → transform-postprocess-phase-39a5hm2a.js} +17 -16
- package/dist/v2/auto-search-worker.js +3 -3
- package/dist/v2/chunk-embedding-write-worker.js +5 -4
- package/dist/v2/{context-at9nje0j.js → context-k2rrqzf4.js} +39 -39
- package/dist/v2/{derive-budgets-xbwcap8k.js → derive-budgets-ecjy1aqh.js} +4 -2
- package/dist/v2/{embedding-backfill-hjvjxp7d.js → embedding-backfill-k8kqnwfq.js} +7 -5
- package/dist/v2/embedding-worker.js +15 -27
- package/dist/v2/migration-worker.js +4 -3
- package/dist/v2/{project-embedding-registry-mzsvyads.js → project-embedding-registry-2jp1antr.js} +6 -4
- package/dist/v2/raw-ordinal-warmup-worker.js +2 -2
- package/dist/v2/{recomp-orchestrator-nhef90gc.js → recomp-orchestrator-jnbxbsc8.js} +17 -16
- package/dist/v2/{render-c9r2g2jv.js → render-fezgh7pa.js} +8 -7
- package/dist/v2/{search-archive-80ckv9kq.js → search-archive-zz1kza50.js} +2 -2
- package/dist/v2/{search-t06js5dc.js → search-h5w7510x.js} +11 -9
- package/dist/v2/{server-4z964n1c.js → server-3p6b0qya.js} +1 -1
- package/dist/v2/{server-3cndh146.js → server-4wwwm2ya.js} +24 -24
- package/dist/v2/{server-mr9rqn0y.js → server-97w51d8n.js} +4 -4
- package/dist/v2/{server-gx1s06dx.js → server-98hsp35q.js} +2 -2
- package/dist/v2/{server-d706s5xn.js → server-b93f0bqh.js} +205 -17
- package/dist/v2/{server-dfesqfv1.js → server-brgandk4.js} +1 -1
- package/dist/v2/{server-w1jfaxas.js → server-cwtehwbb.js} +1 -1
- package/dist/v2/{server-y4favn4d.js → server-e2k9mt86.js} +1 -1
- package/dist/v2/{server-68q80y27.js → server-hn8b7sfe.js} +16 -9
- package/dist/v2/{server-pejjj0nv.js → server-mbkwcwgw.js} +1 -1
- package/dist/v2/{server-ry6rpspz.js → server-n5zr7190.js} +15 -15
- package/dist/v2/{server-210rc0z9.js → server-ps6rz88g.js} +1 -1
- package/dist/{index-fvnzcnww.js → v2/server-r2es6zt7.js} +192 -11
- package/dist/v2/{server-bt546axy.js → server-rz4snd3x.js} +3 -3
- package/dist/v2/{server-3hhakg5a.js → server-s76ty4ws.js} +13 -13
- package/dist/v2/{server-hhw6rzsn.js → server-w7mpvkpj.js} +1 -1
- package/dist/v2/{server-863bwkga.js → server-x77hd658.js} +6 -6
- package/dist/v2/{server-sy98vksf.js → server-xa8fefhw.js} +3 -3
- package/dist/v2/{server-cce6m31c.js → server-ytqps2xa.js} +1 -1
- package/dist/v2/server.js +6 -4
- package/dist/v2/{store-reader-paamf0ac.js → store-reader-2vhx33n6.js} +1 -1
- package/dist/v2/{store-h3s95ywe.js → store-y56y034s.js} +2 -2
- package/dist/v2/{v2-archive-reader-1zzteaa5.js → v2-archive-reader-e2w39c3p.js} +1 -1
- package/dist/v2/{wrapup-orchestrator-9y98qcqz.js → wrapup-orchestrator-mmje3etf.js} +16 -15
- package/dist/{v2-archive-reader-3yjxaj5z.js → v2-archive-reader-8dsngf2j.js} +1 -1
- package/dist/{wrapup-orchestrator-sa3a075a.js → wrapup-orchestrator-sm6pwf3p.js} +17 -16
- package/package.json +1 -1
- package/src/shared/storage-file-mutex-review.test.ts +125 -2
- package/src/shared/storage-file-mutex.ts +17 -8
- package/src/shared/storage-permissions-creators.test.ts +194 -0
- package/src/shared/storage-permissions-startup.test.ts +476 -0
- package/src/shared/storage-permissions.ts +227 -12
- /package/dist/{index-rdh63md0.js → index-1y4y98r1.js} +0 -0
- /package/dist/v2/{server-9nk5h6w6.js → server-qyazxy92.js} +0 -0
|
@@ -5,11 +5,13 @@
|
|
|
5
5
|
* applying POSIX modes. The default preserves the historical owner-only policy.
|
|
6
6
|
*/
|
|
7
7
|
import { randomBytes } from "node:crypto";
|
|
8
|
-
import type { WriteStream } from "node:fs";
|
|
8
|
+
import type { Stats, WriteStream } from "node:fs";
|
|
9
9
|
import {
|
|
10
10
|
chmodSync,
|
|
11
11
|
closeSync,
|
|
12
|
+
constants,
|
|
12
13
|
createWriteStream,
|
|
14
|
+
fstatSync,
|
|
13
15
|
fsyncSync,
|
|
14
16
|
lstatSync,
|
|
15
17
|
mkdirSync,
|
|
@@ -18,6 +20,7 @@ import {
|
|
|
18
20
|
readlinkSync,
|
|
19
21
|
readSync,
|
|
20
22
|
renameSync,
|
|
23
|
+
rmdirSync,
|
|
21
24
|
rmSync,
|
|
22
25
|
symlinkSync,
|
|
23
26
|
writeFileSync,
|
|
@@ -25,12 +28,55 @@ import {
|
|
|
25
28
|
} from "node:fs";
|
|
26
29
|
import type { FileHandle } from "node:fs/promises";
|
|
27
30
|
import { open as openAsync, writeFile as writeFileAsync } from "node:fs/promises";
|
|
28
|
-
import { dirname, join } from "node:path";
|
|
31
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
32
|
+
import { isPidAlive } from "./rpc-utils";
|
|
29
33
|
|
|
30
34
|
let enforcePrivateStoragePermissions = true;
|
|
35
|
+
const STORAGE_PERMISSIONS_POLICY_VERSION = 1;
|
|
36
|
+
const STORAGE_PERMISSIONS_MARKER = `.storage-permissions-v${STORAGE_PERMISSIONS_POLICY_VERSION}`;
|
|
37
|
+
const STORAGE_PERMISSIONS_MARKER_BYTES = Buffer.from(`${STORAGE_PERMISSIONS_POLICY_VERSION}\n`);
|
|
38
|
+
const STORAGE_PERMISSIONS_MARKER_MAX_AGE_MS = 24 * 60 * 60_000;
|
|
39
|
+
const LEGACY_FENCE_TEMP_MIN_AGE_MS = 10 * 60_000;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Storage roots that this process checked with tightenStorageTreeSync. Only a
|
|
43
|
+
* root has a marker. Each database open checks its root, so a process that
|
|
44
|
+
* writes storage files knows its root.
|
|
45
|
+
*/
|
|
46
|
+
const storagePermissionRoots = new Set<string>();
|
|
47
|
+
|
|
48
|
+
function invalidateStoragePermissionMarkers(directory: string): void {
|
|
49
|
+
// Stop at the storage root: an ancestor of the root has no applicable marker.
|
|
50
|
+
// A directory that is not in a known root continues to the file system
|
|
51
|
+
// root, because a marker that stays can keep the approval of a loose tree.
|
|
52
|
+
for (let current = resolve(directory); ; current = dirname(current)) {
|
|
53
|
+
const marker = join(current, STORAGE_PERMISSIONS_MARKER);
|
|
54
|
+
try {
|
|
55
|
+
rmSync(marker, { force: true });
|
|
56
|
+
} catch (error) {
|
|
57
|
+
const stat = lstatSync(marker, { throwIfNoEntry: false });
|
|
58
|
+
// Only a regular file can be a certificate.
|
|
59
|
+
// A read-only mount can reject an unlink even if the marker is absent.
|
|
60
|
+
if (stat?.isFile() || (!stat && (error as NodeJS.ErrnoException).code !== "EROFS")) {
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (storagePermissionRoots.has(current) || dirname(current) === current) return;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
31
67
|
|
|
32
68
|
export function setStoragePrivatePermissionEnforcement(enforce: boolean): void {
|
|
33
69
|
enforcePrivateStoragePermissions = enforce;
|
|
70
|
+
if (enforce || process.platform === "win32") return;
|
|
71
|
+
// A host can keep its database open across a reload, so the next open does not
|
|
72
|
+
// run the startup walk. Files written while enforcement is off can be loose.
|
|
73
|
+
for (const root of storagePermissionRoots) {
|
|
74
|
+
try {
|
|
75
|
+
rmSync(join(root, STORAGE_PERMISSIONS_MARKER), { force: true });
|
|
76
|
+
} catch {
|
|
77
|
+
// Do not stop the configuration change. The startup walk reports this failure.
|
|
78
|
+
}
|
|
79
|
+
}
|
|
34
80
|
}
|
|
35
81
|
|
|
36
82
|
export function shouldEnforcePrivateStoragePermissions(): boolean {
|
|
@@ -61,7 +107,10 @@ export function ensurePrivateStorageDirectorySync(directory: string): void {
|
|
|
61
107
|
const stat = lstatSync(directory);
|
|
62
108
|
if (!stat.isDirectory() || stat.isSymbolicLink())
|
|
63
109
|
throw new Error("Private storage directory is not a real directory");
|
|
64
|
-
if (process.platform !== "win32")
|
|
110
|
+
if (process.platform !== "win32") {
|
|
111
|
+
if ((stat.mode & 0o777) !== 0o700) invalidateStoragePermissionMarkers(directory);
|
|
112
|
+
chmodSync(directory, 0o700);
|
|
113
|
+
}
|
|
65
114
|
}
|
|
66
115
|
|
|
67
116
|
/** Create or replace a storage file using a private mode from the first byte. */
|
|
@@ -105,15 +154,17 @@ export function syncStorageDirectorySync(directory: string): void {
|
|
|
105
154
|
}
|
|
106
155
|
}
|
|
107
156
|
|
|
108
|
-
/** Publish a safety record only after both its bytes and directory entry are durable.
|
|
157
|
+
/** Publish a safety record only after both its bytes and directory entry are durable.
|
|
158
|
+
* Hold the mutex through this call to use a constant tempPath.
|
|
159
|
+
*/
|
|
109
160
|
export function writeStorageFileDurableAtomicSync(
|
|
110
161
|
filePath: string,
|
|
111
162
|
content: string,
|
|
112
163
|
afterTempSync?: () => void,
|
|
164
|
+
tempPath = `${filePath}.${process.pid}.${randomBytes(12).toString("hex")}.tmp`,
|
|
113
165
|
): void {
|
|
114
166
|
const directory = dirname(filePath);
|
|
115
167
|
ensurePrivateStorageDirectorySync(directory);
|
|
116
|
-
const tempPath = `${filePath}.${process.pid}.${randomBytes(12).toString("hex")}.tmp`;
|
|
117
168
|
let fd: number | undefined;
|
|
118
169
|
try {
|
|
119
170
|
fd = openStorageFileSync(tempPath, "wx", true);
|
|
@@ -218,24 +269,140 @@ export async function createStorageFileHandleAsync(
|
|
|
218
269
|
return openAsync(filePath, flags, privateMode ? 0o600 : undefined);
|
|
219
270
|
}
|
|
220
271
|
|
|
272
|
+
function readStoragePermissionCertificate(marker: string): Stats | undefined {
|
|
273
|
+
const fd = openSync(marker, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
274
|
+
try {
|
|
275
|
+
const stat = fstatSync(fd);
|
|
276
|
+
// File times can have fractions of a millisecond. Use the precision of Date.now().
|
|
277
|
+
const age = Date.now() - Math.floor(stat.mtimeMs);
|
|
278
|
+
if (
|
|
279
|
+
!stat.isFile() ||
|
|
280
|
+
(stat.mode & 0o7777) !== 0o600 ||
|
|
281
|
+
stat.uid !== process.getuid?.() ||
|
|
282
|
+
stat.size !== STORAGE_PERMISSIONS_MARKER_BYTES.length ||
|
|
283
|
+
age < 0 ||
|
|
284
|
+
age >= STORAGE_PERMISSIONS_MARKER_MAX_AGE_MS
|
|
285
|
+
) {
|
|
286
|
+
return undefined;
|
|
287
|
+
}
|
|
288
|
+
// Read one more byte in case the file grew after fstat.
|
|
289
|
+
const buffer = Buffer.alloc(STORAGE_PERMISSIONS_MARKER_BYTES.length + 1);
|
|
290
|
+
const bytesRead = readSync(fd, buffer, 0, buffer.length, 0);
|
|
291
|
+
if (
|
|
292
|
+
bytesRead === STORAGE_PERMISSIONS_MARKER_BYTES.length &&
|
|
293
|
+
buffer.subarray(0, bytesRead).equals(STORAGE_PERMISSIONS_MARKER_BYTES)
|
|
294
|
+
) {
|
|
295
|
+
return stat;
|
|
296
|
+
}
|
|
297
|
+
} finally {
|
|
298
|
+
closeSync(fd);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
221
302
|
/** Tighten existing entries during storage startup; symlinks are never followed. */
|
|
222
|
-
export function tightenStorageTreeSync(
|
|
223
|
-
|
|
303
|
+
export function tightenStorageTreeSync(
|
|
304
|
+
directory: string,
|
|
305
|
+
dbPath = join(directory, "context.db"),
|
|
306
|
+
): { tightened: number; failures: number } {
|
|
307
|
+
if (process.platform === "win32") {
|
|
224
308
|
return { tightened: 0, failures: 0 };
|
|
225
309
|
}
|
|
310
|
+
const root = resolve(directory);
|
|
311
|
+
const marker = join(root, STORAGE_PERMISSIONS_MARKER);
|
|
226
312
|
let tightened = 0;
|
|
227
313
|
let failures = 0;
|
|
228
|
-
|
|
229
|
-
|
|
314
|
+
let keptLegacyTemp = false;
|
|
315
|
+
const removeMarker = (): boolean => {
|
|
230
316
|
try {
|
|
231
|
-
|
|
317
|
+
rmSync(marker, { force: true });
|
|
318
|
+
return true;
|
|
232
319
|
} catch {
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
if (!shouldEnforcePrivateStoragePermissions()) {
|
|
324
|
+
storagePermissionRoots.add(root);
|
|
325
|
+
if (!removeMarker()) failures++;
|
|
326
|
+
return { tightened, failures };
|
|
327
|
+
}
|
|
328
|
+
let rootStat: Stats;
|
|
329
|
+
try {
|
|
330
|
+
rootStat = lstatSync(root);
|
|
331
|
+
if (!rootStat.isDirectory()) return { tightened, failures: 1 };
|
|
332
|
+
} catch {
|
|
333
|
+
return { tightened, failures: 1 };
|
|
334
|
+
}
|
|
335
|
+
storagePermissionRoots.add(root);
|
|
336
|
+
let certificate: Stats | undefined;
|
|
337
|
+
let discardMarker = false;
|
|
338
|
+
try {
|
|
339
|
+
certificate = readStoragePermissionCertificate(marker);
|
|
340
|
+
discardMarker = certificate === undefined;
|
|
341
|
+
} catch (error) {
|
|
342
|
+
discardMarker = (error as NodeJS.ErrnoException).code !== "ENOENT";
|
|
343
|
+
}
|
|
344
|
+
// undefined: no loose entry. false: loose entry, marker stays. true: marker removed.
|
|
345
|
+
let markerRemoved: boolean | undefined;
|
|
346
|
+
const fenceDirectory = join(root, "lkg-recovery-fences");
|
|
347
|
+
const visit = (entryPath: string, recursive = true, optional = false, stat?: Stats): void => {
|
|
348
|
+
try {
|
|
349
|
+
stat ??= lstatSync(entryPath);
|
|
350
|
+
} catch (error) {
|
|
351
|
+
if (!optional || (error as NodeJS.ErrnoException).code !== "ENOENT") failures++;
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
if (entryPath === root && !stat.isDirectory()) {
|
|
233
355
|
failures++;
|
|
234
356
|
return;
|
|
235
357
|
}
|
|
236
358
|
if (stat.isSymbolicLink()) return;
|
|
359
|
+
// A mode change must not turn an invalid marker into a certificate.
|
|
360
|
+
if (entryPath === marker && !stat.isDirectory()) return;
|
|
361
|
+
if (!certificate && dirname(entryPath) === fenceDirectory) {
|
|
362
|
+
const name = basename(entryPath);
|
|
363
|
+
const legacyTemp = stat.isFile() && /^.+\.json\..+\.tmp$/.test(name);
|
|
364
|
+
if (legacyTemp) {
|
|
365
|
+
const publisherPid = /^.+\.json\.([1-9]\d*)\.[a-f0-9]{24}\.tmp$/.exec(name)?.[1];
|
|
366
|
+
// The legacy writer puts its PID in the name. Age does not prove that it stopped.
|
|
367
|
+
if (
|
|
368
|
+
Date.now() - stat.mtimeMs <= LEGACY_FENCE_TEMP_MIN_AGE_MS ||
|
|
369
|
+
(publisherPid && isPidAlive(Number(publisherPid)) !== "dead")
|
|
370
|
+
) {
|
|
371
|
+
// The certificate can prevent a check of these files at the next start.
|
|
372
|
+
keptLegacyTemp = true;
|
|
373
|
+
} else {
|
|
374
|
+
try {
|
|
375
|
+
rmSync(entryPath, { force: true });
|
|
376
|
+
} catch {
|
|
377
|
+
failures++;
|
|
378
|
+
}
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
if (stat.isDirectory() && name.endsWith(".json.locks")) {
|
|
383
|
+
try {
|
|
384
|
+
lstatSync(entryPath.slice(0, -".locks".length));
|
|
385
|
+
} catch (error) {
|
|
386
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
|
387
|
+
try {
|
|
388
|
+
// A live ticket prevents removal of its directory.
|
|
389
|
+
rmdirSync(entryPath);
|
|
390
|
+
return;
|
|
391
|
+
} catch (cleanupError) {
|
|
392
|
+
const code = (cleanupError as NodeJS.ErrnoException).code;
|
|
393
|
+
if (code === "ENOENT") return;
|
|
394
|
+
if (code !== "ENOTEMPTY" && code !== "EEXIST") failures++;
|
|
395
|
+
}
|
|
396
|
+
} else failures++;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
237
400
|
const mode = stat.isDirectory() ? 0o700 : 0o600;
|
|
238
401
|
if ((stat.mode & 0o077) !== 0 || (stat.mode & 0o777) !== mode) {
|
|
402
|
+
if (certificate) {
|
|
403
|
+
// Invalidate before the mode change so a peer can see that the tree changed.
|
|
404
|
+
markerRemoved ??= removeMarker();
|
|
405
|
+
}
|
|
239
406
|
try {
|
|
240
407
|
chmodSync(entryPath, mode);
|
|
241
408
|
tightened++;
|
|
@@ -243,7 +410,7 @@ export function tightenStorageTreeSync(root: string): { tightened: number; failu
|
|
|
243
410
|
failures++;
|
|
244
411
|
}
|
|
245
412
|
}
|
|
246
|
-
if (!stat.isDirectory()) return;
|
|
413
|
+
if (!recursive || !stat.isDirectory()) return;
|
|
247
414
|
let entries: string[];
|
|
248
415
|
try {
|
|
249
416
|
entries = readdirSync(entryPath);
|
|
@@ -253,6 +420,54 @@ export function tightenStorageTreeSync(root: string): { tightened: number; failu
|
|
|
253
420
|
}
|
|
254
421
|
for (const entry of entries) visit(join(entryPath, entry));
|
|
255
422
|
};
|
|
256
|
-
|
|
423
|
+
if (certificate) {
|
|
424
|
+
visit(root, false, false, rootStat);
|
|
425
|
+
visit(dbPath, false, true);
|
|
426
|
+
visit(`${dbPath}-wal`, false, true);
|
|
427
|
+
visit(`${dbPath}-shm`, false, true);
|
|
428
|
+
// Transformers does not set cache entry modes. Keep this subtree checked.
|
|
429
|
+
visit(join(root, "models"), true, true);
|
|
430
|
+
// The Rust logger does not use the storage helpers.
|
|
431
|
+
visit(join(root, "logs"), true, true);
|
|
432
|
+
// A loose entry shows the tree changed after certification. The root's mode does not
|
|
433
|
+
// stop a process with a working directory in the tree. Walk the full tree at this start.
|
|
434
|
+
if (markerRemoved !== undefined) {
|
|
435
|
+
certificate = undefined;
|
|
436
|
+
visit(root);
|
|
437
|
+
if (!markerRemoved && !removeMarker()) failures++;
|
|
438
|
+
} else if (failures > 0) {
|
|
439
|
+
if (!removeMarker()) failures++;
|
|
440
|
+
} else {
|
|
441
|
+
// A peer can remove the certificate during the mode checks.
|
|
442
|
+
let markerChanged: boolean;
|
|
443
|
+
try {
|
|
444
|
+
const current = lstatSync(marker);
|
|
445
|
+
markerChanged =
|
|
446
|
+
current.dev !== certificate.dev ||
|
|
447
|
+
current.ino !== certificate.ino ||
|
|
448
|
+
current.ctimeMs !== certificate.ctimeMs;
|
|
449
|
+
} catch (error) {
|
|
450
|
+
markerChanged = true;
|
|
451
|
+
discardMarker = (error as NodeJS.ErrnoException).code !== "ENOENT";
|
|
452
|
+
}
|
|
453
|
+
if (markerChanged) {
|
|
454
|
+
certificate = undefined;
|
|
455
|
+
visit(root);
|
|
456
|
+
if (discardMarker && !removeMarker()) failures++;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
} else {
|
|
460
|
+
visit(root, true, false, rootStat);
|
|
461
|
+
if (discardMarker && !removeMarker()) failures++;
|
|
462
|
+
if (failures === 0 && !keptLegacyTemp) {
|
|
463
|
+
try {
|
|
464
|
+
writeStorageFileSync(marker, STORAGE_PERMISSIONS_MARKER_BYTES, {
|
|
465
|
+
flag: "wx",
|
|
466
|
+
});
|
|
467
|
+
} catch (error) {
|
|
468
|
+
if ((error as NodeJS.ErrnoException).code !== "EEXIST") failures++;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
257
472
|
return { tightened, failures };
|
|
258
473
|
}
|
|
File without changes
|
|
File without changes
|