Skip to content

Commit 9e4f9a7

Browse files
committed
Support with ~
1 parent 65700a6 commit 9e4f9a7

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/common/files.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import * as fs from 'fs';
77
import * as os from 'os';
8+
import * as path from 'path';
89

910
const homeDir = os.homedir();
1011

@@ -20,3 +21,17 @@ export async function exists(path: string) {
2021
export function untildify(path: string){
2122
return path.replace(/^~(?=$|\/|\\)/, homeDir);
2223
}
24+
25+
export function resolveHomeDir(filepath: string | undefined) {
26+
if (!filepath) {
27+
return filepath;
28+
}
29+
const homedir = os.homedir();
30+
if (filepath === '~') {
31+
return homedir;
32+
}
33+
if (filepath.startsWith('~/')) {
34+
return path.join(homedir, filepath.slice(2));
35+
}
36+
return filepath;
37+
}

src/remoteConnector.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { HeartbeatManager } from './heartbeat';
2828
import { getGitpodVersion, isFeatureSupported } from './featureSupport';
2929
import SSHConfiguration from './ssh/sshConfig';
3030
import { isWindows } from './common/platform';
31-
import { untildify } from './common/files';
31+
import { resolveHomeDir, untildify } from './common/files';
3232

3333
interface SSHConnectionParams {
3434
workspaceId: string;
@@ -440,7 +440,7 @@ export default class RemoteConnector extends Disposable {
440440
identityFiles.push(...DEFAULT_IDENTITY_FILES);
441441
}
442442

443-
const identityFileContentsResult = await Promise.allSettled(identityFiles.map(async path => fs.promises.readFile(path + '.pub')));
443+
const identityFileContentsResult = await Promise.allSettled(identityFiles.map(async path => fs.promises.readFile(resolveHomeDir(path) + '.pub')));
444444
const fileKeys = identityFileContentsResult.map((result, i) => {
445445
if (result.status === 'rejected') {
446446
return undefined;
@@ -462,14 +462,20 @@ export default class RemoteConnector extends Disposable {
462462
};
463463
}).filter(<T>(v: T | undefined): v is T => !!v);
464464

465-
const sshAgentSock = isWindows ? `\\.\pipe\openssh-ssh-agent` : (hostConfig['IdentityAgent'] || process.env['SSH_AUTH_SOCK']);
465+
let sshAgentSock: string | undefined;
466+
if (isWindows) {
467+
sshAgentSock = `\\.\pipe\openssh-ssh-agent`;
468+
} else {
469+
sshAgentSock = (hostConfig['IdentityAgent'] || process.env['SSH_AUTH_SOCK']);
470+
sshAgentSock = resolveHomeDir(sshAgentSock);
471+
}
466472
let sshAgentParsedKeys: ParsedKey[] = [];
467473
try {
468-
if (!sshAgentSock) {
469-
throw new Error(`SSH_AUTH_SOCK environment variable not defined`);
470-
}
471-
472474
sshAgentParsedKeys = await new Promise<ParsedKey[]>((resolve, reject) => {
475+
if (!sshAgentSock) {
476+
reject(new Error(`SSH_AUTH_SOCK environment variable not defined`));
477+
return;
478+
}
473479
const sshAgent = new OpenSSHAgent(sshAgentSock);
474480
sshAgent.getIdentities((err, publicKeys) => {
475481
if (err) {

0 commit comments

Comments
 (0)