Skip to content

Commit 2810b60

Browse files
committedJul 19, 2024
Refactor get_app_manifes
Removing the async allowed the code to be greatly simplified, and likely doesn't impact performance anyway.
1 parent fd83010 commit 2810b60

File tree

2 files changed

+12
-35
lines changed

2 files changed

+12
-35
lines changed
 

‎test/test-manager/src/main.rs

-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ async fn main() -> Result<()> {
266266
app_package_to_upgrade_from,
267267
package_folder,
268268
)
269-
.await
270269
.context("Could not find the specified app packages")?;
271270

272271
let mut instance = vm::run(&config, &name)

‎test/test-manager/src/package.rs

+12-34
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use anyhow::{Context, Result};
33
use once_cell::sync::Lazy;
44
use regex::Regex;
55
use std::path::{Path, PathBuf};
6-
use tokio::fs;
76

87
static VERSION_REGEX: Lazy<Regex> =
98
Lazy::new(|| Regex::new(r"\d{4}\.\d+(-beta\d+)?(-dev)?-([0-9a-z])+").unwrap());
@@ -19,34 +18,21 @@ pub struct Manifest {
1918
/// If it's a path, use the path.
2019
/// If it corresponds to a file in packages/, use that package.
2120
/// TODO: If it's a git tag or rev, download it.
22-
pub async fn get_app_manifest(
21+
pub fn get_app_manifest(
2322
config: &VmConfig,
2423
app_package: String,
2524
app_package_to_upgrade_from: Option<String>,
2625
package_folder: Option<PathBuf>,
2726
) -> Result<Manifest> {
2827
let package_type = (config.os_type, config.package_type, config.architecture);
2928

30-
let app_package_path =
31-
find_app(&app_package, false, package_type, package_folder.as_ref()).await?;
29+
let app_package_path = find_app(&app_package, false, package_type, package_folder.as_ref())?;
3230
log::info!("Current app: {}", app_package_path.display());
3331

34-
let app_package_to_upgrade_from_path =
35-
if let Some(app_package_to_upgrade_from) = app_package_to_upgrade_from {
36-
log::info!("Previous app: {}", app_package_to_upgrade_from);
37-
Some(
38-
find_app(
39-
&app_package_to_upgrade_from,
40-
false,
41-
package_type,
42-
package_folder.as_ref(),
43-
)
44-
.await?,
45-
)
46-
} else {
47-
log::warn!("No previous app version specified");
48-
None
49-
};
32+
let app_package_to_upgrade_from_path = app_package_to_upgrade_from
33+
.map(|app| find_app(&app, false, package_type, package_folder.as_ref()))
34+
.transpose()?;
35+
log::info!("Previous app: {app_package_to_upgrade_from_path:?}");
5036

5137
let capture = VERSION_REGEX
5238
.captures(app_package_path.to_str().unwrap())
@@ -55,14 +41,8 @@ pub async fn get_app_manifest(
5541
.map(|c| c.as_str())
5642
.expect("Could not parse version from package name: {app_package}");
5743

58-
let ui_e2e_tests_path = find_app(capture, true, package_type, package_folder.as_ref())
59-
.await
60-
.ok();
61-
if let Some(ui_e2e_tests_path) = &ui_e2e_tests_path {
62-
log::info!("GUI e2e test binary: {}", ui_e2e_tests_path.display());
63-
} else {
64-
log::warn!("Could not find UI e2e test binary");
65-
}
44+
let ui_e2e_tests_path = find_app(capture, true, package_type, package_folder.as_ref()).ok();
45+
log::info!("GUI e2e test binary: {ui_e2e_tests_path:?}");
6646

6747
Ok(Manifest {
6848
app_package_path,
@@ -71,7 +51,7 @@ pub async fn get_app_manifest(
7151
})
7252
}
7353

74-
async fn find_app(
54+
fn find_app(
7555
app: &str,
7656
e2e_bin: bool,
7757
package_type: (OsType, Option<PackageType>, Option<Architecture>),
@@ -89,14 +69,12 @@ async fn find_app(
8969

9070
let current_dir = std::env::current_dir().expect("Unable to get current directory");
9171
let packages_dir = package_folder.unwrap_or(&current_dir);
92-
fs::create_dir_all(&packages_dir).await?;
93-
let mut dir = fs::read_dir(packages_dir.clone())
94-
.await
95-
.context("Failed to list packages")?;
72+
std::fs::create_dir_all(packages_dir)?;
73+
let mut dir = std::fs::read_dir(packages_dir.clone()).context("Failed to list packages")?;
9674

9775
let mut matches = vec![];
9876

99-
while let Ok(Some(entry)) = dir.next_entry().await {
77+
while let Some(Ok(entry)) = dir.next() {
10078
let path = entry.path();
10179
if !path.is_file() {
10280
continue;

0 commit comments

Comments
 (0)