@@ -201,7 +201,7 @@ impl Install {
201
201
#[ cfg( unix) ]
202
202
if !self . bypass_root_check {
203
203
anyhow:: ensure!(
204
- ! is_root( ) ,
204
+ !is_root( ) ,
205
205
"Running as root is not recommended. Use --bypass-root-check to override."
206
206
) ;
207
207
}
@@ -249,8 +249,8 @@ impl Install {
249
249
250
250
// Update extension line in the ini file.
251
251
//
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.
254
254
fn update_ini_file ( php_ini : & PathBuf , ext_name : & str , disable : bool ) -> anyhow:: Result < ( ) > {
255
255
let current_ini_content = std:: fs:: read_to_string ( php_ini) ?;
256
256
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::
277
277
//
278
278
// Checking if we have write permission for ext_dir may fail due to ACL, group
279
279
// 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.
281
281
fn copy_extension ( ext_path : & Utf8PathBuf , ext_dir : & PathBuf ) -> anyhow:: Result < ( ) > {
282
282
if let Err ( _e) = std:: fs:: copy ( ext_path, ext_dir) {
283
283
#[ cfg( unix) ]
@@ -606,8 +606,9 @@ fn build_ext(
606
606
607
607
// Write content to a given filepath.
608
608
//
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.
611
612
fn write_to_file ( content : String , filepath : & PathBuf ) -> anyhow:: Result < ( ) > {
612
613
// write to a temp file
613
614
let tempf = std:: env:: temp_dir ( ) . join ( "__tmp_cargo_php" ) ;
@@ -634,7 +635,14 @@ fn write_to_file(content: String, filepath: &PathBuf) -> anyhow::Result<()> {
634
635
}
635
636
636
637
#[ 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
+ }
640
648
}
0 commit comments