Skip to content

Commit 68023f2

Browse files
committed
Use sudo to escalate privilege and try again to copy/edit ini file
1 parent 060c8bf commit 68023f2

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

crates/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dialoguer = "0.11"
1919
libloading = "0.8"
2020
cargo_metadata = "0.20"
2121
semver = "1.0"
22+
sudo = "0.6.0"
2223

2324
[lints.rust]
2425
missing_docs = "warn"

crates/cli/src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,16 @@ impl Install {
221221
ext_dir.push(ext_name);
222222
}
223223

224-
std::fs::copy(&ext_path, &ext_dir).with_context(|| {
225-
"Failed to copy extension from target directory to extension directory"
226-
})?;
224+
// We copying of file fails, escalate the privilege and try again.
225+
if let Err(_) = std::fs::copy(&ext_path, &ext_dir) {
226+
// failed to copy. escalate the privileges and try again.
227+
#[cfg(unix)]
228+
let _ = sudo::escalate_if_needed().ok();
229+
230+
std::fs::copy(&ext_path, &ext_dir).with_context(|| {
231+
"Failed to copy extension from target directory to extension directory"
232+
})?;
233+
}
227234

228235
if let Some(php_ini) = php_ini {
229236
let mut file = OpenOptions::new()

0 commit comments

Comments
 (0)