Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahul committed Aug 14, 2023
1 parent 0950994 commit c5e0c20
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 47 deletions.
8 changes: 4 additions & 4 deletions src/core/buckets/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Query<&str> for Buckets {

fn query_fts(query: &str) -> Result<Self, Self::Error> {
let buckets_dir = Config::buckets_dir()?;
let buckets = Config::read()?.known_buckets();
let buckets = Config::read()?.list_buckets();

let query = match query.contains(" ") {
true => query
Expand All @@ -31,7 +31,7 @@ impl Query<&str> for Buckets {
false => query.into(),
};

let predicate = |(bucket_name, _): (String, _)| -> Option<(String, Bucket)> {
let predicate = |bucket_name: String| -> Option<(String, Bucket)> {
let content = read_to_string(buckets_dir.join(&bucket_name)).unwrap();
let bucket: Bucket = from_str(&content).unwrap();
let bucket: Bucket = bucket.query_fts(&query);
Expand All @@ -49,9 +49,9 @@ impl Query<&str> for Buckets {

fn query_app(query: &str) -> Result<Self, Self::Error> {
let buckets_dir = Config::buckets_dir()?;
let buckets = Config::read()?.known_buckets();
let buckets = Config::read()?.list_buckets();

let predicate = |(bucket_name, _): (String, _)| -> Option<(String, Bucket)> {
let predicate = |bucket_name: String| -> Option<(String, Bucket)> {
let content = read_to_string(buckets_dir.join(&bucket_name)).unwrap();
let bucket: Bucket = from_str(&content).unwrap();
let bucket: Bucket = bucket.query_app(&query);
Expand Down
15 changes: 12 additions & 3 deletions src/core/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,12 @@ impl Config {
self.buckets
}

pub fn download(&self) -> Download {
self.download.to_owned()
pub fn list_buckets(self) -> Vec<String> {
self.buckets.into_keys().collect()
}

pub fn download(self) -> Download {
self.download
}
}

Expand All @@ -140,7 +144,12 @@ pub trait DefaultDirs {
impl DefaultDirs for Config {
fn home_dir() -> Result<PathBuf, ScoopieError> {
let scoopie_home = env::var("SCOOPIE_HOME").map_err(|_| ScoopieError::EnvResolve)?;
Ok(PathBuf::from(scoopie_home))
let scoopie_home = PathBuf::from(scoopie_home);

match scoopie_home.exists() {
true => Ok(scoopie_home),
false => Err(ScoopieError::HomeDirUnavailable),
}
}

fn buckets_dir() -> Result<PathBuf, ScoopieError> {
Expand Down
38 changes: 10 additions & 28 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ pub enum ScoopieError {
#[error("While syncing repositories, {0}")]
Sync(SyncError),
#[error("{0}")]
Database(DatabaseError),
#[error("{0}")]
Bucket(BucketError),
#[error("{0}")]
Init(InitError),
#[error("While reading config, {0}")]
Config(ConfigError),
#[error("{0}")]
Query(QueryError),
#[error("{0}")]
Download(DownloadError),
#[error("User directory unavailable")]
UserDirUnavailable,
Expand Down Expand Up @@ -62,6 +58,16 @@ pub enum DownloadError {
NoAppFound(String),
#[error("App: \"{0}\" is not available in {1} repo.")]
NoAppFoundInBucket(String, String),
#[error("Unable to write to file: {0:?}")]
FlushFile(PathBuf),
#[error("Unable to write downloaded chunk to file: {0:?}")]
ChunkWrite(PathBuf),
#[error("Unable to download chunk while downloading app: {0}")]
UnableToGetChunk(String),
#[error("Unable to create file while downloading app: {0}")]
UnableToCreateFile(String),
#[error("Unable to get HTTP client, possible reasons could be system configuration or network error")]
UnableToGetClient,
}

#[derive(Debug, Error)]
Expand All @@ -76,18 +82,6 @@ pub enum SyncError {
UnableToGetCommit,
}

#[derive(Debug, Error)]
pub enum DatabaseError {
#[error("Unable to open database")]
UnableToOpen,
#[error("Failed to create database")]
FailedToCreateTable,
#[error("Failed to make statement for database")]
FailedToMkStmt,
#[error("Failed to insert mainfest to database")]
FailedInsertion,
}

#[derive(Debug, Error)]
pub enum BucketError {
#[error("No buckets found")]
Expand All @@ -104,8 +98,6 @@ pub enum BucketError {
pub enum InitError {
#[error("Config write error")]
ConfigWrite,
#[error("Unable to set environment variable")]
UnableToSetEnvVar,
}

#[derive(Debug, Error)]
Expand All @@ -123,13 +115,3 @@ pub enum ConfigError {
#[error("No buckets configured in config")]
NoBucketsConfigured,
}

#[derive(Debug, Error)]
pub enum QueryError {
#[error("Failed to retrieve data")]
FailedToRetrieveData,
// #[error("Found invalid JSON while retrieving data")]
// InavlidJSONData,
// #[error("Failed to query")]
// FailedToQuery,
}
12 changes: 0 additions & 12 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,3 @@ impl Absolute for PathBuf {
))
}
}

pub struct Zipper;

impl Zipper {
pub fn zip<T, U>(iter1: T, iter2: U) -> impl Iterator<Item = (T::Item, U::Item)>
where
T: Iterator,
U: Iterator,
{
iter1.zip(iter2)
}
}

0 comments on commit c5e0c20

Please sign in to comment.