Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure windsock path exists #3

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions windsock/src/data.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
use std::path::PathBuf;
use std::sync::OnceLock;

static INITIALIZED_PATH: OnceLock<()> = OnceLock::new();

pub fn windsock_path() -> PathBuf {
let path = windsock_path_inner();

// Create the directory only the first time this function is called during program execution.
if INITIALIZED_PATH.set(()).is_ok() {
std::fs::create_dir_all(&path).unwrap();
}

path
}

fn windsock_path_inner() -> PathBuf {
// If we are run via cargo (we are in a target directory) use the target directory for storage.
// Otherwise just fallback to the current working directory.
let mut path = std::env::current_exe().unwrap();
Expand Down