Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
workspaceStatusLabel,
} from "./api/api-helper";
import * as cliExec from "./core/cliExec";
import { appendVsCodeLogs } from "./core/supportBundleLogs";
import { CertificateError } from "./error/certificateError";
import { toError } from "./error/errorUtils";
import { type FeatureSet, featureSetForVersion } from "./featureSet";
Expand All @@ -26,6 +25,7 @@ import {
applySettingOverrides,
} from "./remote/sshOverrides";
import { resolveCliAuth } from "./settings/cli";
import { appendVsCodeLogs } from "./supportBundle/appendVsCodeLogs";
import { toRemoteAuthority, toSafeHost } from "./util";
import { vscodeProposed } from "./vscodeProposed";
import { parseSpeedtestResult } from "./webviews/speedtest/types";
Expand Down Expand Up @@ -304,7 +304,7 @@ export class Commands {
await appendVsCodeLogs(
outputUri.fsPath,
{
remoteSshLogPath: this.workspaceLogPath,
activeProxyLogPath: this.workspaceLogPath,
proxyLogDir: this.pathResolver.getProxyLogPath(),
extensionLogDir: this.pathResolver.getCodeLogDir(),
},
Expand Down
158 changes: 0 additions & 158 deletions src/core/supportBundleLogs.ts

This file was deleted.

22 changes: 22 additions & 0 deletions src/remote/sshExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@ export const REMOTE_SSH_EXTENSION_IDS = [

export type RemoteSshExtensionId = (typeof REMOTE_SSH_EXTENSION_IDS)[number];

/**
* VS Code Remote-SSH log layout, shared by the live SSH monitor and the
* support-bundle collector so a future layout change updates one place.
*/
const OUTPUT_LOGGING_DIR_PREFIX = "output_logging_";
const REMOTE_SSH_LOG_NAME_FRAGMENT = "Remote - SSH";

/** True if `dirName` is the exthost dir of a known Remote-SSH extension. */
export function isRemoteSshExtensionDir(dirName: string): boolean {
return (REMOTE_SSH_EXTENSION_IDS as readonly string[]).includes(dirName);
}

/** True if `dirName` is a VS Code shared output channel dir. */
export function isOutputLoggingDir(dirName: string): boolean {
return dirName.startsWith(OUTPUT_LOGGING_DIR_PREFIX);
}

/** True if `fileName` is the Remote-SSH log inside a shared output channel. */
export function isSharedChannelRemoteSshLog(fileName: string): boolean {
return fileName.includes(REMOTE_SSH_LOG_NAME_FRAGMENT);
}

type RemoteSshExtension = vscode.Extension<unknown> & {
id: RemoteSshExtensionId;
};
Expand Down
8 changes: 6 additions & 2 deletions src/remote/sshProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import { findPort } from "../util";
import { cleanupFiles } from "../util/fileCleanup";

import { NetworkStatusReporter } from "./networkStatus";
import {
isOutputLoggingDir,
isSharedChannelRemoteSshLog,
} from "./sshExtension";

import type { Logger } from "../logging/logger";
import type { TelemetryReporter } from "../telemetry/reporter";
Expand Down Expand Up @@ -514,7 +518,7 @@ async function findRemoteSshLogPath(
try {
const dirs = await fs.readdir(logsParentDir);
const outputDirs = dirs
.filter((d) => d.startsWith("output_logging_"))
.filter(isOutputLoggingDir)
.sort((a, b) => a.localeCompare(b))
.reverse();

Expand All @@ -541,6 +545,6 @@ async function findRemoteSshLogPath(

async function findSshLogInDir(dirPath: string): Promise<string | undefined> {
const files = await fs.readdir(dirPath);
const remoteSshLog = files.find((f) => f.includes("Remote - SSH"));
const remoteSshLog = files.find(isSharedChannelRemoteSshLog);
return remoteSshLog ? path.join(dirPath, remoteSshLog) : undefined;
}
98 changes: 98 additions & 0 deletions src/supportBundle/appendVsCodeLogs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { unzip, zip, type Zippable } from "fflate";
import { randomUUID } from "node:crypto";
import * as fs from "node:fs/promises";
import * as path from "node:path";
import { promisify } from "node:util";

import { type Logger } from "../logging/logger";
import { renameWithRetry } from "../util/fs";

import { collectVsCodeDiagnostics, type LogSources } from "./logFiles";

export type { LogSources } from "./logFiles";

const unzipAsync = promisify(unzip);
const zipAsync = promisify(zip);

/**
* Best-effort: append VS Code logs to the bundle zip, swapped in by atomic
* rename so a failure leaves the original intact.
*/
export async function appendVsCodeLogs(
zipPath: string,
sources: LogSources,
logger: Logger,
): Promise<void> {
try {
const diagnosticFiles = await collectVsCodeDiagnostics(sources, logger);
if (diagnosticFiles.size === 0) {
logger.info("No VS Code diagnostics found to add to support bundle");
return;
}

logger.info(
`Adding ${diagnosticFiles.size} VS Code diagnostic file(s) to support bundle`,
);

const outputBundlePath = vscodeBundlePath(zipPath);
Comment thread
EhabY marked this conversation as resolved.
try {
await writeBundleWithDiagnostics(
zipPath,
outputBundlePath,
diagnosticFiles,
);
} catch (error) {
logger.error(
"Failed to add VS Code diagnostics to support bundle",
error,
);

// Write-failure path only: success and failed-rename both keep the file.
try {
await fs.rm(outputBundlePath, { force: true });
} catch (cleanupError) {
logger.warn(
`Could not clean up partial bundle at ${outputBundlePath}`,
cleanupError,
);
}
Comment thread
EhabY marked this conversation as resolved.
return;
}

try {
await renameWithRetry(fs.rename, outputBundlePath, zipPath);
} catch (error) {
logger.warn(
`Could not replace original bundle; VS Code diagnostics saved separately at ${outputBundlePath}`,
error,
);
}
} catch (error) {
// Best-effort: never let a failure here lose the user's bundle.
logger.error("Unexpected error appending VS Code diagnostics", error);
}
}

function vscodeBundlePath(zipPath: string): string {
const parsed = path.parse(zipPath);
return path.join(
parsed.dir,
`${parsed.name}-vscode-${randomUUID().slice(0, 8)}${parsed.ext}`,
);
}

async function writeBundleWithDiagnostics(
zipPath: string,
outputPath: string,
diagnosticFiles: Map<string, Uint8Array>,
): Promise<void> {
const sourceMode = (await fs.stat(zipPath)).mode & 0o777;
const entries: Zippable = await unzipAsync(await fs.readFile(zipPath));

for (const [name, data] of diagnosticFiles) {
entries[name] = data;
}

// Set mode at create time: avoids a umask window and a fallible chmod.
await fs.writeFile(outputPath, await zipAsync(entries), { mode: sourceMode });
}
Loading
Loading