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' ;
910import * as crypto from 'crypto' ;
1011import Log from './common/logger' ;
1112import { getVSCodeServerConfig } from './serverConfig' ;
@@ -45,7 +46,7 @@ export class ServerInstallError extends Error {
4546
4647const 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}"
231238SERVER_INITIAL_EXTENSIONS="${ extensions } "
232239SERVER_LISTEN_FLAG="${ useSocketPath ? `--socket-path="$TMP_DIR/vscode-server-sock-${ crypto . randomUUID ( ) } "` : '--port=0' } "
233240SERVER_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+
234248SERVER_DIR="$SERVER_DATA_DIR/bin/$DISTRO_COMMIT"
235249SERVER_SCRIPT="$SERVER_DIR/bin/$SERVER_APP_NAME"
236250SERVER_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"
0 commit comments