Skip to content

Commit 1614182

Browse files
committed
cli: allow handling control server requests in parallel
Previously the control server could only handle a single request at a time. To enable local download mode, this needs to change as the client will be sending data to the CLI as it downloads the vscode server zip. This does that. There's a little mess since things that async handlers need to use are cloned out of the previously unified "context" (we could try and clone the whole context each time, but this is more work than needed.) We still keep the fast things as "blocking" since that avoids the need for clones and separate tasks.
1 parent 2cd1bf6 commit 1614182

File tree

4 files changed

+203
-121
lines changed

4 files changed

+203
-121
lines changed

cli/src/desktop/version_manager.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -318,17 +318,11 @@ fn detect_installed_program(log: &log::Logger, quality: Quality) -> io::Result<V
318318
}
319319
}
320320
State::LookingForLocation => {
321-
if line.starts_with(LOCATION_PREFIX) {
321+
if let Some(suffix) = line.strip_prefix(LOCATION_PREFIX) {
322322
output.push(
323-
[
324-
&line[LOCATION_PREFIX.len()..].trim(),
325-
"Contents/Resources",
326-
"app",
327-
"bin",
328-
"code",
329-
]
330-
.iter()
331-
.collect(),
323+
[suffix.trim(), "Contents/Resources", "app", "bin", "code"]
324+
.iter()
325+
.collect(),
332326
);
333327
state = State::LookingForName;
334328
}
@@ -338,7 +332,7 @@ fn detect_installed_program(log: &log::Logger, quality: Quality) -> io::Result<V
338332

339333
// Sort shorter paths to the front, preferring "more global" installs, and
340334
// incidentally preferring local installs over Parallels 'installs'.
341-
output.sort_by(|a, b| a.as_os_str().len().cmp(&b.as_os_str().len()));
335+
output.sort_by_key(|a| a.as_os_str().len());
342336

343337
Ok(output)
344338
}

cli/src/tunnels/code_server.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use std::fs;
2424
use std::fs::File;
2525
use std::io::{ErrorKind, Write};
2626
use std::path::{Path, PathBuf};
27+
use std::sync::Arc;
2728
use std::time::Duration;
2829
use tokio::fs::remove_file;
2930
use tokio::io::{AsyncBufReadExt, BufReader};
@@ -209,17 +210,19 @@ struct UpdateServerVersion {
209210
}
210211

211212
/// Code server listening on a port address.
213+
#[derive(Clone)]
212214
pub struct SocketCodeServer {
213215
pub commit_id: String,
214216
pub socket: PathBuf,
215-
pub origin: CodeServerOrigin,
217+
pub origin: Arc<CodeServerOrigin>,
216218
}
217219

218220
/// Code server listening on a socket address.
221+
#[derive(Clone)]
219222
pub struct PortCodeServer {
220223
pub commit_id: String,
221224
pub port: u16,
222-
pub origin: CodeServerOrigin,
225+
pub origin: Arc<CodeServerOrigin>,
223226
}
224227

225228
/// A server listening on any address/location.
@@ -448,7 +451,7 @@ impl<'a> ServerBuilder<'a> {
448451
)
449452
.await?;
450453

451-
let origin = CodeServerOrigin::Existing(pid);
454+
let origin = Arc::new(CodeServerOrigin::Existing(pid));
452455
let contents = fs::read_to_string(&self.server_paths.logfile)
453456
.expect("Something went wrong reading log file");
454457

@@ -544,7 +547,7 @@ impl<'a> ServerBuilder<'a> {
544547
Ok(SocketCodeServer {
545548
commit_id: self.server_params.release.commit.to_owned(),
546549
socket,
547-
origin,
550+
origin: Arc::new(origin),
548551
})
549552
}
550553

0 commit comments

Comments
 (0)