@@ -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.
254254fn 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.
281281fn 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.
611612fn 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