style: fix rustfmt formatting for DNF/YUM backend
This commit is contained in:
@ -1173,7 +1173,6 @@ impl Default for ApkBackend {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// DNF package manager backend (Fedora/RHEL/CentOS 8+)
|
/// DNF package manager backend (Fedora/RHEL/CentOS 8+)
|
||||||
pub struct DnfBackend {
|
pub struct DnfBackend {
|
||||||
_marker: std::marker::PhantomData<()>,
|
_marker: std::marker::PhantomData<()>,
|
||||||
@ -1246,7 +1245,10 @@ impl DnfBackend {
|
|||||||
let without_arch = if let Some(pos) = trimmed.rfind('.') {
|
let without_arch = if let Some(pos) = trimmed.rfind('.') {
|
||||||
// Verify the suffix looks like an arch (only alphanumeric, no dots)
|
// Verify the suffix looks like an arch (only alphanumeric, no dots)
|
||||||
let suffix = &trimmed[pos + 1..];
|
let suffix = &trimmed[pos + 1..];
|
||||||
if suffix.chars().all(|c| c.is_ascii_alphanumeric() || c == '_') {
|
if suffix
|
||||||
|
.chars()
|
||||||
|
.all(|c| c.is_ascii_alphanumeric() || c == '_')
|
||||||
|
{
|
||||||
&trimmed[..pos]
|
&trimmed[..pos]
|
||||||
} else {
|
} else {
|
||||||
trimmed
|
trimmed
|
||||||
@ -1303,9 +1305,7 @@ impl DnfBackend {
|
|||||||
} else if line.starts_with("Release") {
|
} else if line.starts_with("Release") {
|
||||||
release = line.split(':').nth(1).unwrap_or("").trim().to_string();
|
release = line.split(':').nth(1).unwrap_or("").trim().to_string();
|
||||||
} else if line.starts_with("Install Date") {
|
} else if line.starts_with("Install Date") {
|
||||||
install_date = Some(
|
install_date = Some(line.split(':').nth(1).unwrap_or("").trim().to_string());
|
||||||
line.split(':').nth(1).unwrap_or("").trim().to_string(),
|
|
||||||
);
|
|
||||||
} else if line.starts_with("Size") {
|
} else if line.starts_with("Size") {
|
||||||
size_installed = Some(line.split(':').nth(1).unwrap_or("").trim().to_string());
|
size_installed = Some(line.split(':').nth(1).unwrap_or("").trim().to_string());
|
||||||
} else if line.starts_with("Summary") {
|
} else if line.starts_with("Summary") {
|
||||||
@ -1368,11 +1368,7 @@ impl DnfBackend {
|
|||||||
// RPM dependencies can be complex: "rpmlib(...) >= value"
|
// RPM dependencies can be complex: "rpmlib(...) >= value"
|
||||||
// or simple: "libc.so.6()(64bit)" or "bash >= 4.0"
|
// or simple: "libc.so.6()(64bit)" or "bash >= 4.0"
|
||||||
// Extract just the base name
|
// Extract just the base name
|
||||||
let dep_name = dep
|
let dep_name = dep.split_whitespace().next().unwrap_or("").to_string();
|
||||||
.split_whitespace()
|
|
||||||
.next()
|
|
||||||
.unwrap_or("")
|
|
||||||
.to_string();
|
|
||||||
// Skip rpmlib and capability-style deps
|
// Skip rpmlib and capability-style deps
|
||||||
if dep_name.starts_with("rpmlib") || dep_name.starts_with("rtld") {
|
if dep_name.starts_with("rpmlib") || dep_name.starts_with("rtld") {
|
||||||
continue;
|
continue;
|
||||||
@ -1425,9 +1421,7 @@ impl PackageManagerBackend for DnfBackend {
|
|||||||
|
|
||||||
if query_result.is_err() {
|
if query_result.is_err() {
|
||||||
// Package not installed, check if available via dnf
|
// Package not installed, check if available via dnf
|
||||||
let search_output = Command::new("dnf")
|
let search_output = Command::new("dnf").args(["info", "-q", name]).output();
|
||||||
.args(["info", "-q", name])
|
|
||||||
.output();
|
|
||||||
|
|
||||||
if let Ok(output) = search_output {
|
if let Ok(output) = search_output {
|
||||||
if output.status.success() {
|
if output.status.success() {
|
||||||
@ -1797,7 +1791,10 @@ impl YumBackend {
|
|||||||
|
|
||||||
let without_arch = if let Some(pos) = trimmed.rfind('.') {
|
let without_arch = if let Some(pos) = trimmed.rfind('.') {
|
||||||
let suffix = &trimmed[pos + 1..];
|
let suffix = &trimmed[pos + 1..];
|
||||||
if suffix.chars().all(|c| c.is_ascii_alphanumeric() || c == '_') {
|
if suffix
|
||||||
|
.chars()
|
||||||
|
.all(|c| c.is_ascii_alphanumeric() || c == '_')
|
||||||
|
{
|
||||||
&trimmed[..pos]
|
&trimmed[..pos]
|
||||||
} else {
|
} else {
|
||||||
trimmed
|
trimmed
|
||||||
@ -1853,9 +1850,7 @@ impl YumBackend {
|
|||||||
} else if line.starts_with("Release") {
|
} else if line.starts_with("Release") {
|
||||||
release = line.split(':').nth(1).unwrap_or("").trim().to_string();
|
release = line.split(':').nth(1).unwrap_or("").trim().to_string();
|
||||||
} else if line.starts_with("Install Date") {
|
} else if line.starts_with("Install Date") {
|
||||||
install_date = Some(
|
install_date = Some(line.split(':').nth(1).unwrap_or("").trim().to_string());
|
||||||
line.split(':').nth(1).unwrap_or("").trim().to_string(),
|
|
||||||
);
|
|
||||||
} else if line.starts_with("Size") {
|
} else if line.starts_with("Size") {
|
||||||
size_installed = Some(line.split(':').nth(1).unwrap_or("").trim().to_string());
|
size_installed = Some(line.split(':').nth(1).unwrap_or("").trim().to_string());
|
||||||
} else if line.starts_with("Summary") {
|
} else if line.starts_with("Summary") {
|
||||||
@ -1911,11 +1906,7 @@ impl YumBackend {
|
|||||||
if dep.is_empty() {
|
if dep.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let dep_name = dep
|
let dep_name = dep.split_whitespace().next().unwrap_or("").to_string();
|
||||||
.split_whitespace()
|
|
||||||
.next()
|
|
||||||
.unwrap_or("")
|
|
||||||
.to_string();
|
|
||||||
if dep_name.starts_with("rpmlib") || dep_name.starts_with("rtld") {
|
if dep_name.starts_with("rpmlib") || dep_name.starts_with("rtld") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1966,9 +1957,7 @@ impl PackageManagerBackend for YumBackend {
|
|||||||
|
|
||||||
if query_result.is_err() {
|
if query_result.is_err() {
|
||||||
// Package not installed, check if available via yum
|
// Package not installed, check if available via yum
|
||||||
let search_output = Command::new("yum")
|
let search_output = Command::new("yum").args(["info", "-q", name]).output();
|
||||||
.args(["info", "-q", name])
|
|
||||||
.output();
|
|
||||||
|
|
||||||
if let Ok(output) = search_output {
|
if let Ok(output) = search_output {
|
||||||
if output.status.success() {
|
if output.status.success() {
|
||||||
@ -2383,7 +2372,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_dnf_parse_rpm_package_list() {
|
fn test_dnf_parse_rpm_package_list() {
|
||||||
let backend = DnfBackend::new();
|
let backend = DnfBackend::new();
|
||||||
let output = "bash-5.2.21-1.fc43.x86_64\nopenssl-3.1.4-1.fc43.x86_64\ncurl-8.6.0-1.fc43.noarch";
|
let output =
|
||||||
|
"bash-5.2.21-1.fc43.x86_64\nopenssl-3.1.4-1.fc43.x86_64\ncurl-8.6.0-1.fc43.noarch";
|
||||||
let packages = backend.parse_rpm_package_list(output);
|
let packages = backend.parse_rpm_package_list(output);
|
||||||
assert_eq!(packages.len(), 3);
|
assert_eq!(packages.len(), 3);
|
||||||
assert_eq!(packages[0].name, "bash");
|
assert_eq!(packages[0].name, "bash");
|
||||||
|
|||||||
Reference in New Issue
Block a user