pub use self::inner::force_cargo_color;
use std::fs;
use std::path::PathBuf;
use std::time::{SystemTime, UNIX_EPOCH};
pub fn dir_last_modified(dir: &fs::DirEntry) -> u128 {
dir.metadata()
.and_then(|md| {
md.modified()
.map(|t| t.duration_since(UNIX_EPOCH).unwrap().as_millis())
})
.unwrap_or(0)
}
pub fn current_time() -> u128 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis()
}
pub fn cache_dir() -> PathBuf {
#[cfg(not(test))]
{
dirs::cache_dir()
.map(|dir| dir.join(crate::consts::PROGRAM_NAME))
.expect("Cannot get cache directory")
}
#[cfg(test)]
{
use lazy_static::lazy_static;
lazy_static! {
static ref TEMP_DIR: tempfile::TempDir = tempfile::TempDir::new().unwrap();
}
TEMP_DIR.path().to_path_buf()
}
}
pub fn generated_projects_cache_path() -> PathBuf {
cache_dir().join("projects")
}
pub fn binary_cache_path() -> PathBuf {
cache_dir().join("binaries")
}
#[cfg(unix)]
mod inner {
use std::io::IsTerminal as _;
pub fn force_cargo_color() -> bool {
std::io::stderr().is_terminal()
}
}
#[cfg(windows)]
pub mod inner {
pub fn force_cargo_color() -> bool {
false
}
}