summaryrefslogtreecommitdiff
path: root/crates/vcs_data/src/data/local/vault_modified.rs
blob: 125fb924408c0ba04ea1e7d61a3633a37438c5e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use crate::{constants::CLIENT_FILE_VAULT_MODIFIED, current::current_local_path};

pub async fn check_vault_modified() -> bool {
    let Some(current_dir) = current_local_path() else {
        return false;
    };

    let record_file = current_dir.join(CLIENT_FILE_VAULT_MODIFIED);
    if !record_file.exists() {
        return false;
    }

    let Ok(contents) = tokio::fs::read_to_string(&record_file).await else {
        return false;
    };

    matches!(contents.trim().to_lowercase().as_str(), "true")
}

pub async fn sign_vault_modified(modified: bool) -> bool {
    let Some(current_dir) = current_local_path() else {
        return false;
    };

    let record_file = current_dir.join(CLIENT_FILE_VAULT_MODIFIED);

    let contents = if modified { "true" } else { "false" };

    match tokio::fs::write(&record_file, contents).await {
        Ok(_) => true,
        Err(_) => false,
    }
}