Skip to content

Commit 2cd4101

Browse files
Copilotjosecelano
andcommitted
fix: address code review feedback - async sleep and cross-platform concerns
Co-authored-by: josecelano <[email protected]>
1 parent edbfde5 commit 2cd4101

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

packages/dependency-installer/src/installer/lxd.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
55
// Standard library
66
use std::process::Command;
7-
use std::thread;
8-
use std::time::Duration;
97

108
// External crates
119
use async_trait::async_trait;
@@ -60,7 +58,7 @@ impl DependencyInstaller for LxdInstaller {
6058

6159
// Wait for LXD daemon to start
6260
debug!("Waiting for LXD daemon to initialize");
63-
thread::sleep(Duration::from_secs(15));
61+
tokio::time::sleep(tokio::time::Duration::from_secs(15)).await;
6462

6563
// Initialize LXD with default settings
6664
debug!("Initializing LXD with default settings");

packages/dependency-installer/src/installer/opentofu.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,27 @@ impl DependencyInstaller for OpenTofuInstaller {
6767
});
6868
}
6969

70-
// Make script executable
71-
debug!("Making installer script executable");
72-
fs::set_permissions(
73-
script_path,
74-
std::os::unix::fs::PermissionsExt::from_mode(0o755),
75-
)
76-
.map_err(|e| InstallationError::CommandFailed {
77-
dependency: Dependency::OpenTofu,
78-
source: e,
79-
})?;
70+
// Make script executable (Unix-specific)
71+
#[cfg(unix)]
72+
{
73+
debug!("Making installer script executable");
74+
fs::set_permissions(
75+
script_path,
76+
std::os::unix::fs::PermissionsExt::from_mode(0o755),
77+
)
78+
.map_err(|e| InstallationError::CommandFailed {
79+
dependency: Dependency::OpenTofu,
80+
source: e,
81+
})?;
82+
}
83+
84+
#[cfg(not(unix))]
85+
{
86+
return Err(InstallationError::InstallationFailed {
87+
dependency: Dependency::OpenTofu,
88+
message: "OpenTofu installation is only supported on Unix-like systems".to_string(),
89+
});
90+
}
8091

8192
// Run installer with sudo
8293
debug!("Running OpenTofu installer with sudo");
@@ -90,8 +101,8 @@ impl DependencyInstaller for OpenTofuInstaller {
90101

91102
if !output.status.success() {
92103
let stderr = String::from_utf8_lossy(&output.stderr);
93-
// Clean up script before returning error
94-
drop(fs::remove_file(script_path));
104+
// Clean up script before returning error (ignore cleanup errors)
105+
fs::remove_file(script_path).ok();
95106
return Err(InstallationError::InstallationFailed {
96107
dependency: Dependency::OpenTofu,
97108
message: format!("Installer script failed: {stderr}"),

0 commit comments

Comments
 (0)