Files
firezone/rust/gui-client/src-tauri/src/controller/ran_before.rs
Thomas Eizinger b7dc897eea refactor(rust): introduce libs/ directory (#10964)
The current Rust workspace isn't as consistent as it could be. To make
navigation a bit easier, we move a few crates around. Generally, we
follow the idea that entry-points should be at the top-level. `rust/`
now looks like this (directories only):

```
.
├── cli             # Firezone CLI
├── client-ffi      # Entry point for Apple & Android
├── gateway         # Gateway
├── gui-client      # GUI client
├── headless-client # Headless client
├── libs            # Library crates
├── relay           # Relay
├── target          # Compile artifacts
├── tests           # Crates for testing
└── tools           # Local tools
```

To further enforce this structure, we also drop the `firezone-` prefix
from all crates that are not top-level binary crates.
2025-11-25 10:59:11 +00:00

31 lines
877 B
Rust

//! Controls an on-disk flag indicating whether the user has signed in before
use anyhow::{Context as _, Result};
use std::path::PathBuf;
use tokio::fs;
/// Returns true if the flag is set
pub(crate) async fn get() -> Result<bool> {
// Just check if the file exists. We don't use `atomicwrites` to write it,
// so the content itself may be corrupt.
Ok(fs::try_exists(path()?).await?)
}
/// Sets the flag to true
pub(crate) async fn set() -> Result<()> {
let path = path()?;
fs::create_dir_all(
path.parent()
.context("ran_before path should have a parent dir")?,
)
.await?;
fs::write(&path, &[]).await?;
debug_assert!(get().await?);
Ok(())
}
fn path() -> Result<PathBuf> {
let session_dir = bin_shared::known_dirs::session().context("Couldn't find session dir")?;
Ok(session_dir.join("ran_before.txt"))
}