diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-03-21 16:37:51 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-03-21 16:37:51 +0800 |
| commit | c811c5818d21a67280ef9dd35ad40f6f5411daa5 (patch) | |
| tree | 46062311242da24771466ad99be26b530e83d497 /legacy_data/src/data/local/latest_file_data.rs | |
| parent | 9a60751a901f568bdeb154c4115235d4f3a0f8b9 (diff) | |
Good Bye! Legacy JVCS
Diffstat (limited to 'legacy_data/src/data/local/latest_file_data.rs')
| -rw-r--r-- | legacy_data/src/data/local/latest_file_data.rs | 103 |
1 files changed, 0 insertions, 103 deletions
diff --git a/legacy_data/src/data/local/latest_file_data.rs b/legacy_data/src/data/local/latest_file_data.rs deleted file mode 100644 index f9b3aeb..0000000 --- a/legacy_data/src/data/local/latest_file_data.rs +++ /dev/null @@ -1,103 +0,0 @@ -use std::{collections::HashMap, io::Error, path::PathBuf}; - -use cfg_file::ConfigFile; -use serde::{Deserialize, Serialize}; - -use crate::{ - constants::{CLIENT_FILE_LATEST_DATA, CLIENT_FILE_MEMBER_HELD_NOSET, KEY_ACCOUNT}, - data::{ - member::MemberId, - vault::virtual_file::{VirtualFileId, VirtualFileVersion, VirtualFileVersionDescription}, - }, - env::current_local_path, -}; - -/// # Latest file data -/// Records the file holder and the latest version for permission and update checks -#[derive(Debug, Default, Clone, Serialize, Deserialize, ConfigFile)] -#[cfg_file(path = CLIENT_FILE_MEMBER_HELD_NOSET)] -pub struct LatestFileData { - /// File holding status - #[serde(rename = "held")] - held_status: HashMap<VirtualFileId, HeldStatus>, - - /// File version - #[serde(rename = "ver")] - versions: HashMap<VirtualFileId, VirtualFileVersion>, - - /// File histories and descriptions - #[serde(rename = "his")] - histories: HashMap<VirtualFileId, Vec<(VirtualFileVersion, VirtualFileVersionDescription)>>, -} - -#[derive(Debug, Default, Clone, Serialize, Deserialize)] -pub enum HeldStatus { - #[serde(rename = "Hold")] - HeldWith(MemberId), // Held, status changes are sync to the client - - #[serde(rename = "None")] - NotHeld, // Not held, status changes are sync to the client - - #[default] - #[serde(rename = "Unknown")] - WantedToKnow, // Holding status is unknown, notify server must inform client -} - -impl LatestFileData { - /// Get the path to the file holding the held status information for the given member. - pub fn data_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_LATEST_DATA.replace(KEY_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, - }) - } - - /// Get the version of the file with the given ID. - pub fn file_version(&self, vfid: &VirtualFileId) -> Option<&VirtualFileVersion> { - self.versions.get(vfid) - } - - /// Get the version of the file with the given ID. - pub fn file_histories( - &self, - vfid: &VirtualFileId, - ) -> Option<&Vec<(VirtualFileVersion, VirtualFileVersionDescription)>> { - self.histories.get(vfid) - } - - /// Update the held status of the files. - pub fn update_info( - &mut self, - map: HashMap< - VirtualFileId, - ( - Option<MemberId>, - VirtualFileVersion, - Vec<(VirtualFileVersion, VirtualFileVersionDescription)>, - ), - >, - ) { - for (vfid, (member_id, version, desc)) in map { - self.held_status.insert( - vfid.clone(), - match member_id { - Some(member_id) => HeldStatus::HeldWith(member_id), - None => HeldStatus::NotHeld, - }, - ); - self.versions.insert(vfid.clone(), version); - self.histories.insert(vfid, desc); - } - } -} |
