Skip to content

Commit 3f14db6

Browse files
committed
replace nix with libc
since libc is already in cargo.lock
1 parent 5d6dfa3 commit 3f14db6

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

crates/cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ cargo_metadata = "0.20"
2121
semver = "1.0"
2222

2323
[target.'cfg(unix)'.dependencies]
24-
nix = { version = "0.30", features=["user"]}
24+
libc = "0.2"
2525

2626
[lints.rust]
2727
missing_docs = "warn"

crates/cli/src/lib.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl Install {
201201
#[cfg(unix)]
202202
if !self.bypass_root_check {
203203
anyhow::ensure!(
204-
! is_root(),
204+
!is_root(),
205205
"Running as root is not recommended. Use --bypass-root-check to override."
206206
);
207207
}
@@ -249,8 +249,8 @@ impl Install {
249249

250250
// Update extension line in the ini file.
251251
//
252-
// Write to a temp file then copy it to a given path. If this fails, then try `sudo mv`
253-
// on unix.
252+
// Write to a temp file then copy it to a given path. If this fails, then try
253+
// `sudo mv` on unix.
254254
fn update_ini_file(php_ini: &PathBuf, ext_name: &str, disable: bool) -> anyhow::Result<()> {
255255
let current_ini_content = std::fs::read_to_string(php_ini)?;
256256
let mut ext_line = format!("extension={ext_name}");
@@ -277,7 +277,7 @@ fn update_ini_file(php_ini: &PathBuf, ext_name: &str, disable: bool) -> anyhow::
277277
//
278278
// Checking if we have write permission for ext_dir may fail due to ACL, group
279279
// list and and other nuances. See
280-
// https://doc.rust-lang.org/std/fs/struct.Permissions.html#method.readonly.
280+
// https://doc.rust-lang.org/std/fs/struct.Permissions.html#method.readonly.
281281
fn copy_extension(ext_path: &Utf8PathBuf, ext_dir: &PathBuf) -> anyhow::Result<()> {
282282
if let Err(_e) = std::fs::copy(ext_path, ext_dir) {
283283
#[cfg(unix)]
@@ -606,8 +606,9 @@ fn build_ext(
606606

607607
// Write content to a given filepath.
608608
//
609-
// We may not have write permission but we may have sudo privilege on unix. So we write to
610-
// a temp file and then try moving it to given filepath, and retry with sudo on unix.
609+
// We may not have write permission but we may have sudo privilege on unix. So
610+
// we write to a temp file and then try moving it to given filepath, and retry
611+
// with sudo on unix.
611612
fn write_to_file(content: String, filepath: &PathBuf) -> anyhow::Result<()> {
612613
// write to a temp file
613614
let tempf = std::env::temp_dir().join("__tmp_cargo_php");
@@ -634,7 +635,14 @@ fn write_to_file(content: String, filepath: &PathBuf) -> anyhow::Result<()> {
634635
}
635636

636637
#[cfg(unix)]
637-
fn is_root() -> bool
638-
{
639-
nix::unistd::Uid::effective().is_root()
638+
fn is_root() -> bool {
639+
// nix::unistd::Uid::effective().is_root()
640+
let uid = unsafe { libc::getuid() };
641+
let euid = unsafe { libc::geteuid() };
642+
643+
match (uid, euid) {
644+
(0, 0) => true,
645+
(_, 0) => true, // suid set
646+
(_, _) => false,
647+
}
640648
}

0 commit comments

Comments
 (0)