diff --git a/hipcheck/src/cache/plugin.rs b/hipcheck/src/cache/plugin.rs index 5c2adf8c..5d66b527 100644 --- a/hipcheck/src/cache/plugin.rs +++ b/hipcheck/src/cache/plugin.rs @@ -8,8 +8,6 @@ use std::{borrow::Borrow, use pathbuf::pathbuf; use tabled::{Table, Tabled}; use walkdir::{DirEntry, WalkDir}; -use tabled::{Table, Tabled}; -use walkdir::{DirEntry, WalkDir}; use crate::plugin::PluginId; use crate::StdResult; //use super::super::cli::CliConfig; @@ -137,130 +135,6 @@ impl Iterator for HcPluginCacheIterator { } -use crate::StdResult; -//use super::super::cli::CliConfig; -use crate::error::Result; -use regex::Regex; //used for regex -use semver::{Version, VersionReq}; -use crate::cache::repo; - -///enums used for sorting are the same as the ones used for listing repo cache entries except for -/// does not include Largest -#[derive(Debug, Clone)] -pub enum PluginCacheSort { - Oldest, - Alpha, -} - -#[derive(Debug, Clone)] -pub enum PluginCacheDeleteScope { - All, - Group { - sort: PluginCacheSort, - invert: bool, - n: usize, - }, -} - -#[derive(Debug, Clone)] -pub struct PluginCacheListScope { - pub sort: PluginCacheSort, - pub invert: bool, - pub n: Option, -} - - -#[derive(Debug, Clone, Tabled)] -pub struct PluginCacheEntry { - pub publisher: String, - pub name: String, - pub version: String, - #[tabled(display_with("Self::display_modified", self), rename = "last_modified")] - pub modified: SystemTime -} - -impl PluginCacheEntry { //copied the function from repo for simplicity - pub fn display_modified(&self) -> String { - let Ok(dur) = self.modified.duration_since(SystemTime::UNIX_EPOCH) else { - return "".to_owned(); - }; - let Some(dt) = chrono::DateTime::::from_timestamp( - dur.as_secs() as i64, - dur.subsec_nanos(), - ) else { - return "".to_owned(); - }; - let chars = dt.to_rfc2822().chars().collect::>(); - // Remove unnecessary " +0000" from end of rfc datetime str - chars[..chars.len() - 6].iter().collect() - } - -} - -struct HcPluginCacheIterator { - wd: Box>> -} - -impl HcPluginCacheIterator { - fn new(path: &Path) -> Self { - HcPluginCacheIterator{ - wd: Box::new( - WalkDir::new(path) //builds a new iterator using WalkDir - .min_depth(3) //makes sure to get the publisher, name, and version folders - .into_iter() - .filter_entry(|e| e.path().is_dir()), //makes sure the path is a directory - ) - } - } - fn path_to_plugin_entry(&self, path: &Path) -> Result { //does function need to work when you clone a repo? - let components: Vec = path - .components() - .filter_map(|component| { - if let Component::Normal(name) = component { //extracts components seperated by "/" from the path - name.to_str().map(|s| s.to_string()) //converts the string slices into Strings - } else { - None - } - - }) - .collect(); //collects filepath into vector -//Todo: add error handling for when the path length is less than 3 - let relevant_components: &[String] = &components[components.len() - 3..]; - let plugin_publisher = relevant_components[0].to_owned(); - let plugin_name = relevant_components[1].to_owned(); - let plugin_version = relevant_components[2].to_owned(); - let last_modified: SystemTime = repo::get_last_modified_or_now(path); - Ok(PluginCacheEntry{ - publisher:plugin_publisher, - name:plugin_name, - version: plugin_version, - modified: last_modified - }) - - } - -} - - - -///Function will take the full file path and put the last 3 directories (publisher, plugin, and review) -///into the Plugin Cache entry -impl Iterator for HcPluginCacheIterator { - type Item = PluginCacheEntry; - fn next(&mut self) -> Option { - if let Some(Ok(e)) = self.wd.next() { - if let Ok(ce) = self.path_to_plugin_entry(e.path()) { - return Some(ce); - } - else { - return None; - } - } - else { - return None; - } - } -} @@ -269,9 +143,6 @@ pub struct HcPluginCache { pub path: PathBuf, //path to the root of the plugin cache pub entries: Vec, //needs to store a vector of PluginEntries - pub path: PathBuf, //path to the root of the plugin cache - pub entries: Vec, //needs to store a vector of PluginEntries - } impl HcPluginCache { @@ -280,9 +151,6 @@ impl HcPluginCache { let entries: Vec = HcPluginCacheIterator::new(plugins_path.as_path()).collect(); Self { path: plugins_path , entries: entries} - let entries: Vec = - HcPluginCacheIterator::new(plugins_path.as_path()).collect(); - Self { path: plugins_path , entries: entries} } /// The folder in which a specific PluginID will be stored