Исправлены clippy-замечания под gate -D warnings

This commit is contained in:
2026-05-12 12:19:47 +05:00
parent d114784d7d
commit bff9c50a6b
6 changed files with 43 additions and 39 deletions
+6 -6
View File
@@ -150,12 +150,12 @@ fn docker_events_loop(cfg: &Config, state: &Arc<Mutex<LastActionState>>) -> anyh
fn wait_for_interface(cfg: &Config, container_name: &str, timeout_secs: u64) -> bool {
let start = Instant::now();
while start.elapsed() < Duration::from_secs(timeout_secs.max(1)) {
if let Ok(target) = docker::discover_target(cfg) {
if target.container_name == container_name {
let transport = build_transport(target.container_pid, &target.container_name);
if iface::detect_interface_with_transport(cfg, transport.as_ref()).is_ok() {
return true;
}
if let Ok(target) = docker::discover_target(cfg)
&& target.container_name == container_name
{
let transport = build_transport(target.container_pid, &target.container_name);
if iface::detect_interface_with_transport(cfg, transport.as_ref()).is_ok() {
return true;
}
}
+6 -4
View File
@@ -532,9 +532,10 @@ pub fn antitorrent_drop_counter(cfg: &Config) -> anyhow::Result<Option<(u64, u64
match json {
Ok(raw) => {
if let Some(v) = parse_counter_json(&raw)? {
return Ok(Some(v));
Ok(Some(v))
} else {
Ok(None)
}
return Ok(None);
}
Err(e) => {
let msg = e.to_string();
@@ -543,9 +544,10 @@ pub fn antitorrent_drop_counter(cfg: &Config) -> anyhow::Result<Option<(u64, u64
|| msg.contains("not found")
|| msg.contains("not exist")
{
return Ok(None);
Ok(None)
} else {
Err(anyhow::anyhow!("nft counter inspection failed: {e}"))
}
return Err(anyhow::anyhow!("nft counter inspection failed: {e}"));
}
}
}
+8 -6
View File
@@ -11,6 +11,7 @@ pub struct FileLock {
}
impl FileLock {
#[cfg(test)]
pub fn acquire(path: &str) -> anyhow::Result<Self> {
Self::acquire_timeout(path, Duration::from_secs(0))
}
@@ -42,9 +43,9 @@ impl FileLock {
match OpenOptions::new().create_new(true).write(true).open(p) {
Ok(mut file) => {
file.write_all(std::process::id().to_string().as_bytes())?;
return Ok(Self {
Ok(Self {
path: path.to_string(),
});
})
}
Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => {
let stale = is_stale_lock(p)?;
@@ -52,13 +53,14 @@ impl FileLock {
let _ = fs::remove_file(p);
let mut file = OpenOptions::new().create_new(true).write(true).open(p)?;
file.write_all(std::process::id().to_string().as_bytes())?;
return Ok(Self {
Ok(Self {
path: path.to_string(),
});
})
} else {
anyhow::bail!("lock already exists: {path}");
}
anyhow::bail!("lock already exists: {path}");
}
Err(e) => return Err(e.into()),
Err(e) => Err(e.into()),
}
}
}
+13 -10
View File
@@ -56,7 +56,9 @@ pub fn print_status(cfg: &Config) -> anyhow::Result<()> {
}
println!("WireGuard clients:");
println!(" IP State Latest handshake RX TX Endpoint");
println!(
" IP State Latest handshake RX TX Public key Endpoint"
);
match wg::discover_peer_runtime(
target.container_pid,
&target.container_name,
@@ -87,13 +89,13 @@ pub fn print_status(cfg: &Config) -> anyhow::Result<()> {
let tx = format_bytes(rp.transfer_tx_bytes.unwrap_or(0));
let ep = rp.endpoint.clone().unwrap_or_else(|| "-".to_string());
println!(
" {:<11} {:<8} {:<19} {:<9} {:<9} {}",
ip, state, hs, rx, tx, ep
" {:<11} {:<8} {:<19} {:<9} {:<9} {:<44} {}",
ip, state, hs, rx, tx, rp.public_key, ep
);
} else {
println!(
" {:<11} {:<8} {:<19} {:<9} {:<9} -",
ip, "offline", "never", "0B", "0B"
" {:<11} {:<8} {:<19} {:<9} {:<9} {:<44} -",
ip, "offline", "never", "0B", "0B", "-"
);
}
}
@@ -427,6 +429,7 @@ fn print_swap_status(cfg: &Config) {
" fstab_exclusive: {}",
if s.fstab_exclusive { "yes" } else { "no" }
);
println!(" fstab_swap_entries: {}", s.fstab_swap_entries.len());
println!(
" swappiness_current: {}",
s.current_swappiness
@@ -556,11 +559,11 @@ fn parse_tc_filter_hits(raw: &str) -> BTreeMap<String, u64> {
let hits = parse_sent_packets(t).unwrap_or(0);
out.insert(ip, hits);
}
} else if t.contains(" success ") || t.starts_with("success ") {
if let Some(ip) = current_ip.clone() {
let hits = parse_success_packets(t).unwrap_or(0);
out.insert(ip, hits);
}
} else if (t.contains(" success ") || t.starts_with("success "))
&& let Some(ip) = current_ip.clone()
{
let hits = parse_success_packets(t).unwrap_or(0);
out.insert(ip, hits);
}
}
out
+1 -2
View File
@@ -69,8 +69,7 @@ pub fn inspect_swap(cfg: &Config) -> anyhow::Result<SwapStatus> {
let fstab_swap_entries = read_fstab_swap_entries("/etc/fstab")?;
let expected_line = render_fstab_line(&desired_path, cfg.swap.priority);
let fstab_exclusive = fstab_swap_entries.len() == 1
&& normalize_ws(&fstab_swap_entries[0])
== normalize_ws(&expected_line.trim_end().to_string());
&& normalize_ws(&fstab_swap_entries[0]) == normalize_ws(expected_line.trim_end());
let current_swappiness = read_current_swappiness().ok();
let persisted_swappiness = read_persisted_swappiness()?;
+9 -11
View File
@@ -90,10 +90,10 @@ fn parse_allowed_ips(raw: &str, peer_cidr: &str) -> anyhow::Result<Vec<Peer>> {
if pfx != "32" {
continue;
}
if let Ok(v4) = ip.parse::<Ipv4Addr>() {
if config::ip_in_cidr(v4, peer_cidr)? {
out.push(Peer { ipv4: v4 });
}
if let Ok(v4) = ip.parse::<Ipv4Addr>()
&& config::ip_in_cidr(v4, peer_cidr)?
{
out.push(Peer { ipv4: v4 });
}
}
}
@@ -115,10 +115,10 @@ fn parse_fallback_wg_show(raw: &str, peer_cidr: &str) -> anyhow::Result<Vec<Peer
if pfx != "32" {
continue;
}
if let Ok(v4) = ip.parse::<Ipv4Addr>() {
if config::ip_in_cidr(v4, peer_cidr)? {
out.push(Peer { ipv4: v4 });
}
if let Ok(v4) = ip.parse::<Ipv4Addr>()
&& config::ip_in_cidr(v4, peer_cidr)?
{
out.push(Peer { ipv4: v4 });
}
}
}
@@ -308,9 +308,7 @@ mod tests {
"wg show all dump",
Err(anyhow::anyhow!("wg broken")),
)]);
let err = discover_peer_runtime_with_transport(&transport, "10.8.1.0/24")
.err()
.expect("err");
let err = discover_peer_runtime_with_transport(&transport, "10.8.1.0/24").expect_err("err");
assert!(err.to_string().contains("wg show all dump failed"));
}
}