Skip to main content

fur_cli/security/
state.rs

1use serde_json::json;
2use serde_json::Value;
3use std::fs;
4use std::path::Path;
5
6pub fn lock_file() -> &'static str {
7    ".fur/lock.json"
8}
9
10pub fn is_locked() -> bool {
11    let path = Path::new(lock_file());
12
13    if !path.exists() {
14        return false;
15    }
16
17    let content = fs::read_to_string(path).unwrap_or_default();
18
19    if let Ok(v) = serde_json::from_str::<Value>(&content) {
20        return v["locked"].as_bool().unwrap_or(false);
21    }
22
23    false
24}
25
26pub fn write_lock() {
27    let data = json!({
28        "locked": true,
29        "algorithm": "AES-256-GCM",
30        "version": 1
31    });
32
33    fs::write(lock_file(), serde_json::to_string_pretty(&data).unwrap()).unwrap();
34}
35
36pub fn remove_lock() {
37    let path = Path::new(lock_file());
38
39    if path.exists() {
40        let _ = fs::remove_file(path);
41    }
42}