Skip to content

Commit

Permalink
fix(cli): made system tools cache XDG-compliant
Browse files Browse the repository at this point in the history
  • Loading branch information
arctic-hen7 committed Jul 18, 2022
1 parent 4682b9d commit 085cd9b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/perseus-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ tokio-stream = "0.1"
reqwest = { version = "0.11", features = [ "json", "stream" ] }
tar = "0.4"
flate2 = "1"
home = "0.5"
directories = "4"

[dev-dependencies]
assert_cmd = "2"
Expand Down
6 changes: 3 additions & 3 deletions packages/perseus-cli/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use clap::Parser;
use command_group::stdlib::CommandGroup;
use directories::ProjectDirs;
use fmterr::fmt_err;
use home::home_dir;
use notify::{recommended_watcher, RecursiveMode, Watcher};
use perseus_cli::parse::{ExportOpts, ServeOpts, SnoopSubcommand};
use perseus_cli::{
Expand Down Expand Up @@ -55,8 +55,8 @@ async fn real_main() -> i32 {
if let Err(err) = delete_artifacts(dir.clone(), "tools") {
eprintln!("{}", fmt_err(&err));
}
if let Some(path) = home_dir() {
let target = path.join(".cargo/perseus_tools");
if let Some(dirs) = ProjectDirs::from("", "perseus", "perseus_cli") {
let target = dirs.cache_dir().join("tools");
if target.exists() {
if let Err(err) = std::fs::remove_dir_all(&target) {
let err = ExecutionError::RemoveArtifactsFailed {
Expand Down
13 changes: 6 additions & 7 deletions packages/perseus-cli/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use crate::cmd::{cfg_spinner, fail_spinner, succeed_spinner};
use crate::errors::*;
use crate::parse::Opts;
use console::Emoji;
use directories::ProjectDirs;
use flate2::read::GzDecoder;
use futures::future::try_join;
use home::home_dir;
use indicatif::ProgressBar;
use reqwest::Client;
use std::borrow::BorrowMut;
Expand Down Expand Up @@ -32,14 +32,13 @@ static INSTALLING: Emoji<'_, '_> = Emoji("📥", "");
/// If the user specifies that we're running on CI, we'll use the local version
/// regardless.
pub fn get_tools_dir(project: &Path, no_system_cache: bool) -> Result<PathBuf, InstallError> {
match home_dir() {
Some(path) if !no_system_cache => {
let target = path.join(".cargo/perseus_tools");
match ProjectDirs::from("", "perseus", "perseus_cli") {
Some(dirs) if !no_system_cache => {
let target = dirs.cache_dir().join("tools");
if target.exists() {
Ok(target)
Ok(target.to_path_buf())
} else {
// Try to create the system-wide cache (this will create `~/.cargo/` as well if
// necessary)
// Try to create the system-wide cache
if fs::create_dir_all(&target).is_ok() {
Ok(target)
} else {
Expand Down

0 comments on commit 085cd9b

Please sign in to comment.