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:
@@ -83,11 +83,10 @@ impl FileFsReadRepository {
|
||||
|
||||
async fn get_file_metadata_raw(&self, abs_path: &PathBuf) -> FileRepositoryResult<(u64, u64, u64)> {
|
||||
// Cache first
|
||||
if let Some(cached) = self.metadata_cache.get_metadata(abs_path).await {
|
||||
if let (Some(s), Some(c), Some(m)) = (cached.size, cached.created_at, cached.modified_at) {
|
||||
if let Some(cached) = self.metadata_cache.get_metadata(abs_path).await
|
||||
&& let (Some(s), Some(c), Some(m)) = (cached.size, cached.created_at, cached.modified_at) {
|
||||
return Ok((s, c, m));
|
||||
}
|
||||
}
|
||||
let metadata = time::timeout(self.config.timeouts.file_timeout(), fs::metadata(abs_path))
|
||||
.await
|
||||
.map_err(|_| FileRepositoryError::StorageError(format!("Timeout metadata: {}", abs_path.display())))?
|
||||
|
||||
@@ -101,11 +101,10 @@ impl FileFsWriteRepository {
|
||||
}
|
||||
|
||||
async fn get_file_metadata_raw(&self, abs_path: &PathBuf) -> FileRepositoryResult<(u64, u64, u64)> {
|
||||
if let Some(cached) = self.metadata_cache.get_metadata(abs_path).await {
|
||||
if let (Some(s), Some(c), Some(m)) = (cached.size, cached.created_at, cached.modified_at) {
|
||||
if let Some(cached) = self.metadata_cache.get_metadata(abs_path).await
|
||||
&& let (Some(s), Some(c), Some(m)) = (cached.size, cached.created_at, cached.modified_at) {
|
||||
return Ok((s, c, m));
|
||||
}
|
||||
}
|
||||
let meta = time::timeout(self.config.timeouts.file_timeout(), fs::metadata(abs_path))
|
||||
.await
|
||||
.map_err(|_| FileRepositoryError::StorageError(format!("Timeout: {}", abs_path.display())))?
|
||||
@@ -177,11 +176,10 @@ impl FileFsWriteRepository {
|
||||
for attempt in 1..=3 {
|
||||
match self.id_mapping_service.save_changes().await {
|
||||
Ok(_) => {
|
||||
if let Ok(verified) = self.id_mapping_service.get_path_by_id(id).await {
|
||||
if verified.to_string() == expected_path {
|
||||
if let Ok(verified) = self.id_mapping_service.get_path_by_id(id).await
|
||||
&& verified.to_string() == expected_path {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
if attempt == 3 {
|
||||
return Err(FileRepositoryError::Other("Failed to verify ID mapping after 3 attempts".into()));
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ impl FolderFsRepository {
|
||||
|
||||
/// Updates a folder path in the ID mapping service
|
||||
pub async fn update_mapped_folder_path(&self, folder_id: &str, new_path: &PathBuf) -> FolderRepositoryResult<()> {
|
||||
let storage_path = StoragePath::from_string(&new_path.to_string_lossy().to_string());
|
||||
let storage_path = StoragePath::from_string(new_path.to_string_lossy().as_ref());
|
||||
self.id_mapping_service.update_path(folder_id, &storage_path).await
|
||||
.map_err(|e| FolderRepositoryError::StorageError(format!("Failed to update folder path: {}", e)))
|
||||
}
|
||||
@@ -338,10 +338,7 @@ impl FolderRepository for FolderFsRepository {
|
||||
let parent_id: Option<String> = if parent.is_none() || parent.as_ref().unwrap().is_empty() {
|
||||
None
|
||||
} else {
|
||||
match self.id_mapping_service.get_or_create_id(parent.as_ref().unwrap()).await {
|
||||
Ok(pid) => Some(pid),
|
||||
Err(_) => None,
|
||||
}
|
||||
self.id_mapping_service.get_or_create_id(parent.as_ref().unwrap()).await.ok()
|
||||
};
|
||||
|
||||
// Create folder entity
|
||||
@@ -377,10 +374,7 @@ impl FolderRepository for FolderFsRepository {
|
||||
let parent_id: Option<String> = if parent.is_none() || parent.as_ref().unwrap().is_empty() {
|
||||
None
|
||||
} else {
|
||||
match self.id_mapping_service.get_or_create_id(parent.as_ref().unwrap()).await {
|
||||
Ok(pid) => Some(pid),
|
||||
Err(_) => None,
|
||||
}
|
||||
self.id_mapping_service.get_or_create_id(parent.as_ref().unwrap()).await.ok()
|
||||
};
|
||||
|
||||
// Get folder metadata
|
||||
@@ -651,11 +645,10 @@ impl FolderRepository for FolderFsRepository {
|
||||
current_idx += 1;
|
||||
}
|
||||
|
||||
if !folders.is_empty() {
|
||||
if let Err(e) = self.id_mapping_service.save_changes().await {
|
||||
if !folders.is_empty()
|
||||
&& let Err(e) = self.id_mapping_service.save_changes().await {
|
||||
tracing::error!("Error saving ID mappings: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
Ok((folders, total_count))
|
||||
}
|
||||
@@ -771,15 +764,13 @@ impl FolderRepository for FolderFsRepository {
|
||||
tokio::task::spawn_blocking(move || {
|
||||
if let Err(e) = std::fs::remove_dir_all(&path_for_large_removal) {
|
||||
tracing::error!("Error removing large directory: {}", e);
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
return Err(std::io::Error::other(
|
||||
format!("Failed to remove large directory: {}", e)
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}).await.unwrap_or_else(|e| {
|
||||
Err(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
Err(std::io::Error::other(
|
||||
format!("Task panicked during directory removal: {}", e)
|
||||
))
|
||||
})
|
||||
|
||||
@@ -94,15 +94,14 @@ impl FolderFsRepository {
|
||||
let original_path_buf = PathBuf::from(original_path);
|
||||
|
||||
// Ensure the destination parent directory exists
|
||||
if let Some(parent) = original_path_buf.parent() {
|
||||
if !parent.exists() {
|
||||
if let Some(parent) = original_path_buf.parent()
|
||||
&& !parent.exists() {
|
||||
fs::create_dir_all(parent).await
|
||||
.map_err(|e| {
|
||||
error!("Error creating parent directory for restoration: {}", e);
|
||||
FolderRepositoryError::StorageError(e.to_string())
|
||||
})?;
|
||||
}
|
||||
}
|
||||
|
||||
// Move the folder from the trash to its original location
|
||||
match fs::rename(¤t_path, &original_path_buf).await {
|
||||
|
||||
@@ -32,7 +32,7 @@ impl UserPgRepository {
|
||||
UserRepositoryError::NotFound("User not found".to_string())
|
||||
},
|
||||
sqlx::Error::Database(db_err) => {
|
||||
if db_err.code().map_or(false, |code| code == "23505") {
|
||||
if db_err.code().is_some_and(|code| code == "23505") {
|
||||
// PostgreSQL uniqueness violation code
|
||||
UserRepositoryError::AlreadyExists(
|
||||
"User or email already exists".to_string()
|
||||
@@ -268,7 +268,7 @@ impl UserRepository for UserPgRepository {
|
||||
.bind(user_clone.username())
|
||||
.bind(user_clone.email())
|
||||
.bind(user_clone.password_hash())
|
||||
.bind(&user_clone.role().to_string())
|
||||
.bind(user_clone.role().to_string())
|
||||
.bind(user_clone.storage_quota_bytes())
|
||||
.bind(user_clone.storage_used_bytes())
|
||||
.bind(user_clone.updated_at())
|
||||
|
||||
Reference in New Issue
Block a user