























@@ -24,6 +24,7 @@ type LegacyCaptureSessionRow = {
2424source_scope: string;
2525source_process: string;
2626proxy_url: string | null;
27+blob_dir: string;
2728};
28292930type LegacyCaptureEventRow = {
@@ -153,6 +154,7 @@ function readLegacyDebugProxyCapture(params: { sourcePath: string; blobDir: stri
153154sessions: LegacyCaptureSessionRow[];
154155events: LegacyCaptureEventRow[];
155156blobs: LegacyCaptureBlobRow[];
157+blobDirs: string[];
156158} {
157159const sqlite = requireNodeSqlite();
158160const db = new sqlite.DatabaseSync(params.sourcePath, { readOnly: true });
@@ -192,7 +194,7 @@ function readLegacyDebugProxyCapture(params: { sourcePath: string; blobDir: stri
192194]);
193195const sessions = db
194196.prepare(
195-`SELECT id, started_at, ended_at, mode, source_scope, source_process, proxy_url
197+`SELECT id, started_at, ended_at, mode, source_scope, source_process, proxy_url, blob_dir
196198 FROM capture_sessions
197199 ORDER BY started_at ASC, id ASC`,
198200)
@@ -220,6 +222,7 @@ function readLegacyDebugProxyCapture(params: { sourcePath: string; blobDir: stri
220222source_scope: event.source_scope,
221223source_process: event.source_process,
222224proxy_url: null,
225+blob_dir: params.blobDir,
223226});
224227sessionIds.add(event.session_id);
225228}
@@ -233,15 +236,33 @@ function readLegacyDebugProxyCapture(params: { sourcePath: string; blobDir: stri
233236rows.push(event);
234237blobEvents.set(event.data_blob_id, rows);
235238}
239+const blobDirBySession = new Map(
240+sessions.map((session) => [session.id, session.blob_dir] as const),
241+);
242+const usedBlobDirs = new Set<string>();
236243const blobs: LegacyCaptureBlobRow[] = [];
237244for (const [blobId, referencingEvents] of blobEvents) {
238-const blobPath = path.join(params.blobDir, `${blobId}.bin.gz`);
245+const candidateBlobDirs = [
246+ ...new Set(
247+[
248+ ...referencingEvents.map(
249+(event) => blobDirBySession.get(event.session_id) ?? params.blobDir,
250+),
251+params.blobDir,
252+],
253+),
254+];
255+const blobPath =
256+candidateBlobDirs
257+.map((blobDir) => path.join(blobDir, `${blobId}.bin.gz`))
258+.find(fileExists) ?? path.join(candidateBlobDirs[0] ?? params.blobDir, `${blobId}.bin.gz`);
239259const data = fs.readFileSync(blobPath);
240260const raw = gunzipSync(data);
241261const sha256 = createHash("sha256").update(raw).digest("hex");
242262if (sha256.slice(0, 24) !== blobId) {
243263throw new Error(`legacy debug proxy blob hash mismatch: ${blobPath}`);
244264}
265+usedBlobDirs.add(path.dirname(blobPath));
245266blobs.push({
246267 blobId,
247268contentType: referencingEvents.find((event) => event.content_type)?.content_type ?? null,
@@ -254,7 +275,7 @@ function readLegacyDebugProxyCapture(params: { sourcePath: string; blobDir: stri
254275),
255276});
256277}
257-return { sessions, events, blobs };
278+return { sessions, events, blobs, blobDirs: [...usedBlobDirs] };
258279} finally {
259280db.close();
260281}
@@ -519,6 +540,14 @@ export function migrateLegacyDebugProxyCaptureSidecar(params: {
519540archiveLegacyDebugProxySqlite({ sourcePath: detected.sourcePath, changes, warnings });
520541if (!fileExists(detected.sourcePath) && fileExists(`${detected.sourcePath}.migrated`)) {
521542archiveLegacyDebugProxyBlobs({ blobDir: detected.blobDir, changes, warnings });
543+for (const blobDir of legacy.blobDirs) {
544+if (path.resolve(blobDir) === path.resolve(detected.blobDir) || !dirExists(blobDir)) {
545+continue;
546+}
547+warnings.push(
548+`Left migrated debug proxy capture blobs in stored session directory: ${blobDir}`,
549+);
550+}
522551}
523552return { changes, warnings };
524553}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。