From ee6d809b60fabc707c079b3c22f5f237760d4ba1 Mon Sep 17 00:00:00 2001 From: konsti Date: Tue, 9 Jan 2024 17:35:10 +0100 Subject: [PATCH] Remove unused `Result` (#849) Remove some dead code, seems to be a refactoring oversight --- crates/distribution-types/src/cached.rs | 17 +++++------------ .../src/index/built_wheel_index.rs | 19 ++----------------- .../src/index/registry_wheel_index.rs | 19 ++----------------- 3 files changed, 9 insertions(+), 46 deletions(-) diff --git a/crates/distribution-types/src/cached.rs b/crates/distribution-types/src/cached.rs index f0e4a0ed6..a37d510d6 100644 --- a/crates/distribution-types/src/cached.rs +++ b/crates/distribution-types/src/cached.rs @@ -141,23 +141,16 @@ pub struct CachedWheel { impl CachedWheel { /// Try to parse a distribution from a cached directory name (like `typing-extensions-4.8.0-py3-none-any`). - pub fn from_path(path: &Path) -> Result> { - let Some(file_name) = path.file_name() else { - return Ok(None); - }; - let Some(file_name) = file_name.to_str() else { - return Ok(None); - }; - let Ok(filename) = WheelFilename::from_stem(file_name) else { - return Ok(None); - }; + pub fn from_path(path: &Path) -> Option { + let filename = path.file_name()?.to_str()?; + let filename = WheelFilename::from_stem(filename).ok()?; if path.is_file() { - return Ok(None); + return None; } let path = path.to_path_buf(); - Ok(Some(Self { filename, path })) + Some(Self { filename, path }) } /// Convert a [`CachedWheel`] into a [`CachedRegistryDist`]. diff --git a/crates/puffin-distribution/src/index/built_wheel_index.rs b/crates/puffin-distribution/src/index/built_wheel_index.rs index e457fe440..6680e4796 100644 --- a/crates/puffin-distribution/src/index/built_wheel_index.rs +++ b/crates/puffin-distribution/src/index/built_wheel_index.rs @@ -1,6 +1,3 @@ -use fs_err as fs; -use tracing::warn; - use distribution_types::CachedWheel; use platform_tags::Tags; use puffin_cache::CacheShard; @@ -31,8 +28,8 @@ impl BuiltWheelIndex { for subdir in directories(&**shard) { match CachedWheel::from_path(&subdir) { - Ok(None) => {} - Ok(Some(dist_info)) => { + None => {} + Some(dist_info) => { // Pick the wheel with the highest priority let compatibility = dist_info.filename.compatibility(tags); @@ -56,18 +53,6 @@ impl BuiltWheelIndex { candidate = Some(dist_info); } } - Err(err) => { - warn!( - "Invalid cache entry at {}, removing. {err}", - subdir.display() - ); - if let Err(err) = fs::remove_dir_all(&subdir) { - warn!( - "Failed to remove invalid cache entry at {}: {err}", - subdir.display() - ); - } - } } } diff --git a/crates/puffin-distribution/src/index/registry_wheel_index.rs b/crates/puffin-distribution/src/index/registry_wheel_index.rs index 1d07eef4f..1b34069c8 100644 --- a/crates/puffin-distribution/src/index/registry_wheel_index.rs +++ b/crates/puffin-distribution/src/index/registry_wheel_index.rs @@ -2,9 +2,7 @@ use std::collections::hash_map::Entry; use std::collections::BTreeMap; use std::path::Path; -use fs_err as fs; use rustc_hash::FxHashMap; -use tracing::warn; use distribution_types::{CachedRegistryDist, CachedWheel, IndexUrls}; use pep440_rs::Version; @@ -110,8 +108,8 @@ impl<'a> RegistryWheelIndex<'a> { ) { for wheel_dir in directories(path.as_ref()) { match CachedWheel::from_path(&wheel_dir) { - Ok(None) => {} - Ok(Some(dist_info)) => { + None => {} + Some(dist_info) => { let dist_info = dist_info.into_registry_dist(); // Pick the wheel with the highest priority @@ -125,19 +123,6 @@ impl<'a> RegistryWheelIndex<'a> { versions.insert(dist_info.filename.version.clone(), dist_info); } } - Err(err) => { - warn!( - "Invalid cache entry at {}, removing. {err}", - wheel_dir.display() - ); - - if let Err(err) = fs::remove_dir_all(&wheel_dir) { - warn!( - "Failed to remove invalid cache entry at {}: {err}", - wheel_dir.display() - ); - } - } } } }