Skip to content

Commit

Permalink
feat: Updated fluere-plugin/src/util.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] authored Nov 8, 2023
1 parent a2c4284 commit b1cc9dd
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions fluere-plugin/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,23 @@ pub fn home_cache_path() -> std::io::Result<PathBuf> {

let path_base = match sudo_user {
Ok(user) => {
// If SUDO_USER is set, construct the path using the user's home directory
let user_home = format!("/home/{}", user);
Path::new(&user_home).join(".cache")
// on macOS just return the cache_dir()
if env::consts::OS == "macos" {
cache_dir().expect("Could not determine the home directory")
} else {
// If SUDO_USER is set, construct the path using the user's home directory
let user_home = format!("/home/{}", user);
Path::new(&user_home).join(".cache")
}
}
Err(_) => {
// If not running under sudo, just use the config_dir function as before
match cache_dir() {
Ok(dir) => dir,
Err(_) => {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
"Operation not supported by the OS",
))
}
}
// If not running under sudo, just use the cache_dir function as before
cache_dir().expect("Could not determine the home directory")
}
};

let path_config = path_base.join("fluere");
if !path_config.exists() {
fs::create_dir_all(path_config.clone())?;
}
path_config
Ok(path_config)
}

0 comments on commit b1cc9dd

Please sign in to comment.