mirror of
https://github.com/containers/bootc.git
synced 2026-02-05 15:45:53 +01:00
crates/sysusers: Fix various clippy lints
Signed-off-by: Colin Walters <walters@verbum.org>
This commit is contained in:
@@ -61,7 +61,7 @@ impl FromStr for GroupReference {
|
||||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
||||
let r = if s.starts_with('/') {
|
||||
Self::Path(s.to_owned())
|
||||
} else if s.chars().all(|c| matches!(c, '0'..='9')) {
|
||||
} else if s.chars().all(|c| c.is_ascii_digit()) {
|
||||
Self::Numeric(u32::from_str(s)?)
|
||||
} else {
|
||||
Self::Name(s.to_owned())
|
||||
@@ -129,15 +129,11 @@ impl SysusersEntry {
|
||||
let s = s.trim_start();
|
||||
let (first, rest) = match s.strip_prefix('"') {
|
||||
None => {
|
||||
let idx = s
|
||||
.find(|c: char| c.is_whitespace())
|
||||
.unwrap_or(s.as_bytes().len());
|
||||
let idx = s.find(|c: char| c.is_whitespace()).unwrap_or(s.len());
|
||||
s.split_at(idx)
|
||||
}
|
||||
Some(rest) => {
|
||||
let Some(end) = rest.find(|c: char| c == '"') else {
|
||||
return None;
|
||||
};
|
||||
let end = rest.find('"')?;
|
||||
(&rest[..end], &rest[end + 1..])
|
||||
}
|
||||
};
|
||||
@@ -164,10 +160,10 @@ impl SysusersEntry {
|
||||
|
||||
pub(crate) fn parse(s: &str) -> Result<Option<SysusersEntry>> {
|
||||
let err = || Error::ParseFailure(s.to_owned());
|
||||
let (ftype, s) = Self::next_token(s).ok_or_else(err.clone())?;
|
||||
let (ftype, s) = Self::next_token(s).ok_or_else(err)?;
|
||||
let r = match ftype {
|
||||
"u" | "u!" => {
|
||||
let (name, s) = Self::next_token_owned(s).ok_or_else(err.clone())?;
|
||||
let (name, s) = Self::next_token_owned(s).ok_or_else(err)?;
|
||||
let (id, s) = Self::next_optional_token(s).unwrap_or_default();
|
||||
let (uid, pgid) = id
|
||||
.and_then(|v| v.split_once(':'))
|
||||
@@ -194,15 +190,15 @@ impl SysusersEntry {
|
||||
}
|
||||
}
|
||||
"g" => {
|
||||
let (name, s) = Self::next_token_owned(s).ok_or_else(err.clone())?;
|
||||
let (name, s) = Self::next_token_owned(s).ok_or_else(err)?;
|
||||
let (id, _) = Self::next_optional_token(s).unwrap_or_default();
|
||||
let id = id.map(|id| id.parse()).transpose().map_err(|_| err())?;
|
||||
SysusersEntry::Group { name, id }
|
||||
}
|
||||
"r" => {
|
||||
let (_, s) = Self::next_optional_token(s).ok_or_else(err.clone())?;
|
||||
let (range, _) = Self::next_token(s).ok_or_else(err.clone())?;
|
||||
let (start, end) = range.split_once('-').ok_or_else(err.clone())?;
|
||||
let (_, s) = Self::next_optional_token(s).ok_or_else(err)?;
|
||||
let (range, _) = Self::next_token(s).ok_or_else(err)?;
|
||||
let (start, end) = range.split_once('-').ok_or_else(err)?;
|
||||
let start: u32 = start.parse().map_err(|_| err())?;
|
||||
let end: u32 = end.parse().map_err(|_| err())?;
|
||||
SysusersEntry::Range { start, end }
|
||||
|
||||
@@ -49,7 +49,7 @@ pub(crate) fn parse_group_content(content: impl BufRead) -> Result<Vec<GroupEntr
|
||||
let mut groups = vec![];
|
||||
for (line_num, line) in content.lines().enumerate() {
|
||||
let input =
|
||||
line.with_context(|| format!("failed to read group entry at line {}", line_num))?;
|
||||
line.with_context(|| format!("failed to read group entry at line {line_num}"))?;
|
||||
|
||||
// Skip empty and comment lines
|
||||
if input.is_empty() || input.starts_with('#') {
|
||||
|
||||
@@ -54,7 +54,7 @@ pub(crate) fn parse_passwd_content(content: impl BufRead) -> Result<Vec<PasswdEn
|
||||
let mut passwds = vec![];
|
||||
for (line_num, line) in content.lines().enumerate() {
|
||||
let input =
|
||||
line.with_context(|| format!("failed to read passwd entry at line {}", line_num))?;
|
||||
line.with_context(|| format!("failed to read passwd entry at line {line_num}"))?;
|
||||
|
||||
// Skip empty and comment lines
|
||||
if input.is_empty() || input.starts_with('#') {
|
||||
|
||||
@@ -40,7 +40,7 @@ fn u32_or_none(value: &str) -> Result<Option<u32>, std::num::ParseIntError> {
|
||||
|
||||
fn number_or_empty(value: Option<u32>) -> String {
|
||||
if let Some(number) = value {
|
||||
format!("{}", number)
|
||||
format!("{number}")
|
||||
} else {
|
||||
"".to_string()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user