cli.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. diff --git a/cli/src/commands/serve_web.rs b/cli/src/commands/serve_web.rs
  2. index d3f7db8..988024b 100644
  3. --- a/cli/src/commands/serve_web.rs
  4. +++ b/cli/src/commands/serve_web.rs
  5. @@ -756,3 +756,3 @@ impl ConnectionManager {
  6. let dir_fut = cache.create(&args.release.commit, |target_dir| async move {
  7. - info!(log_for_fut, "Downloading server {}", release_for_fut.commit);
  8. + info!(log_for_fut, "Downloading server {}/{}", release_for_fut.commit, release_for_fut.name);
  9. let tmpdir = tempfile::tempdir().unwrap();
  10. @@ -784,3 +784,3 @@ impl ConnectionManager {
  11. .join("bin")
  12. - .join(args.release.quality.server_entrypoint());
  13. + .join(args.release.quality.server_entrypoint().unwrap());
  14. diff --git a/cli/src/constants.rs b/cli/src/constants.rs
  15. index 1e277a8..97f17d3 100644
  16. --- a/cli/src/constants.rs
  17. +++ b/cli/src/constants.rs
  18. @@ -35,3 +35,6 @@ pub const DOCUMENTATION_URL: Option<&'static str> = option_env!("VSCODE_CLI_DOCU
  19. pub const VSCODE_CLI_COMMIT: Option<&'static str> = option_env!("VSCODE_CLI_COMMIT");
  20. -pub const VSCODE_CLI_UPDATE_ENDPOINT: Option<&'static str> = option_env!("VSCODE_CLI_UPDATE_URL");
  21. +pub const VSCODE_CLI_UPDATE_ENDPOINT: Option<&'static str> = option_env!("VSCODE_CLI_UPDATE_ENDPOINT");
  22. +pub const VSCODE_CLI_DOWNLOAD_ENDPOINT: Option<&'static str> = option_env!("VSCODE_CLI_DOWNLOAD_ENDPOINT");
  23. +pub const VSCODE_CLI_APP_NAME: Option<&'static str> = option_env!("VSCODE_CLI_APP_NAME");
  24. +pub const VSCODE_CLI_BINARY_NAME: Option<&'static str> = option_env!("VSCODE_CLI_BINARY_NAME");
  25. diff --git a/cli/src/options.rs b/cli/src/options.rs
  26. index 7d152c0..c0f2fb2 100644
  27. --- a/cli/src/options.rs
  28. +++ b/cli/src/options.rs
  29. @@ -9,3 +9,3 @@ use serde::{Deserialize, Serialize};
  30. -use crate::constants::SERVER_NAME_MAP;
  31. +use crate::{constants::VSCODE_CLI_BINARY_NAME, util::errors::CodeError};
  32. @@ -21,2 +21,6 @@ pub enum Quality {
  33. +fn get_binary_name() -> Result<&'static str, CodeError> {
  34. + VSCODE_CLI_BINARY_NAME.ok_or_else(|| CodeError::UpdatesNotConfigured("no binary name"))
  35. +}
  36. +
  37. impl Quality {
  38. @@ -41,9 +45,4 @@ impl Quality {
  39. /// Server application name
  40. - pub fn server_entrypoint(&self) -> String {
  41. - let mut server_name = SERVER_NAME_MAP
  42. - .as_ref()
  43. - .and_then(|m| m.get(self))
  44. - .map(|s| s.server_application_name.as_str())
  45. - .unwrap_or("code-server-oss")
  46. - .to_string();
  47. + pub fn server_entrypoint(&self) -> Result<String, CodeError> {
  48. + let mut server_name = get_binary_name()?.to_string();
  49. @@ -53,3 +52,3 @@ impl Quality {
  50. - server_name
  51. + Ok(server_name)
  52. }
  53. diff --git a/cli/src/tunnels/code_server.rs b/cli/src/tunnels/code_server.rs
  54. index bbabadc..b454d0e 100644
  55. --- a/cli/src/tunnels/code_server.rs
  56. +++ b/cli/src/tunnels/code_server.rs
  57. @@ -462,3 +462,3 @@ impl<'a> ServerBuilder<'a> {
  58. .join("bin")
  59. - .join(self.server_params.release.quality.server_entrypoint()),
  60. + .join(self.server_params.release.quality.server_entrypoint().unwrap()),
  61. &["--version"],
  62. diff --git a/cli/src/tunnels/paths.rs b/cli/src/tunnels/paths.rs
  63. index 3d7d718..98529bc 100644
  64. --- a/cli/src/tunnels/paths.rs
  65. +++ b/cli/src/tunnels/paths.rs
  66. @@ -100,3 +100,3 @@ impl InstalledServer {
  67. .join("bin")
  68. - .join(self.quality.server_entrypoint())
  69. + .join(self.quality.server_entrypoint().unwrap())
  70. },
  71. diff --git a/cli/src/update_service.rs b/cli/src/update_service.rs
  72. index 55f1dad..3b7ef5c 100644
  73. --- a/cli/src/update_service.rs
  74. +++ b/cli/src/update_service.rs
  75. @@ -10,3 +10,3 @@ use serde::{Deserialize, Serialize};
  76. use crate::{
  77. - constants::VSCODE_CLI_UPDATE_ENDPOINT,
  78. + constants::{VSCODE_CLI_APP_NAME, VSCODE_CLI_DOWNLOAD_ENDPOINT, VSCODE_CLI_UPDATE_ENDPOINT},
  79. debug, log, options, spanf,
  80. @@ -18,3 +18,3 @@ use crate::{
  81. zipper,
  82. - },
  83. + }
  84. };
  85. @@ -58,2 +58,10 @@ fn quality_download_segment(quality: options::Quality) -> &'static str {
  86. +fn get_app_name() -> Result<&'static str, CodeError> {
  87. + VSCODE_CLI_APP_NAME.ok_or_else(|| CodeError::UpdatesNotConfigured("no app name"))
  88. +}
  89. +
  90. +fn get_download_endpoint() -> Result<&'static str, CodeError> {
  91. + VSCODE_CLI_DOWNLOAD_ENDPOINT.ok_or_else(|| CodeError::UpdatesNotConfigured("no download url"))
  92. +}
  93. +
  94. fn get_update_endpoint() -> Result<String, CodeError> {
  95. @@ -66,3 +74,3 @@ fn get_update_endpoint() -> Result<String, CodeError> {
  96. .map(|s| s.to_string())
  97. - .ok_or_else(|| CodeError::UpdatesNotConfigured("no service url"))
  98. + .ok_or_else(|| CodeError::UpdatesNotConfigured("no update url"))
  99. }
  100. @@ -74,3 +82,4 @@ impl UpdateService {
  101. - pub async fn get_release_by_semver_version(
  102. + /// Gets the latest commit for the target of the given quality.
  103. + pub async fn get_latest_commit(
  104. &self,
  105. @@ -79,14 +88,10 @@ impl UpdateService {
  106. quality: options::Quality,
  107. - version: &str,
  108. ) -> Result<Release, AnyError> {
  109. let update_endpoint = get_update_endpoint()?;
  110. - let download_segment = target
  111. - .download_segment(platform)
  112. - .ok_or_else(|| CodeError::UnsupportedPlatform(platform.to_string()))?;
  113. let download_url = format!(
  114. - "{}/api/versions/{}/{}/{}",
  115. + "{}/{}/{}/{}/latest.json",
  116. &update_endpoint,
  117. - version,
  118. - download_segment,
  119. quality_download_segment(quality),
  120. + platform.os(),
  121. + platform.arch(),
  122. );
  123. @@ -104,3 +109,3 @@ impl UpdateService {
  124. let res = response.json::<UpdateServerVersion>().await?;
  125. - debug!(self.log, "Resolved version {} to {}", version, res.version);
  126. + debug!(self.log, "Resolved quality {} to {}", quality, res.version);
  127. @@ -115,40 +120,17 @@ impl UpdateService {
  128. - /// Gets the latest commit for the target of the given quality.
  129. - pub async fn get_latest_commit(
  130. - &self,
  131. - platform: Platform,
  132. - target: TargetKind,
  133. - quality: options::Quality,
  134. - ) -> Result<Release, AnyError> {
  135. - let update_endpoint = get_update_endpoint()?;
  136. - let download_segment = target
  137. - .download_segment(platform)
  138. - .ok_or_else(|| CodeError::UnsupportedPlatform(platform.to_string()))?;
  139. + pub fn get_download_url(&self, release: &Release) -> Result<String, AnyError> {
  140. + let app_name = get_app_name()?;
  141. + let download_endpoint = get_download_endpoint()?;
  142. +
  143. let download_url = format!(
  144. - "{}/api/latest/{}/{}",
  145. - &update_endpoint,
  146. - download_segment,
  147. - quality_download_segment(quality),
  148. + "{}/download/{}/{}-reh-web-{}-{}-{}.tar.gz",
  149. + download_endpoint,
  150. + release.name,
  151. + app_name,
  152. + release.platform.os(),
  153. + release.platform.arch(),
  154. + release.name,
  155. );
  156. - let mut response = spanf!(
  157. - self.log,
  158. - self.log.span("server.version.resolve"),
  159. - self.client.make_request("GET", download_url)
  160. - )?;
  161. -
  162. - if !response.status_code.is_success() {
  163. - return Err(response.into_err().await.into());
  164. - }
  165. -
  166. - let res = response.json::<UpdateServerVersion>().await?;
  167. - debug!(self.log, "Resolved quality {} to {}", quality, res.version);
  168. -
  169. - Ok(Release {
  170. - target,
  171. - platform,
  172. - quality,
  173. - name: res.name,
  174. - commit: res.version,
  175. - })
  176. + Ok(download_url)
  177. }
  178. @@ -157,15 +139,3 @@ impl UpdateService {
  179. pub async fn get_download_stream(&self, release: &Release) -> Result<SimpleResponse, AnyError> {
  180. - let update_endpoint = get_update_endpoint()?;
  181. - let download_segment = release
  182. - .target
  183. - .download_segment(release.platform)
  184. - .ok_or_else(|| CodeError::UnsupportedPlatform(release.platform.to_string()))?;
  185. -
  186. - let download_url = format!(
  187. - "{}/commit:{}/{}/{}",
  188. - &update_endpoint,
  189. - release.commit,
  190. - download_segment,
  191. - quality_download_segment(release.quality),
  192. - );
  193. + let download_url = self.get_download_url(release)?;
  194. @@ -203,13 +173,2 @@ pub enum TargetKind {
  195. -impl TargetKind {
  196. - fn download_segment(&self, platform: Platform) -> Option<String> {
  197. - match *self {
  198. - TargetKind::Server => Some(platform.headless()),
  199. - TargetKind::Archive => platform.archive(),
  200. - TargetKind::Web => Some(platform.web()),
  201. - TargetKind::Cli => Some(platform.cli()),
  202. - }
  203. - }
  204. -}
  205. -
  206. #[derive(Debug, Copy, Clone, Eq, PartialEq, Serialize, Deserialize)]
  207. @@ -232,30 +191,17 @@ pub enum Platform {
  208. impl Platform {
  209. - pub fn archive(&self) -> Option<String> {
  210. - match self {
  211. - Platform::LinuxX64 => Some("linux-x64".to_owned()),
  212. - Platform::LinuxARM64 => Some("linux-arm64".to_owned()),
  213. - Platform::LinuxARM32 => Some("linux-armhf".to_owned()),
  214. - Platform::DarwinX64 => Some("darwin".to_owned()),
  215. - Platform::DarwinARM64 => Some("darwin-arm64".to_owned()),
  216. - Platform::WindowsX64 => Some("win32-x64-archive".to_owned()),
  217. - Platform::WindowsX86 => Some("win32-archive".to_owned()),
  218. - Platform::WindowsARM64 => Some("win32-arm64-archive".to_owned()),
  219. - _ => None,
  220. - }
  221. - }
  222. - pub fn headless(&self) -> String {
  223. + pub fn arch(&self) -> String {
  224. match self {
  225. - Platform::LinuxAlpineARM64 => "server-alpine-arm64",
  226. - Platform::LinuxAlpineX64 => "server-linux-alpine",
  227. - Platform::LinuxX64 => "server-linux-x64",
  228. - Platform::LinuxX64Legacy => "server-linux-legacy-x64",
  229. - Platform::LinuxARM64 => "server-linux-arm64",
  230. - Platform::LinuxARM64Legacy => "server-linux-legacy-arm64",
  231. - Platform::LinuxARM32 => "server-linux-armhf",
  232. - Platform::LinuxARM32Legacy => "server-linux-legacy-armhf",
  233. - Platform::DarwinX64 => "server-darwin",
  234. - Platform::DarwinARM64 => "server-darwin-arm64",
  235. - Platform::WindowsX64 => "server-win32-x64",
  236. - Platform::WindowsX86 => "server-win32",
  237. - Platform::WindowsARM64 => "server-win32-arm64",
  238. + Platform::LinuxAlpineARM64 => "arm64",
  239. + Platform::LinuxAlpineX64 => "x64",
  240. + Platform::LinuxX64 => "x64",
  241. + Platform::LinuxX64Legacy => "x64",
  242. + Platform::LinuxARM64 => "arm64",
  243. + Platform::LinuxARM64Legacy => "arm64",
  244. + Platform::LinuxARM32 => "armhf",
  245. + Platform::LinuxARM32Legacy => "armhf",
  246. + Platform::DarwinX64 => "x64",
  247. + Platform::DarwinARM64 => "arm64",
  248. + Platform::WindowsX64 => "x64",
  249. + Platform::WindowsX86 => "ia42",
  250. + Platform::WindowsARM64 => "arm64",
  251. }
  252. @@ -264,17 +210,17 @@ impl Platform {
  253. - pub fn cli(&self) -> String {
  254. + pub fn os(&self) -> String {
  255. match self {
  256. - Platform::LinuxAlpineARM64 => "cli-alpine-arm64",
  257. - Platform::LinuxAlpineX64 => "cli-alpine-x64",
  258. - Platform::LinuxX64 => "cli-linux-x64",
  259. - Platform::LinuxX64Legacy => "cli-linux-x64",
  260. - Platform::LinuxARM64 => "cli-linux-arm64",
  261. - Platform::LinuxARM64Legacy => "cli-linux-arm64",
  262. - Platform::LinuxARM32 => "cli-linux-armhf",
  263. - Platform::LinuxARM32Legacy => "cli-linux-armhf",
  264. - Platform::DarwinX64 => "cli-darwin-x64",
  265. - Platform::DarwinARM64 => "cli-darwin-arm64",
  266. - Platform::WindowsARM64 => "cli-win32-arm64",
  267. - Platform::WindowsX64 => "cli-win32-x64",
  268. - Platform::WindowsX86 => "cli-win32",
  269. + Platform::LinuxAlpineARM64 => "alpine",
  270. + Platform::LinuxAlpineX64 => "alpine",
  271. + Platform::LinuxX64 => "linux",
  272. + Platform::LinuxX64Legacy => "linux",
  273. + Platform::LinuxARM64 => "linux",
  274. + Platform::LinuxARM64Legacy => "linux",
  275. + Platform::LinuxARM32 => "linux",
  276. + Platform::LinuxARM32Legacy => "linux",
  277. + Platform::DarwinX64 => "darwin",
  278. + Platform::DarwinARM64 => "darwin",
  279. + Platform::WindowsX64 => "win32",
  280. + Platform::WindowsX86 => "win32",
  281. + Platform::WindowsARM64 => "win32",
  282. }
  283. @@ -283,6 +229,2 @@ impl Platform {
  284. - pub fn web(&self) -> String {
  285. - format!("{}-web", self.headless())
  286. - }
  287. -
  288. pub fn env_default() -> Option<Platform> {
  289. diff --git a/extensions/tunnel-forwarding/src/extension.ts b/extensions/tunnel-forwarding/src/extension.ts
  290. index 299c728..9fb635d 100644
  291. --- a/extensions/tunnel-forwarding/src/extension.ts
  292. +++ b/extensions/tunnel-forwarding/src/extension.ts
  293. @@ -28,3 +28,3 @@ const cliPath = process.env.VSCODE_FORWARDING_IS_DEV
  294. process.platform === 'darwin' ? 'bin' : '../../bin',
  295. - vscode.env.appQuality === 'stable' ? 'code-tunnel' : 'code-tunnel-insiders',
  296. + '!!TUNNEL_APP_NAME!!'
  297. ) + (process.platform === 'win32' ? '.exe' : '');