This commit is contained in:
Thomas Forgione 2019-02-12 11:11:32 +01:00
parent 949490b350
commit 8480ae88f0
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
3 changed files with 13 additions and 7 deletions

View File

@ -4,7 +4,7 @@ use std::path::PathBuf;
use std::fs::File;
use std::io::{Write, BufRead, BufReader};
use walkdir::WalkDir;
use crate::{Result, GIT_DIR};
use crate::{Result, GCLONE_PATH};
/// The cache of gclone.
///
@ -17,7 +17,7 @@ impl Cache {
/// Generates the cache by traversing the files in the git directory.
pub fn generate() -> Cache {
Cache(WalkDir::new(&*GIT_DIR)
Cache(WalkDir::new(&*GCLONE_PATH)
.max_depth(3)
.into_iter()
.filter_map(|x| x.ok())
@ -28,7 +28,7 @@ impl Cache {
/// Reads the cache file.
pub fn read() -> Result<Cache> {
let mut path = PathBuf::from(&*GIT_DIR);
let mut path = PathBuf::from(&*GCLONE_PATH);
path.push(".cdgcache");
let file = File::open(&path)?;
@ -55,7 +55,7 @@ impl Cache {
/// Writes the current content of the cache to the cache file.
pub fn write(&self) -> Result<()> {
let mut path = PathBuf::from(&*GIT_DIR);
let mut path = PathBuf::from(&*GCLONE_PATH);
path.push(".cdgcache");
let mut file = File::create(path)?;

View File

@ -6,7 +6,7 @@ use std::path::PathBuf;
use colored::*;
use gclone::{GIT_DIR, Cache, Result};
use gclone::{GCLONE_PATH, Cache, Result};
macro_rules! unwrap {
($e: expr) => {
@ -85,7 +85,7 @@ fn main() -> Result<()> {
};
// Build path
let mut path = PathBuf::from(&*GIT_DIR);
let mut path = PathBuf::from(&*GCLONE_PATH);
path.push(&server);
path.push(&owner);
path.push(&repo);

View File

@ -9,7 +9,8 @@ mod cache;
pub use cache::Cache;
lazy_static! {
pub static ref GIT_DIR: String = {
/// The directory in which the repositories will be cloned and searched.
pub static ref GCLONE_PATH: String = {
match env::var("GCLONE_PATH") {
Ok(d) => d,
Err(e) => {
@ -32,8 +33,12 @@ macro_rules! impl_from_error {
}
#[derive(Debug)]
/// The error type of gclone.
pub enum Error {
/// Couldn't read the GCLONE_PATH env.
NoGclonePath(env::VarError),
/// An error occured while manipulating files.
IoError(io::Error),
}
@ -59,5 +64,6 @@ impl fmt::Display for Error {
impl error::Error for Error {}
/// The result type of gclone.
pub type Result<T> = result::Result<T, Error>;