Apply clippy fixes for code quality

Clippy Fixes Applied:
- Removed unused imports
- Fixed manual implementation of .is_multiple_of()
- Fixed unnecessary_sort_by suggestions
- Added missing Ipv4Addr imports

Files Modified:
- forward_acl.rs: Add Ipv4Addr import
- known_hosts.rs: Add Ipv4Addr import
- Various files: Remove unused imports

Build: ✅ markbase-core
Tests: 495 passed
This commit is contained in:
Warren
2026-06-24 11:18:02 +08:00
parent 85218333d9
commit 1418e9958b
22 changed files with 61 additions and 67 deletions
+1 -2
View File
@@ -3,10 +3,9 @@
//! Compatible with ZFS send/receive and Proxmox Backup Server format
use std::path::PathBuf;
use std::time::SystemTime;
use serde::{Serialize, Deserialize};
use sha2::{Sha256, Digest};
use sha2::Digest;
use super::{VfsCompression};
use super::checksum::VfsChecksumFile;
+1 -1
View File
@@ -269,7 +269,7 @@ impl BackupScheduler {
let final_data = if self.config.compress != super::VfsCompression::None {
let compressor = Compressor::new(VfsCompressionConfig {
algorithm: self.config.compress.clone(),
algorithm: self.config.compress,
min_size: 1024,
level: 3,
});
+8 -9
View File
@@ -6,14 +6,13 @@
//!
//! MarkBase uses SHA-256 (32 bytes) per 4KB block for integrity verification.
use std::collections::{HashMap, HashSet};
use std::path::PathBuf;
use std::io::{Read, Write, Seek, SeekFrom};
use std::io::{Read, Write};
use sha2::{Sha256, Digest};
use serde::{Serialize, Deserialize};
use super::{VfsBackend, VfsFile, VfsError, VfsStat};
use super::{VfsBackend, VfsFile, VfsError};
pub const BLOCK_SIZE: usize = 4096;
pub const HASH_SIZE: usize = 32; // SHA-256
@@ -71,7 +70,7 @@ impl VfsChecksumFile {
pub fn block_count(&self) -> usize {
(self.file_size as usize / BLOCK_SIZE) +
if self.file_size as usize % BLOCK_SIZE > 0 { 1 } else { 0 }
if !(self.file_size as usize).is_multiple_of(BLOCK_SIZE) { 1 } else { 0 }
}
}
@@ -214,7 +213,7 @@ pub fn scrub_file(
corrupted_blocks.push(offset);
if repair {
if let Ok(_) = repair_block(backend, file_path, offset, &buffer) {
if repair_block(backend, file_path, offset, &buffer).is_ok() {
repaired_blocks.push(offset);
}
}
@@ -283,10 +282,10 @@ fn scrub_recursive(
///
/// Tries RAID repair first (if backend is RAID), then Dedup repair.
pub fn repair_block(
backend: &dyn VfsBackend,
file_path: &PathBuf,
offset: u64,
expected_checksum: &[u8],
_backend: &dyn VfsBackend,
_file_path: &PathBuf,
_offset: u64,
_expected_checksum: &[u8],
) -> Result<Vec<u8>, VfsError> {
// Try Dedup repair first (check if block exists in dedup store)
// This requires the backend to have dedup integration
+1 -1
View File
@@ -16,7 +16,7 @@ use super::checksum::{
BLOCK_SIZE, compute_block_hash, verify_block_hash,
checksum_path_for_file, ensure_checksum_dir,
};
use sha2::{Sha256, Digest};
use sha2::Digest;
pub struct ChecksumFile {
inner: Box<dyn VfsFile>,
+4 -5
View File
@@ -16,8 +16,7 @@ use aes_gcm::{
};
use sha2::{Sha256, Digest};
use super::{VfsBackend, VfsFile, VfsStat, VfsError, VfsDirEntry};
use super::open_flags::OpenFlags;
use super::{VfsBackend, VfsFile, VfsStat, VfsError};
use super::local_fs::LocalFs;
const ENCRYPTED_MAGIC: &[u8] = b"MBE1"; // MarkBase Encrypted v1
@@ -62,7 +61,7 @@ impl EncryptedVfs {
Self { inner, config }
}
pub fn wrap_local_fs(root: PathBuf, config: EncryptedVfsConfig) -> Self {
pub fn wrap_local_fs(_root: PathBuf, config: EncryptedVfsConfig) -> Self {
Self::new(Box::new(LocalFs::new()), config)
}
@@ -132,8 +131,8 @@ fn rand_key(len: usize) -> Vec<u8> {
use std::time::{SystemTime, UNIX_EPOCH};
let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_nanos();
let mut hasher = Sha256::new();
hasher.update(&now.to_le_bytes());
hasher.update(&[0u8; 32]);
hasher.update(now.to_le_bytes());
hasher.update([0u8; 32]);
let hash = hasher.finalize();
hash[..len].to_vec()
}
+1 -1
View File
@@ -596,7 +596,7 @@ impl VfsBackend for LocalFs {
fn get_xattr(&self, path: &Path, name: &str) -> Result<Vec<u8>, VfsError> {
#[cfg(unix)]
{
use std::os::unix::fs::MetadataExt;
let _meta = path.metadata().map_err(|e| util::map_io_error(path, e))?;
xattr::get(path, name)
.map_err(|e| VfsError::Io(e.to_string()))?
+5 -5
View File
@@ -48,7 +48,7 @@ impl VfsRaidBackend {
}
pub fn level(&self) -> VfsRaidLevel {
self.config.level.clone()
self.config.level
}
pub fn backends(&self) -> &[Box<dyn VfsBackend>] {
@@ -213,7 +213,7 @@ impl VfsRaidBackend {
match self.config.level {
VfsRaidLevel::RaidZ1 => {
if parity_blocks.len() < 1 {
if parity_blocks.is_empty() {
return Err(VfsError::Io("Not enough parity for RaidZ1 repair".to_string()));
}
let reconstructed = Self::reconstruct_from_p(
@@ -284,7 +284,7 @@ impl VfsRaidBackend {
fn reconstruct_from_pq(
data_blocks: &[Option<Vec<u8>>],
p_block: &[u8],
q_block: &[u8],
_q_block: &[u8],
missing_index: usize,
data_disk_count: usize,
) -> Vec<u8> {
@@ -294,8 +294,8 @@ impl VfsRaidBackend {
fn reconstruct_from_pqr(
data_blocks: &[Option<Vec<u8>>],
p_block: &[u8],
q_block: &[u8],
r_block: &[u8],
_q_block: &[u8],
_r_block: &[u8],
missing_index: usize,
data_disk_count: usize,
) -> Vec<u8> {
+1 -2
View File
@@ -5,7 +5,6 @@
use std::sync::Arc;
use std::path::PathBuf;
use std::time::Duration;
use super::{VfsBackend, VfsError};
use super::checksum::{scrub_all, ScrubResult};
@@ -180,7 +179,7 @@ impl ScrubStats {
}
fn format_timestamp(secs: u64) -> String {
use chrono::{DateTime, Utc, TimeZone};
use chrono::{Utc, TimeZone};
Utc.timestamp_opt(secs as i64, 0)
.single()
.map(|dt| dt.format("%Y-%m-%d %H:%M:%S UTC").to_string())
+2 -3
View File
@@ -8,8 +8,7 @@ use std::collections::HashSet;
use super::{VfsBackend, VfsError, VfsCompression};
use super::backup_manifest::{BackupManifest, BackupStream, SendFormat, MANIFEST_FILE};
use super::checksum::{VfsChecksumFile, create_checksums_for_file, scrub_file};
use super::dedup::{DedupStore, DedupManifest};
use super::checksum::{VfsChecksumFile, scrub_file};
pub struct SendOptions {
pub format: SendFormat,
@@ -107,7 +106,7 @@ pub fn receive_snapshot(
restore_snapshot_data(backend, &stream.data, &snapshot_dir)?;
stream.manifest.save(&snapshot_dir).map_err(|e| VfsError::Io(e))?;
stream.manifest.save(&snapshot_dir).map_err(VfsError::Io)?;
if options.verify_checksums {
verify_snapshot_checksums(backend, &snapshot_dir, root)?;
+1 -1
View File
@@ -4,7 +4,7 @@
use std::path::PathBuf;
use super::{VfsBackend, VfsError, VfsStat, VfsCompression, VfsRaidLevel};
use super::{VfsBackend, VfsError, VfsCompression, VfsRaidLevel};
use super::dedup::DedupStats;
use super::raid::VfsRaidBackend;