Skip to content

Commit 1ebd884

Browse files
Copilotjosecelano
andcommitted
fix: resolve Windows compilation errors in OpenTofu installer
Move non-Unix early return to the beginning of install() method to avoid unreachable code warnings on Windows. All Unix-specific installation logic is now properly guarded with #[cfg(unix)] blocks. Co-authored-by: josecelano <[email protected]>
1 parent 2cd4101 commit 1ebd884

File tree

1 file changed

+64
-64
lines changed

1 file changed

+64
-64
lines changed

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

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -37,39 +37,47 @@ impl DependencyInstaller for OpenTofuInstaller {
3737
}
3838

3939
async fn install(&self) -> Result<(), InstallationError> {
40-
info!(dependency = "opentofu", "Installing OpenTofu");
41-
42-
let script_path = "/tmp/install-opentofu.sh";
43-
44-
// Download installer script
45-
debug!("Downloading OpenTofu installer script");
46-
let output = Command::new("curl")
47-
.args([
48-
"--proto",
49-
"=https",
50-
"--tlsv1.2",
51-
"-fsSL",
52-
"https://get.opentofu.org/install-opentofu.sh",
53-
"-o",
54-
script_path,
55-
])
56-
.output()
57-
.map_err(|e| InstallationError::CommandFailed {
58-
dependency: Dependency::OpenTofu,
59-
source: e,
60-
})?;
61-
62-
if !output.status.success() {
63-
let stderr = String::from_utf8_lossy(&output.stderr);
40+
#[cfg(not(unix))]
41+
{
6442
return Err(InstallationError::InstallationFailed {
6543
dependency: Dependency::OpenTofu,
66-
message: format!("Failed to download installer: {stderr}"),
44+
message: "OpenTofu installation is only supported on Unix-like systems".to_string(),
6745
});
6846
}
6947

70-
// Make script executable (Unix-specific)
7148
#[cfg(unix)]
7249
{
50+
info!(dependency = "opentofu", "Installing OpenTofu");
51+
52+
let script_path = "/tmp/install-opentofu.sh";
53+
54+
// Download installer script
55+
debug!("Downloading OpenTofu installer script");
56+
let output = Command::new("curl")
57+
.args([
58+
"--proto",
59+
"=https",
60+
"--tlsv1.2",
61+
"-fsSL",
62+
"https://get.opentofu.org/install-opentofu.sh",
63+
"-o",
64+
script_path,
65+
])
66+
.output()
67+
.map_err(|e| InstallationError::CommandFailed {
68+
dependency: Dependency::OpenTofu,
69+
source: e,
70+
})?;
71+
72+
if !output.status.success() {
73+
let stderr = String::from_utf8_lossy(&output.stderr);
74+
return Err(InstallationError::InstallationFailed {
75+
dependency: Dependency::OpenTofu,
76+
message: format!("Failed to download installer: {stderr}"),
77+
});
78+
}
79+
80+
// Make script executable
7381
debug!("Making installer script executable");
7482
fs::set_permissions(
7583
script_path,
@@ -79,50 +87,42 @@ impl DependencyInstaller for OpenTofuInstaller {
7987
dependency: Dependency::OpenTofu,
8088
source: e,
8189
})?;
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-
}
9190

92-
// Run installer with sudo
93-
debug!("Running OpenTofu installer with sudo");
94-
let output = Command::new("sudo")
95-
.args([script_path, "--install-method", "deb"])
96-
.output()
97-
.map_err(|e| InstallationError::CommandFailed {
91+
// Run installer with sudo
92+
debug!("Running OpenTofu installer with sudo");
93+
let output = Command::new("sudo")
94+
.args([script_path, "--install-method", "deb"])
95+
.output()
96+
.map_err(|e| InstallationError::CommandFailed {
97+
dependency: Dependency::OpenTofu,
98+
source: e,
99+
})?;
100+
101+
if !output.status.success() {
102+
let stderr = String::from_utf8_lossy(&output.stderr);
103+
// Clean up script before returning error (ignore cleanup errors)
104+
fs::remove_file(script_path).ok();
105+
return Err(InstallationError::InstallationFailed {
106+
dependency: Dependency::OpenTofu,
107+
message: format!("Installer script failed: {stderr}"),
108+
});
109+
}
110+
111+
// Clean up installer script
112+
debug!("Cleaning up installer script");
113+
fs::remove_file(script_path).map_err(|e| InstallationError::CommandFailed {
98114
dependency: Dependency::OpenTofu,
99115
source: e,
100116
})?;
101117

102-
if !output.status.success() {
103-
let stderr = String::from_utf8_lossy(&output.stderr);
104-
// Clean up script before returning error (ignore cleanup errors)
105-
fs::remove_file(script_path).ok();
106-
return Err(InstallationError::InstallationFailed {
107-
dependency: Dependency::OpenTofu,
108-
message: format!("Installer script failed: {stderr}"),
109-
});
110-
}
118+
info!(
119+
dependency = "opentofu",
120+
status = "installed",
121+
"OpenTofu installation completed"
122+
);
111123

112-
// Clean up installer script
113-
debug!("Cleaning up installer script");
114-
fs::remove_file(script_path).map_err(|e| InstallationError::CommandFailed {
115-
dependency: Dependency::OpenTofu,
116-
source: e,
117-
})?;
118-
119-
info!(
120-
dependency = "opentofu",
121-
status = "installed",
122-
"OpenTofu installation completed"
123-
);
124-
125-
Ok(())
124+
Ok(())
125+
}
126126
}
127127

128128
fn requires_sudo(&self) -> bool {

0 commit comments

Comments
 (0)