Skip to content

Commit 0aa2255

Browse files
authored
Merge pull request microsoft#165861 from microsoft/connor4312/cli-async-handling
cli: allow handling control server requests in parallel
2 parents dec7735 + 1614182 commit 0aa2255

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)