Skip to content

Commit

Permalink
make tmp direcotry default to cache dir in mac
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmaSd committed Nov 5, 2024
1 parent ce674c1 commit 4a78e3f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions crates/irust/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@ pub mod irust_dirs {
if let Ok(dir) = std::env::var("IRUST_TEMP_DIR") {
return dir.into();
}
// On macOS, binaries inside the default temp directory can't acess the outside filesystem
// so we use the cache directory instead
if cfg!(target_os = "macos") {
return dirs::cache_dir().unwrap_or_else(std::env::temp_dir);
}
std::env::temp_dir()
}
}
3 changes: 3 additions & 0 deletions crates/irust_repl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ license = "MIT"
serde = { version = "1.0.188", features = ["derive"], optional = true }
uuid = { version = "1.4.1", features = ["v4"] }

[target.'cfg(target_os = "macos")'.dependencies]
dirs = "5.0.1"

[dev-dependencies]
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.105"
Expand Down
11 changes: 10 additions & 1 deletion crates/irust_repl/src/cargo_cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@ impl CargoPaths {
let tmp_dir = if let Ok(dir) = std::env::var("IRUST_TEMP_DIR") {
dir.into()
} else {
std::env::temp_dir()
// On macOS, binaries inside the default temp directory can't acess the outside filesystem
// so we use the cache directory instead
#[cfg(target_os = "macos")]
{
dirs::cache_dir().unwrap_or_else(std::env::temp_dir);
}
#[cfg(not(target_os = "macos"))]
{
std::env::temp_dir()
}
};
let common_root = tmp_dir.join("irust_repls");
let irust_dir = common_root.join(name);
Expand Down

0 comments on commit 4a78e3f

Please sign in to comment.