Skip to content

Commit

Permalink
Merge pull request #27 from ktwrd/feature/custom-tmpdir
Browse files Browse the repository at this point in the history
Custom Temporary Directory
  • Loading branch information
ktwrd authored Jul 14, 2024
2 parents 2395077 + f72d83b commit 9068205
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/helper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,32 @@ pub fn format_size(i: usize) -> String {
}
return format!("{}{}", whole, dec_x);
}
/// Check if we should use the custom temporary directory, which is stored in the environment variable
/// defined in `CUSTOM_TMPDIR_NAME`.
///
/// ## Return
/// `Some` when the environment variable is set, and the directory exist.
/// Otherwise `None` is returned.
pub fn use_custom_tmpdir() -> Option<String>
{
if let Ok(x) = std::env::var(CUSTOM_TMPDIR_NAME) {
let s = x.to_string();
if dir_exists(s.clone()) {
return Some(s);
} else {
warn!("[use_custom_tmp_dir] Custom temporary directory \"{}\" doesn't exist", s);
}
}
return None;
}
pub const CUSTOM_TMPDIR_NAME: &str = "ADASTRAL_TMPDIR";
/// Create directory in temp directory with name of "beans-rs"
pub fn get_tmp_dir() -> String
{
let mut dir = std::env::temp_dir().to_str().unwrap_or("").to_string();
if is_steamdeck() {
if let Some(x) = use_custom_tmpdir() {
dir = x;
} else if is_steamdeck() {
trace!("[helper::get_tmp_dir] Detected that we are running on a steam deck. Using ~/.tmp/beans-rs");
match simple_home_dir::home_dir() {
Some(v) => {
Expand Down

0 comments on commit 9068205

Please sign in to comment.