refactor: apply clippy auto-fixes (162 warnings resolved)
- Fix needless borrows and references - Collapse nested if statements - Replace manual strip_prefix with str::strip_prefix() - Remove redundant closures in map/unwrap_or_else - Use Iterator::next_back() instead of rev().next() - Simplify map_or patterns - Use std::io::Error::other() instead of new(ErrorKind::Other, ..) - Use div_ceil() instead of manual ceiling division - Consolidate format! string arguments - Various other idiomatic Rust improvements 39 files changed, 220 insertions(+), 320 deletions(-)
This commit is contained in:
@@ -80,7 +80,7 @@ pub struct UploadSession {
|
||||
impl UploadSession {
|
||||
/// Calculate number of chunks needed
|
||||
pub fn calculate_chunk_count(total_size: u64, chunk_size: usize) -> usize {
|
||||
((total_size as usize + chunk_size - 1) / chunk_size).max(1)
|
||||
(total_size as usize).div_ceil(chunk_size).max(1)
|
||||
}
|
||||
|
||||
/// Get upload progress (0.0 - 1.0)
|
||||
@@ -212,14 +212,12 @@ impl ChunkedUploadService {
|
||||
let sessions = sessions.read().await;
|
||||
if !sessions.contains_key(dir_name) {
|
||||
// Check if directory is old (>24h)
|
||||
if let Ok(metadata) = fs::metadata(&path).await {
|
||||
if let Ok(modified) = metadata.modified() {
|
||||
if modified.elapsed().unwrap_or_default() > SESSION_EXPIRATION {
|
||||
if let Ok(metadata) = fs::metadata(&path).await
|
||||
&& let Ok(modified) = metadata.modified()
|
||||
&& modified.elapsed().unwrap_or_default() > SESSION_EXPIRATION {
|
||||
let _ = fs::remove_dir_all(&path).await;
|
||||
tracing::info!("🧹 Cleaned orphaned upload dir: {:?}", path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -283,7 +281,7 @@ impl ChunkedUploadService {
|
||||
bytes_received: 0,
|
||||
};
|
||||
|
||||
let expires_at = (SESSION_EXPIRATION.as_secs()) as u64;
|
||||
let expires_at = SESSION_EXPIRATION.as_secs();
|
||||
|
||||
{
|
||||
let mut sessions = self.sessions.write().await;
|
||||
|
||||
@@ -159,7 +159,7 @@ impl CompressionService for GzipCompressionService {
|
||||
Ok(compressed)
|
||||
}).await.unwrap_or_else(|e| {
|
||||
error!("Compression task error: {}", e);
|
||||
Err(io::Error::new(io::ErrorKind::Other, e.to_string()))
|
||||
Err(io::Error::other(e.to_string()))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ impl CompressionService for GzipCompressionService {
|
||||
Ok(decompressed)
|
||||
}).await.unwrap_or_else(|e| {
|
||||
error!("Decompression task error: {}", e);
|
||||
Err(io::Error::new(io::ErrorKind::Other, e.to_string()))
|
||||
Err(io::Error::other(e.to_string()))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -622,14 +622,13 @@ impl DedupService {
|
||||
}
|
||||
|
||||
// Check size
|
||||
if let Ok(file_meta) = fs::metadata(&blob_path).await {
|
||||
if file_meta.len() != metadata.size {
|
||||
if let Ok(file_meta) = fs::metadata(&blob_path).await
|
||||
&& file_meta.len() != metadata.size {
|
||||
corrupted.push(format!(
|
||||
"{}: size mismatch (expected: {}, actual: {})",
|
||||
hash, metadata.size, file_meta.len()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if corrupted.is_empty() {
|
||||
|
||||
@@ -51,13 +51,11 @@ impl FileSystemI18nService {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(last_part) = parts.last() {
|
||||
if let Some(value) = current.get(last_part) {
|
||||
if value.is_string() {
|
||||
if let Some(last_part) = parts.last()
|
||||
&& let Some(value) = current.get(last_part)
|
||||
&& value.is_string() {
|
||||
return value.as_str().map(|s| s.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
@@ -75,13 +73,11 @@ impl I18nService for FileSystemI18nService {
|
||||
}
|
||||
|
||||
// Try to use English as fallback if we couldn't find the key
|
||||
if locale != Locale::English {
|
||||
if let Some(english_translations) = cache.get(&Locale::English) {
|
||||
if let Some(value) = self.get_nested_value(english_translations, key) {
|
||||
if locale != Locale::English
|
||||
&& let Some(english_translations) = cache.get(&Locale::English)
|
||||
&& let Some(value) = self.get_nested_value(english_translations, key) {
|
||||
return Ok(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Err(I18nError::KeyNotFound(key.to_string()));
|
||||
}
|
||||
@@ -98,13 +94,11 @@ impl I18nService for FileSystemI18nService {
|
||||
}
|
||||
|
||||
// Try to use English as fallback
|
||||
if locale != Locale::English {
|
||||
if let Some(english_translations) = cache.get(&Locale::English) {
|
||||
if let Some(value) = self.get_nested_value(english_translations, key) {
|
||||
if locale != Locale::English
|
||||
&& let Some(english_translations) = cache.get(&Locale::English)
|
||||
&& let Some(value) = self.get_nested_value(english_translations, key) {
|
||||
return Ok(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,7 @@ impl FileSystemUtils {
|
||||
Ok(file) => file,
|
||||
Err(e) => {
|
||||
error!("Failed to create temporary file in {}: {}", dir.display(), e);
|
||||
return Err(IoError::new(std::io::ErrorKind::Other,
|
||||
format!("Failed to create temporary file: {}", e)));
|
||||
return Err(IoError::other(format!("Failed to create temporary file: {}", e)));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ pub struct OptimizerStats {
|
||||
}
|
||||
|
||||
/// Queue for batch operations
|
||||
#[derive(Default)]
|
||||
struct BatchQueue {
|
||||
/// Pending paths to get/create ID
|
||||
path_to_id_requests: HashSet<String>,
|
||||
@@ -67,14 +68,6 @@ struct BatchQueue {
|
||||
id_to_path_requests: HashSet<String>,
|
||||
}
|
||||
|
||||
impl Default for BatchQueue {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
path_to_id_requests: HashSet::new(),
|
||||
id_to_path_requests: HashSet::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Result of a batch operation
|
||||
struct BatchResult {
|
||||
|
||||
@@ -173,13 +173,11 @@ impl IdMappingService {
|
||||
};
|
||||
|
||||
// Ensure directory exists
|
||||
if let Some(parent) = map_path.parent() {
|
||||
if !parent.exists() {
|
||||
if let Err(e) = fs::create_dir_all(parent).await {
|
||||
if let Some(parent) = map_path.parent()
|
||||
&& !parent.exists()
|
||||
&& let Err(e) = fs::create_dir_all(parent).await {
|
||||
tracing::error!("Failed to create directory for ID map: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Write empty map to file (best-effort: the in-memory map is valid even if disk write fails)
|
||||
match serde_json::to_string_pretty(&empty_map) {
|
||||
@@ -413,8 +411,7 @@ impl IdMappingService {
|
||||
// Try a second save if verification fails
|
||||
if let Err(retry_err) = self.save_id_map().await {
|
||||
tracing::error!("Second save attempt also failed: {}", retry_err);
|
||||
return Err(IdMappingError::IoError(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
return Err(IdMappingError::IoError(std::io::Error::other(
|
||||
format!("Failed to verify and retry save: {}", retry_err)
|
||||
)));
|
||||
}
|
||||
@@ -435,8 +432,7 @@ impl IdMappingService {
|
||||
},
|
||||
Err(retry_e) => {
|
||||
tracing::error!("Second save attempt also failed: {}", retry_e);
|
||||
Err(IdMappingError::IoError(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
Err(IdMappingError::IoError(std::io::Error::other(
|
||||
format!("Failed to save ID mappings after retry: {}", retry_e)
|
||||
)))
|
||||
}
|
||||
|
||||
@@ -200,11 +200,7 @@ impl ImageTranscodeService {
|
||||
// Calculate savings
|
||||
let original_size = original_content.len();
|
||||
let transcoded_size = transcoded_bytes.len();
|
||||
let saved = if transcoded_size < original_size {
|
||||
original_size - transcoded_size
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let saved = original_size.saturating_sub(transcoded_size);
|
||||
|
||||
// Only use transcoded if it's actually smaller
|
||||
if transcoded_size >= original_size {
|
||||
|
||||
@@ -65,7 +65,7 @@ impl PathService {
|
||||
|
||||
/// Checks if a path is at the root
|
||||
pub fn is_in_root(&self, path: &StoragePath) -> bool {
|
||||
path.parent().map_or(true, |p| p.is_empty())
|
||||
path.parent().is_none_or(|p| p.is_empty())
|
||||
}
|
||||
|
||||
/// Gets the root path used by this service
|
||||
|
||||
@@ -256,13 +256,12 @@ impl WriteBehindCache {
|
||||
pending.get(&file_id).cloned()
|
||||
};
|
||||
|
||||
if let Some(entry) = entry {
|
||||
if let Err(e) = self.flush_single(&file_id, &entry).await {
|
||||
if let Some(entry) = entry
|
||||
&& let Err(e) = self.flush_single(&file_id, &entry).await {
|
||||
tracing::error!("Failed to flush {}: {}", file_id, e);
|
||||
// Keep in cache for retry
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
FlushCommand::FlushAll => {
|
||||
let entries: Vec<_> = {
|
||||
|
||||
Reference in New Issue
Block a user