Skip to content

Commit f0d3f6e

Browse files
committed
overhaul!
1 parent c10047a commit f0d3f6e

File tree

5 files changed

+32
-15
lines changed

5 files changed

+32
-15
lines changed

extensions/open-remote-ssh/package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,13 @@
105105
"default": ""
106106
},
107107
"remoteSSH.serverInstallPath": {
108-
"type": "string",
109-
"markdownDescription": "A custom directory to install the Positron server data on the remote machine. By default, the server data is installed in `~/.positron-server`.",
108+
"type": "object",
109+
"markdownDescription": "A map of remote host to the remote directory where the Positron server data will be installed. You may include tildes or environment variables of the form `$ENV_VAR`, which will be resolved on the remote host upon connecting. Relative paths will be parsed relative to `$HOME`. For any host not included here, the server is installed in `$HOME/.positron-server`.",
110110
"scope": "application",
111-
"default": ""
111+
"additionalProperties": {
112+
"type": "string"
113+
},
114+
"default": {}
112115
}
113116
}
114117
},

extensions/open-remote-ssh/src/authResolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export class RemoteSSHResolver implements vscode.RemoteAuthorityResolver, vscode
199199
envVariables['SSH_AUTH_SOCK'] = null;
200200
}
201201

202-
const installResult = await installCodeServer(this.sshConnection, serverDownloadUrlTemplate, defaultExtensions, Object.keys(envVariables), remotePlatformMap[sshDest.hostname], remoteServerListenOnSocket, this.logger);
202+
const installResult = await installCodeServer(this.sshConnection, serverDownloadUrlTemplate, defaultExtensions, Object.keys(envVariables), remotePlatformMap[sshDest.hostname], remoteServerListenOnSocket, this.logger, sshHostName, sshDest.hostname);
203203

204204
for (const key of Object.keys(envVariables)) {
205205
if (installResult[key] !== undefined) {

extensions/open-remote-ssh/src/serverConfig.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export async function getVSCodeServerConfig(): Promise<IServerConfig> {
3535
const productJson = await getVSCodeProductJson();
3636

3737
const customServerBinaryName = vscode.workspace.getConfiguration('remoteSSH.experimental').get<string>('serverBinaryName', '');
38-
const customDataFolderName = vscode.workspace.getConfiguration('remoteSSH').get<string>('serverInstallPath', '');
3938

4039
const version = `${positron.version}-${positron.buildNumber}`;
4140

@@ -45,7 +44,7 @@ export async function getVSCodeServerConfig(): Promise<IServerConfig> {
4544
quality: productJson.quality,
4645
release: productJson.release,
4746
serverApplicationName: customServerBinaryName || productJson.serverApplicationName,
48-
serverDataFolderName: customDataFolderName || productJson.serverDataFolderName,
47+
serverDataFolderName: productJson.serverDataFolderName,
4948
serverDownloadUrlTemplate: productJson.serverDownloadUrlTemplate
5049
};
5150
}

extensions/open-remote-ssh/src/serverSetup.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// The code in extensions/open-remote-ssh has been adapted from https://github.com/jeanp413/open-remote-ssh,
77
// which is licensed under the MIT license.
88

9+
import * as vscode from 'vscode';
910
import * as crypto from 'crypto';
1011
import Log from './common/logger';
1112
import { getVSCodeServerConfig } from './serverConfig';
@@ -45,7 +46,7 @@ export class ServerInstallError extends Error {
4546

4647
const DEFAULT_DOWNLOAD_URL_TEMPLATE = 'https://cdn.posit.co/positron/dailies/reh/${arch-long}/positron-reh-${os}-${arch}-${version}.tar.gz';
4748

48-
export async function installCodeServer(conn: SSHConnection, serverDownloadUrlTemplate: string | undefined, extensionIds: string[], envVariables: string[], platform: string | undefined, useSocketPath: boolean, logger: Log): Promise<ServerInstallResult> {
49+
export async function installCodeServer(conn: SSHConnection, serverDownloadUrlTemplate: string | undefined, extensionIds: string[], envVariables: string[], platform: string | undefined, useSocketPath: boolean, logger: Log, hostname: string, hostAlias: string): Promise<ServerInstallResult> {
4950
let shell = 'powershell';
5051

5152
// detect platform and shell for windows
@@ -78,6 +79,15 @@ export async function installCodeServer(conn: SSHConnection, serverDownloadUrlTe
7879
const scriptId = crypto.randomBytes(12).toString('hex');
7980

8081
const vscodeServerConfig = await getVSCodeServerConfig();
82+
83+
let serverDataFolderName = vscodeServerConfig.serverDataFolderName;
84+
const dataFolderSetting = vscode.workspace.getConfiguration('remoteSSH').get<{ [key: string]: string }>('serverInstallPath', {});
85+
if (dataFolderSetting.hasOwnProperty(hostname)) {
86+
serverDataFolderName = dataFolderSetting[hostname];
87+
} else if (dataFolderSetting.hasOwnProperty(hostAlias)) {
88+
serverDataFolderName = dataFolderSetting[hostAlias];
89+
}
90+
8191
const installOptions: ServerInstallOptions = {
8292
id: scriptId,
8393
version: vscodeServerConfig.version,
@@ -88,21 +98,18 @@ export async function installCodeServer(conn: SSHConnection, serverDownloadUrlTe
8898
envVariables,
8999
useSocketPath,
90100
serverApplicationName: vscodeServerConfig.serverApplicationName,
91-
serverDataFolderName: vscodeServerConfig.serverDataFolderName,
101+
serverDataFolderName,
92102
serverDownloadUrlTemplate: serverDownloadUrlTemplate || vscodeServerConfig.serverDownloadUrlTemplate || DEFAULT_DOWNLOAD_URL_TEMPLATE,
93103
};
94104

95105
let commandOutput: { stdout: string; stderr: string };
96106
if (platform === 'windows') {
97-
// If the default was not changed, adjust the path for PowerShell on Windows
98-
if (installOptions.serverDataFolderName === '$HOME/.positron-server') {
99-
installOptions.serverDataFolderName = '$HOME\\.positron-server';
100-
}
101107
const installServerScript = generatePowerShellInstallScript(installOptions);
102108

103109
logger.trace('Server install command:', installServerScript);
104110

105-
const installDir = `${vscodeServerConfig.serverDataFolderName}\\install`;
111+
// TODO upon supporting windows hosts: respect the remoteSSH.serverInstallPath setting here
112+
const installDir = `$HOME\\${vscodeServerConfig.serverDataFolderName}\\install`;
106113
const installScript = `${installDir}\\${vscodeServerConfig.commit}.ps1`;
107114
const endRegex = new RegExp(`${scriptId}: end`);
108115
// investigate if it's possible to use `-EncodedCommand` flag
@@ -231,6 +238,13 @@ SERVER_APP_NAME="${serverApplicationName}"
231238
SERVER_INITIAL_EXTENSIONS="${extensions}"
232239
SERVER_LISTEN_FLAG="${useSocketPath ? `--socket-path="$TMP_DIR/vscode-server-sock-${crypto.randomUUID()}"` : '--port=0'}"
233240
SERVER_DATA_DIR="${serverDataFolderName}"
241+
242+
# If SERVER_DATA_DIR is relative, make it relative to $HOME
243+
if [[ "$SERVER_DATA_DIR" != /* ]] && [[ "$SERVER_DATA_DIR" != ~* ]]; then
244+
SERVER_DATA_DIR="$HOME/$SERVER_DATA_DIR"
245+
fi
246+
echo "Using server data dir: $SERVER_DATA_DIR"
247+
234248
SERVER_DIR="$SERVER_DATA_DIR/bin/$DISTRO_COMMIT"
235249
SERVER_SCRIPT="$SERVER_DIR/bin/$SERVER_APP_NAME"
236250
SERVER_LOGFILE="$SERVER_DATA_DIR/.$DISTRO_COMMIT.log"
@@ -471,7 +485,8 @@ $DISTRO_VSCODIUM_RELEASE="${release ?? ''}"
471485
$SERVER_APP_NAME="${serverApplicationName}"
472486
$SERVER_INITIAL_EXTENSIONS="${extensions}"
473487
$SERVER_LISTEN_FLAG="${useSocketPath ? `--socket-path="$TMP_DIR/vscode-server-sock-${crypto.randomUUID()}"` : '--port=0'}"
474-
$SERVER_DATA_DIR="${serverDataFolderName}"
488+
# TODO upon supporting windows hosts: respect the remoteSSH.serverInstallPath setting here
489+
$SERVER_DATA_DIR="$(Resolve-Path ~)\\${serverDataFolderName}"
475490
$SERVER_DIR="$SERVER_DATA_DIR\\bin\\$DISTRO_COMMIT"
476491
$SERVER_SCRIPT="$SERVER_DIR\\bin\\$SERVER_APP_NAME.cmd"
477492
$SERVER_LOGFILE="$SERVER_DATA_DIR\\.$DISTRO_COMMIT.log"

product.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"serverLicense": [],
1515
"serverLicensePrompt": "",
1616
"serverApplicationName": "positron-server",
17-
"serverDataFolderName": "$HOME/.positron-server",
17+
"serverDataFolderName": ".positron-server",
1818
"serverDownloadUrlTemplate": "https://cdn.posit.co/positron/dailies/reh/${arch-long}/positron-reh-${os}-${arch}-${version}.tar.gz",
1919
"tunnelApplicationName": "positron-tunnel",
2020
"win32DirName": "Positron",

0 commit comments

Comments
 (0)