@@ -121,6 +121,9 @@ struct Install {
121
121
/// Whether to bypass the install prompt.
122
122
#[ clap( long) ]
123
123
yes : bool ,
124
+ /// Whether to bypass the root check
125
+ #[ clap( long) ]
126
+ bypass_root_check : bool ,
124
127
}
125
128
126
129
#[ derive( Parser ) ]
@@ -140,6 +143,9 @@ struct Remove {
140
143
/// Whether to bypass the remove prompt.
141
144
#[ clap( long) ]
142
145
yes : bool ,
146
+ /// Whether to bypass the root check
147
+ #[ clap( long) ]
148
+ bypass_root_check : bool ,
143
149
}
144
150
145
151
#[ cfg( not( windows) ) ]
@@ -193,6 +199,11 @@ impl Install {
193
199
self . no_default_features ,
194
200
) ?;
195
201
202
+ if !self . bypass_root_check {
203
+ #[ cfg( unix) ]
204
+ sudo:: escalate_if_needed ( ) . expect ( "failed to escalate root privileges." ) ;
205
+ }
206
+
196
207
let ( mut ext_dir, mut php_ini) = if let Some ( install_dir) = self . install_dir {
197
208
( install_dir, None )
198
209
} else {
@@ -221,16 +232,9 @@ impl Install {
221
232
ext_dir. push ( ext_name) ;
222
233
}
223
234
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
- }
235
+ std:: fs:: copy ( & ext_path, & ext_dir) . with_context ( || {
236
+ "Failed to copy extension from target directory to extension directory"
237
+ } ) ?;
234
238
235
239
if let Some ( php_ini) = php_ini {
236
240
let mut file = OpenOptions :: new ( )
@@ -323,6 +327,11 @@ impl Remove {
323
327
pub fn handle ( self ) -> CrateResult {
324
328
use std:: env:: consts;
325
329
330
+ if !self . bypass_root_check {
331
+ #[ cfg( unix) ]
332
+ sudo:: escalate_if_needed ( ) . expect ( "failed to escalate root privileges." ) ;
333
+ }
334
+
326
335
let artifact = find_ext ( self . manifest . as_ref ( ) ) ?;
327
336
328
337
let ( mut ext_path, mut php_ini) = if let Some ( install_dir) = self . install_dir {
0 commit comments