diff options
| author | 魏曹先生 <1992414357@qq.com> | 2025-11-17 11:49:49 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2025-11-17 11:49:49 +0800 |
| commit | 7b97b52af021500d8085c875d20215e8dc0f53cc (patch) | |
| tree | 9b8219363380db3330bda75e28e364154224eca8 /crates/vcs_data/src/data/local/member_held.rs | |
| parent | e190d90594b17fb16849a13198af3f5152414e4c (diff) | |
feat: Add file status tracking and SHA1 hash system
- Implement SHA1 hash calculation module with async support
- Add file status analysis for tracking moves, creates, and modifications
- Enhance local file management with relative path handling
- Update virtual file actions with improved tracking capabilities
Diffstat (limited to 'crates/vcs_data/src/data/local/member_held.rs')
| -rw-r--r-- | crates/vcs_data/src/data/local/member_held.rs | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/crates/vcs_data/src/data/local/member_held.rs b/crates/vcs_data/src/data/local/member_held.rs index 37bc18e..3f07232 100644 --- a/crates/vcs_data/src/data/local/member_held.rs +++ b/crates/vcs_data/src/data/local/member_held.rs @@ -1,13 +1,16 @@ -use std::collections::HashMap; +use std::{collections::HashMap, io::Error, path::PathBuf}; use cfg_file::ConfigFile; use serde::{Deserialize, Serialize}; use crate::{ - constants::CLIENT_FILE_MEMBER_HELD_NOSET, + constants::{CLIENT_FILE_MEMBER_HELD, CLIENT_FILE_MEMBER_HELD_NOSET}, + current::current_local_path, data::{member::MemberId, vault::virtual_file::VirtualFileId}, }; +const ACCOUNT: &str = "{account}"; + /// # Member Held Information /// Records the files held by the member, used for permission validation #[derive(Debug, Default, Clone, Serialize, Deserialize, ConfigFile)] @@ -25,3 +28,37 @@ pub enum HeldStatus { #[default] WantedToKnow, // Holding status is unknown, notify server must inform client } + +impl MemberHeld { + /// Get the path to the file holding the held status information for the given member. + pub fn held_file_path(account: &MemberId) -> Result<PathBuf, std::io::Error> { + let Some(local_path) = current_local_path() else { + return Err(Error::new( + std::io::ErrorKind::NotFound, + "Workspace not found.", + )); + }; + Ok(local_path.join(CLIENT_FILE_MEMBER_HELD.replace(ACCOUNT, account))) + } + + /// Get the member who holds the file with the given ID. + pub fn file_holder(&self, vfid: &VirtualFileId) -> Option<&MemberId> { + self.held_status.get(vfid).and_then(|status| match status { + HeldStatus::HeldWith(id) => Some(id), + _ => None, + }) + } + + /// Update the held status of the files. + pub fn update_held_status(&mut self, map: HashMap<VirtualFileId, Option<MemberId>>) { + for (vfid, member_id) in map { + self.held_status.insert( + vfid, + match member_id { + Some(member_id) => HeldStatus::HeldWith(member_id), + None => HeldStatus::NotHeld, + }, + ); + } + } +} |
