Skip to content

Commit 085cd9b

Browse files
committed
fix(cli): made system tools cache XDG-compliant
See <https://users.rust-lang.org/t/advice-on-adding-arbitrary-data-to-cargo/78449> for further details.
1 parent 4682b9d commit 085cd9b

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

packages/perseus-cli/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ tokio-stream = "0.1"
4040
reqwest = { version = "0.11", features = [ "json", "stream" ] }
4141
tar = "0.4"
4242
flate2 = "1"
43-
home = "0.5"
43+
directories = "4"
4444

4545
[dev-dependencies]
4646
assert_cmd = "2"

packages/perseus-cli/src/bin/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clap::Parser;
22
use command_group::stdlib::CommandGroup;
3+
use directories::ProjectDirs;
34
use fmterr::fmt_err;
4-
use home::home_dir;
55
use notify::{recommended_watcher, RecursiveMode, Watcher};
66
use perseus_cli::parse::{ExportOpts, ServeOpts, SnoopSubcommand};
77
use perseus_cli::{
@@ -55,8 +55,8 @@ async fn real_main() -> i32 {
5555
if let Err(err) = delete_artifacts(dir.clone(), "tools") {
5656
eprintln!("{}", fmt_err(&err));
5757
}
58-
if let Some(path) = home_dir() {
59-
let target = path.join(".cargo/perseus_tools");
58+
if let Some(dirs) = ProjectDirs::from("", "perseus", "perseus_cli") {
59+
let target = dirs.cache_dir().join("tools");
6060
if target.exists() {
6161
if let Err(err) = std::fs::remove_dir_all(&target) {
6262
let err = ExecutionError::RemoveArtifactsFailed {

packages/perseus-cli/src/install.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use crate::cmd::{cfg_spinner, fail_spinner, succeed_spinner};
22
use crate::errors::*;
33
use crate::parse::Opts;
44
use console::Emoji;
5+
use directories::ProjectDirs;
56
use flate2::read::GzDecoder;
67
use futures::future::try_join;
7-
use home::home_dir;
88
use indicatif::ProgressBar;
99
use reqwest::Client;
1010
use std::borrow::BorrowMut;
@@ -32,14 +32,13 @@ static INSTALLING: Emoji<'_, '_> = Emoji("📥", "");
3232
/// If the user specifies that we're running on CI, we'll use the local version
3333
/// regardless.
3434
pub fn get_tools_dir(project: &Path, no_system_cache: bool) -> Result<PathBuf, InstallError> {
35-
match home_dir() {
36-
Some(path) if !no_system_cache => {
37-
let target = path.join(".cargo/perseus_tools");
35+
match ProjectDirs::from("", "perseus", "perseus_cli") {
36+
Some(dirs) if !no_system_cache => {
37+
let target = dirs.cache_dir().join("tools");
3838
if target.exists() {
39-
Ok(target)
39+
Ok(target.to_path_buf())
4040
} else {
41-
// Try to create the system-wide cache (this will create `~/.cargo/` as well if
42-
// necessary)
41+
// Try to create the system-wide cache
4342
if fs::create_dir_all(&target).is_ok() {
4443
Ok(target)
4544
} else {

0 commit comments

Comments
 (0)