Skip to content

Commit

Permalink
fix: fixed errors occuring in merging
Browse files Browse the repository at this point in the history
  • Loading branch information
ninaagrawal committed Jan 10, 2025
1 parent 0fa4781 commit 7a55193
Showing 1 changed file with 0 additions and 132 deletions.
132 changes: 0 additions & 132 deletions hipcheck/src/cache/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<usize>,
}


#[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 "<DISPLAY_ERROR>".to_owned();
};
let Some(dt) = chrono::DateTime::<chrono::offset::Utc>::from_timestamp(
dur.as_secs() as i64,
dur.subsec_nanos(),
) else {
return "<DISPLAY_ERROR>".to_owned();
};
let chars = dt.to_rfc2822().chars().collect::<Vec<char>>();
// Remove unnecessary " +0000" from end of rfc datetime str
chars[..chars.len() - 6].iter().collect()
}

}

struct HcPluginCacheIterator {
wd: Box<dyn Iterator<Item = StdResult<DirEntry, walkdir::Error>>>
}

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<PluginCacheEntry> { //does function need to work when you clone a repo?
let components: Vec<String> = 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<Self::Item> {
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;
}
}
}



Expand All @@ -269,9 +143,6 @@ pub struct HcPluginCache {
pub path: PathBuf, //path to the root of the plugin cache
pub entries: Vec<PluginCacheEntry>, //needs to store a vector of PluginEntries

pub path: PathBuf, //path to the root of the plugin cache
pub entries: Vec<PluginCacheEntry>, //needs to store a vector of PluginEntries

}

impl HcPluginCache {
Expand All @@ -280,9 +151,6 @@ impl HcPluginCache {
let entries: Vec<PluginCacheEntry> =
HcPluginCacheIterator::new(plugins_path.as_path()).collect();
Self { path: plugins_path , entries: entries}
let entries: Vec<PluginCacheEntry> =
HcPluginCacheIterator::new(plugins_path.as_path()).collect();
Self { path: plugins_path , entries: entries}
}

/// The folder in which a specific PluginID will be stored
Expand Down

0 comments on commit 7a55193

Please sign in to comment.