use std::{fs, path::PathBuf};
use crate::{util, Config};
#[derive(Debug)]
pub struct Context {
pub config: Config,
pub intermediates_path: PathBuf,
pub tools_path: PathBuf,
}
impl Context {
pub fn new(config: &Config) -> crate::Result<Self> {
let tools_path = dirs::cache_dir()
.unwrap_or_else(|| config.out_dir())
.join(".cargo-packager");
if !tools_path.exists() {
fs::create_dir_all(&tools_path)?;
}
let intermediates_path = config.out_dir().join(".cargo-packager");
util::create_clean_dir(&intermediates_path)?;
Ok(Self {
config: config.clone(),
tools_path,
intermediates_path,
})
}
}