diff options
| author | 魏曹先生 <1992414357@qq.com> | 2025-11-23 15:55:47 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2025-11-23 15:55:47 +0800 |
| commit | 891510df9b7c43216185d056a979eb5077570458 (patch) | |
| tree | 55805140bd9ccdf318c60abc8f49f6f421414932 /crates/vcs_data | |
| parent | c1a50fbdddc5fad986f4b3b6310cc5167e68f87e (diff) | |
Add vault modification tracking
- Record vault state changes in sheet operations - Track modifications
when creating, dropping, or updating sheets - Mark vault as unmodified
after syncing with upstream - Add vault_modified module with check and
sign functions
Diffstat (limited to 'crates/vcs_data')
| -rw-r--r-- | crates/vcs_data/src/constants.rs | 1 | ||||
| -rw-r--r-- | crates/vcs_data/src/data/local.rs | 11 | ||||
| -rw-r--r-- | crates/vcs_data/src/data/local/vault_modified.rs | 33 |
3 files changed, 40 insertions, 5 deletions
diff --git a/crates/vcs_data/src/constants.rs b/crates/vcs_data/src/constants.rs index 6b4c963..088f8b0 100644 --- a/crates/vcs_data/src/constants.rs +++ b/crates/vcs_data/src/constants.rs @@ -78,6 +78,7 @@ pub const CLIENT_CONTENT_GITIGNORE: &str = "# Git support for JVCS Workspace # Ignore cached datas cached members"; +pub const CLIENT_FILE_VAULT_MODIFIED: &str = "./.jv/.vault_modified"; // ------------------------------------------------------------------------------------- diff --git a/crates/vcs_data/src/data/local.rs b/crates/vcs_data/src/data/local.rs index 22589fc..092ef7d 100644 --- a/crates/vcs_data/src/data/local.rs +++ b/crates/vcs_data/src/data/local.rs @@ -35,6 +35,7 @@ pub mod latest_file_data; pub mod latest_info; pub mod local_files; pub mod local_sheet; +pub mod vault_modified; const SHEET_NAME: &str = "{sheet_name}"; const ACCOUNT_NAME: &str = "{account}"; @@ -117,7 +118,6 @@ impl LocalWorkspace { /// Get the path to a local sheet. pub fn local_sheet_path(&self, member: &MemberId, sheet: &SheetName) -> PathBuf { - self.local_path.join( CLIENT_FILE_LOCAL_SHEET .replace(ACCOUNT_NAME, member) @@ -177,10 +177,11 @@ impl LocalWorkspace { Box::pin(collect_sheet_paths(&path, suffix, paths)).await?; } else if path.is_file() && let Some(extension) = path.extension() - && extension == suffix.trim_start_matches('.') { - let formatted_path = format_path(path)?; - paths.push(formatted_path); - } + && extension == suffix.trim_start_matches('.') + { + let formatted_path = format_path(path)?; + paths.push(formatted_path); + } } } Ok(()) diff --git a/crates/vcs_data/src/data/local/vault_modified.rs b/crates/vcs_data/src/data/local/vault_modified.rs new file mode 100644 index 0000000..125fb92 --- /dev/null +++ b/crates/vcs_data/src/data/local/vault_modified.rs @@ -0,0 +1,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, + } +} |
