|
7 | 7 |
|
8 | 8 | // spell-checker:ignore (vars) fperm srwx |
9 | 9 |
|
10 | | -use libc::{S_IRGRP, S_IROTH, S_IRUSR, S_IWGRP, S_IWOTH, S_IWUSR, mode_t, umask}; |
| 10 | +use libc::umask; |
11 | 11 |
|
12 | 12 | pub fn parse_numeric(fperm: u32, mut mode: &str, considering_dir: bool) -> Result<u32, String> { |
13 | 13 | let (op, pos) = parse_op(mode).map_or_else(|_| (None, 0), |(op, pos)| (Some(op), pos)); |
@@ -169,13 +169,6 @@ pub fn parse(mode_string: &str, considering_dir: bool, umask: u32) -> Result<u32 |
169 | 169 | parse_chmod(0, mode_string, considering_dir, umask) |
170 | 170 | } |
171 | 171 |
|
172 | | -#[allow(clippy::unnecessary_cast)] |
173 | | -pub fn parse_mode(mode: &str) -> Result<mode_t, String> { |
174 | | - let mut new_mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32; |
175 | | - new_mode = parse_chmod(new_mode, mode, true, get_umask())?; |
176 | | - Ok(new_mode as mode_t) |
177 | | -} |
178 | | - |
179 | 172 | pub fn get_umask() -> u32 { |
180 | 173 | // There's no portable way to read the umask without changing it. |
181 | 174 | // We have to replace it and then quickly set it back, hopefully before |
@@ -207,24 +200,20 @@ mod tests { |
207 | 200 |
|
208 | 201 | use super::parse; |
209 | 202 | use super::parse_chmod; |
210 | | - use super::parse_mode; |
211 | 203 |
|
212 | 204 | #[test] |
213 | | - fn test_symbolic_modes() { |
214 | | - assert_eq!(parse_mode("u+x").unwrap(), 0o766); |
215 | | - assert_eq!( |
216 | | - parse_mode("+x").unwrap(), |
217 | | - if crate::os::is_wsl_1() { 0o776 } else { 0o777 } |
218 | | - ); |
219 | | - assert_eq!(parse_mode("a-w").unwrap(), 0o444); |
220 | | - assert_eq!(parse_mode("g-r").unwrap(), 0o626); |
| 205 | + fn test_chmod_symbolic_modes() { |
| 206 | + assert_eq!(parse_chmod(0o666, "u+x", false, 0).unwrap(), 0o766); |
| 207 | + assert_eq!(parse_chmod(0o666, "+x", false, 0).unwrap(), 0o777); |
| 208 | + assert_eq!(parse_chmod(0o666, "a-w", false, 0).unwrap(), 0o444); |
| 209 | + assert_eq!(parse_chmod(0o666, "g-r", false, 0).unwrap(), 0o626); |
221 | 210 | } |
222 | 211 |
|
223 | 212 | #[test] |
224 | | - fn test_numeric_modes() { |
225 | | - assert_eq!(parse_mode("644").unwrap(), 0o644); |
226 | | - assert_eq!(parse_mode("+100").unwrap(), 0o766); |
227 | | - assert_eq!(parse_mode("-4").unwrap(), 0o662); |
| 213 | + fn test_chmod_numeric_modes() { |
| 214 | + assert_eq!(parse_chmod(0o666, "644", false, 0).unwrap(), 0o644); |
| 215 | + assert_eq!(parse_chmod(0o666, "+100", false, 0).unwrap(), 0o766); |
| 216 | + assert_eq!(parse_chmod(0o666, "-4", false, 0).unwrap(), 0o662); |
228 | 217 | } |
229 | 218 |
|
230 | 219 | #[test] |
@@ -345,19 +334,4 @@ mod tests { |
345 | 334 | // First add user write, then set to 755 (should override) |
346 | 335 | assert_eq!(parse("u+w,755", false, 0).unwrap(), 0o755); |
347 | 336 | } |
348 | | - |
349 | | - #[test] |
350 | | - fn test_chmod_symbolic_modes() { |
351 | | - assert_eq!(parse_chmod(0o666, "u+x", false, 0).unwrap(), 0o766); |
352 | | - assert_eq!(parse_chmod(0o666, "+x", false, 0).unwrap(), 0o777); |
353 | | - assert_eq!(parse_chmod(0o666, "a-w", false, 0).unwrap(), 0o444); |
354 | | - assert_eq!(parse_chmod(0o666, "g-r", false, 0).unwrap(), 0o626); |
355 | | - } |
356 | | - |
357 | | - #[test] |
358 | | - fn test_chmod_numeric_modes() { |
359 | | - assert_eq!(parse_chmod(0o666, "644", false, 0).unwrap(), 0o644); |
360 | | - assert_eq!(parse_chmod(0o666, "+100", false, 0).unwrap(), 0o766); |
361 | | - assert_eq!(parse_chmod(0o666, "-4", false, 0).unwrap(), 0o662); |
362 | | - } |
363 | 337 | } |
0 commit comments