cli: add acquire_cli (#179837)

* cli: add acquire_cli

As given in my draft document, pipes a CLI of the given platform to the
specified process, for example:

```js
const cmd = await rpc.call('acquire_cli', {
	command: 'node',
	args: [
		'-e',
		'process.stdin.pipe(fs.createWriteStream("c:/users/conno/downloads/hello-cli"))',
	],
	platform: Platform.LinuxX64,
	quality: 'insider',
});
```

It genericizes caching so that the CLI is also cached on the host, just
like servers.

* fix bug
This commit is contained in:
Connor Peet
2023-04-13 11:18:48 -07:00
committed by GitHub
parent 24c44070ae
commit f743297aa1
15 changed files with 489 additions and 405 deletions

View File

@@ -15,6 +15,7 @@ use serde::{de::DeserializeOwned, Serialize};
use crate::{
constants::VSCODE_CLI_QUALITY,
download_cache::DownloadCache,
util::errors::{wrap, AnyError, NoHomeForLauncherError, WrappedError},
};
@@ -22,6 +23,8 @@ const HOME_DIR_ALTS: [&str; 2] = ["$HOME", "~"];
#[derive(Clone)]
pub struct LauncherPaths {
pub server_cache: DownloadCache,
pub cli_cache: DownloadCache,
root: PathBuf,
}
@@ -95,14 +98,10 @@ where
}
/// Mutates persisted state.
pub fn update_with<V, R>(
&self,
v: V,
mutator: fn(v: V, state: &mut T) -> R,
) -> Result<R, WrappedError> {
pub fn update<R>(&self, mutator: impl FnOnce(&mut T) -> R) -> Result<R, WrappedError> {
let mut container = self.container.lock().unwrap();
let mut state = container.load_or_get();
let r = mutator(v, &mut state);
let r = mutator(&mut state);
container.save(state).map(|_| r)
}
}
@@ -132,7 +131,15 @@ impl LauncherPaths {
}
pub fn new_without_replacements(root: PathBuf) -> LauncherPaths {
LauncherPaths { root }
// cleanup folders that existed before the new LRU strategy:
let _ = std::fs::remove_dir_all(root.join("server-insiders"));
let _ = std::fs::remove_dir_all(root.join("server-stable"));
LauncherPaths {
server_cache: DownloadCache::new(root.join("servers")),
cli_cache: DownloadCache::new(root.join("cli")),
root,
}
}
/// Root directory for the server launcher