Skip to content

Commit 5340b68

Browse files
Cleaned up platform-specific code
1 parent 6e09ec0 commit 5340b68

File tree

22 files changed

+142
-172
lines changed

22 files changed

+142
-172
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

file/find.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ fn parse_expression(tokens: &mut Vec<&str>) -> Vec<Expr> {
149149
"-size" => {
150150
tokens.pop();
151151
if let Some(size) = tokens.pop() {
152-
let (size, in_bytes) = if size.ends_with('c') {
153-
(size[..size.len() - 1].parse::<u64>().unwrap_or(0), true)
152+
let (size, in_bytes) = if let Some(st) = size.strip_suffix('c') {
153+
(st.parse::<u64>().unwrap_or(0), true)
154154
} else {
155155
(size.parse::<u64>().unwrap_or(0), false)
156156
};
@@ -250,15 +250,15 @@ fn evaluate_expression(
250250
match expression {
251251
Expr::Not(inner) => {
252252
let i: Vec<Expr> = vec![f_path.clone(), *inner.clone()];
253-
not_res = evaluate_expression(&i.as_slice(), files.clone(), root_dev)?;
253+
not_res = evaluate_expression(i.as_slice(), files.clone(), root_dev)?;
254254
}
255255
Expr::Or(inner) => {
256256
let i: Vec<Expr> = vec![f_path.clone(), *inner.clone()];
257-
or_res = evaluate_expression(&i.as_slice(), files.clone(), root_dev)?;
257+
or_res = evaluate_expression(i.as_slice(), files.clone(), root_dev)?;
258258
}
259259
Expr::And(inner) => {
260260
let i: Vec<Expr> = vec![f_path.clone(), *inner.clone()];
261-
and_res = evaluate_expression(&i.as_slice(), files.clone(), root_dev)?;
261+
and_res = evaluate_expression(i.as_slice(), files.clone(), root_dev)?;
262262
}
263263
_ => {}
264264
}
@@ -307,7 +307,7 @@ fn evaluate_expression(
307307
FileType::Fifo => file_type.is_fifo(),
308308
FileType::File => file_type.is_file(),
309309
FileType::Socket => file_type.is_socket(),
310-
FileType::Unknown => return Err(format!("Unknown argument to -type")),
310+
FileType::Unknown => return Err("Unknown argument to -type".to_owned()),
311311
};
312312
if !r {
313313
c_files.remove(file.path());
@@ -316,15 +316,15 @@ fn evaluate_expression(
316316
Expr::NoUser => {
317317
if let Ok(metadata) = file.metadata() {
318318
let uid = metadata.uid();
319-
if !users::get_user_by_uid(uid).is_none() {
319+
if users::get_user_by_uid(uid).is_some() {
320320
c_files.remove(file.path());
321321
}
322322
}
323323
}
324324
Expr::NoGroup => {
325325
if let Ok(metadata) = file.metadata() {
326326
let gid = metadata.gid();
327-
if !users::get_group_by_gid(gid).is_none() {
327+
if users::get_group_by_gid(gid).is_some() {
328328
c_files.remove(file.path());
329329
}
330330
}

ftw/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ enum ProcessFileResult {
422422
}
423423

424424
fn process_file<F, H>(
425-
path_stack: &Vec<Rc<[libc::c_char]>>,
425+
path_stack: &[Rc<[libc::c_char]>],
426426
dir_fd: &FileDescriptor,
427427
entry_filename: Rc<[libc::c_char]>,
428428
follow_symlinks: bool,
@@ -439,7 +439,7 @@ where
439439
Ok(md) => md,
440440
Err(e) => {
441441
err_reporter(
442-
Entry::new(dir_fd, &path_stack, &entry_filename, None),
442+
Entry::new(dir_fd, path_stack, &entry_filename, None),
443443
Error::new(e, ErrorKind::Stat),
444444
);
445445
return ProcessFileResult::NotProcessed;
@@ -583,7 +583,7 @@ where
583583
Err(e) => {
584584
if let Some(path_stack) = &path_stack {
585585
err_reporter(
586-
Entry::new(&starting_dir, &path_stack, &filename, None),
586+
Entry::new(&starting_dir, path_stack, &filename, None),
587587
Error::new(e, ErrorKind::Open),
588588
);
589589
}

gettext-rs/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn textdomain<T: Into<Vec<u8>>>(domainname: T) -> Result<Vec<u8>, std::io::E
1818
}
1919

2020
pub fn gettext<T: Into<String>>(msgid: T) -> String {
21-
return msgid.into();
21+
msgid.into()
2222
}
2323

2424
#[macro_export]

m4/test-manager/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn update_snapshots(args: &Args, update: &UpdateSnapshots) {
6868
return false;
6969
}
7070

71-
if let Some(name) = update.test_case_name.as_ref().map(|s| s.as_str()) {
71+
if let Some(name) = update.test_case_name.as_deref() {
7272
if name != entry.path().file_stem().unwrap().to_str().unwrap() {
7373
return false;
7474
}

plib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ license = "MIT"
77
repository = "https://github.com/rustcoreutils/posixutils-rs.git"
88

99
[dependencies]
10+
cfg-if = "1.0"
1011
libc.workspace = true
1112

1213
[lib]

plib/src/io.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,21 @@ use std::path::PathBuf;
1313

1414
pub fn input_stream(pathname: &PathBuf, dashed_stdin: bool) -> io::Result<Box<dyn Read>> {
1515
// open file, or stdin
16-
let file: Box<dyn Read>;
1716
let path_str = pathname.as_os_str();
18-
if dashed_stdin && path_str == "-" {
19-
file = Box::new(io::stdin().lock());
20-
} else if !dashed_stdin && path_str == "" {
21-
file = Box::new(io::stdin().lock());
22-
} else {
23-
file = Box::new(fs::File::open(pathname)?);
24-
}
17+
18+
let file: Box<dyn Read> =
19+
if (dashed_stdin && path_str == "-") || (!dashed_stdin && path_str.is_empty()) {
20+
Box::new(io::stdin().lock())
21+
} else {
22+
Box::new(fs::File::open(pathname)?)
23+
};
2524

2625
Ok(file)
2726
}
2827

2928
pub fn input_stream_opt(pathname: &Option<PathBuf>) -> io::Result<Box<dyn Read>> {
3029
match pathname {
31-
Some(path) => input_stream(&path, false),
30+
Some(path) => input_stream(path, false),
3231
None => input_stream(&PathBuf::new(), false),
3332
}
3433
}

plib/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
pub mod curuser;
1111
pub mod group;
1212
pub mod io;
13-
// TODO: Remove "libc_aliases" when https://github.com/rust-lang/libc/issues/3190 is resolved
14-
pub mod libc_aliases;
1513
pub mod lzw;
1614
pub mod modestr;
15+
pub mod platform;
1716
pub mod sccsfile;
1817
pub mod testing;
1918
pub mod utmpx;

plib/src/libc_aliases.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

plib/src/libc_aliases/musl.rs

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)