summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-11-17 20:29:27 +0800
committer魏曹先生 <1992414357@qq.com>2025-11-17 20:29:27 +0800
commitf73c4c0071bb37430cbf48f7e2d06dcdedb2c8ec (patch)
treedc29c89087f7f584ea07a8e3ecf1e71184de82e6 /crates
parent7b97b52af021500d8085c875d20215e8dc0f53cc (diff)
Use member-specific paths for latest info files
Diffstat (limited to 'crates')
-rw-r--r--crates/vcs_actions/src/actions/local_actions.rs31
-rw-r--r--crates/vcs_actions/src/actions/virtual_file_actions.rs2
-rw-r--r--crates/vcs_data/src/constants.rs2
-rw-r--r--crates/vcs_data/src/data/local/config.rs7
-rw-r--r--crates/vcs_data/src/data/local/latest_info.rs14
5 files changed, 42 insertions, 14 deletions
diff --git a/crates/vcs_actions/src/actions/local_actions.rs b/crates/vcs_actions/src/actions/local_actions.rs
index c9e5db3..d10c317 100644
--- a/crates/vcs_actions/src/actions/local_actions.rs
+++ b/crates/vcs_actions/src/actions/local_actions.rs
@@ -1,9 +1,4 @@
-use std::{
- collections::HashMap,
- io::{Error, ErrorKind},
- net::SocketAddr,
- path::PathBuf,
-};
+use std::{collections::HashMap, io::ErrorKind, net::SocketAddr, path::PathBuf};
use action_system::{action::ActionContext, macros::action_gen};
use cfg_file::config::ConfigFile;
@@ -191,13 +186,18 @@ pub async fn update_to_latest_info_action(
}
if ctx.is_proc_on_local() {
+ let workspace = try_get_local_workspace(&ctx)?;
let mut latest_info = instance
.lock()
.await
.read_large_msgpack::<LatestInfo>(512 as u16)
.await?;
latest_info.update_instant = Some(Instant::now());
- LatestInfo::write(&latest_info).await?;
+ LatestInfo::write_to(
+ &latest_info,
+ LatestInfo::latest_info_path(workspace.local_path(), &member_id),
+ )
+ .await?;
}
}
@@ -206,7 +206,13 @@ pub async fn update_to_latest_info_action(
// Sync Remote Sheets
{
if ctx.is_proc_on_local() {
- let Ok(latest_info) = LatestInfo::read().await else {
+ let workspace = try_get_local_workspace(&ctx)?;
+ let Ok(latest_info) = LatestInfo::read_from(LatestInfo::latest_info_path(
+ workspace.local_path(),
+ &member_id,
+ ))
+ .await
+ else {
return Err(TcpTargetError::NotFound(
"Latest info not found.".to_string(),
));
@@ -301,7 +307,14 @@ pub async fn update_to_latest_info_action(
// Sync Held Info
{
if ctx.is_proc_on_local() {
- let Ok(latest_info) = LatestInfo::read().await else {
+ let workspace = try_get_local_workspace(&ctx)?;
+
+ let Ok(latest_info) = LatestInfo::read_from(LatestInfo::latest_info_path(
+ workspace.local_path(),
+ &member_id,
+ ))
+ .await
+ else {
return Err(TcpTargetError::NotFound(
"Latest info not found.".to_string(),
));
diff --git a/crates/vcs_actions/src/actions/virtual_file_actions.rs b/crates/vcs_actions/src/actions/virtual_file_actions.rs
index fa71f1b..fa74873 100644
--- a/crates/vcs_actions/src/actions/virtual_file_actions.rs
+++ b/crates/vcs_actions/src/actions/virtual_file_actions.rs
@@ -1,4 +1,4 @@
-use std::{collections::HashSet, path::PathBuf, sync::Arc, time::SystemTime};
+use std::{collections::HashSet, path::PathBuf, sync::Arc};
use action_system::{action::ActionContext, macros::action_gen};
use cfg_file::config::ConfigFile;
diff --git a/crates/vcs_data/src/constants.rs b/crates/vcs_data/src/constants.rs
index a1d0ad2..47a77bd 100644
--- a/crates/vcs_data/src/constants.rs
+++ b/crates/vcs_data/src/constants.rs
@@ -48,7 +48,7 @@ pub const CLIENT_FOLDER_WORKSPACE_ROOT_NAME: &str = ".jv";
pub const CLIENT_FILE_WORKSPACE: &str = "./.jv/workspace.toml";
// Client - Latest Information
-pub const CLIENT_FILE_LATEST_INFO: &str = "./.jv/.latest.json";
+pub const CLIENT_FILE_LATEST_INFO: &str = "./.jv/.{account}_latest.json";
// Client - Local
pub const CLIENT_SUFFIX_LOCAL_SHEET_FILE: &str = ".json";
diff --git a/crates/vcs_data/src/data/local/config.rs b/crates/vcs_data/src/data/local/config.rs
index fa3b607..c51147c 100644
--- a/crates/vcs_data/src/data/local/config.rs
+++ b/crates/vcs_data/src/data/local/config.rs
@@ -97,7 +97,12 @@ impl LocalConfig {
let local_path = self.get_local_path().await?;
// Get latest info
- let Ok(latest_info) = LatestInfo::read().await else {
+ let Ok(latest_info) = LatestInfo::read_from(LatestInfo::latest_info_path(
+ &local_path,
+ &self.current_account(),
+ ))
+ .await
+ else {
return Err(std::io::Error::new(
std::io::ErrorKind::NotFound,
"No latest info found",
diff --git a/crates/vcs_data/src/data/local/latest_info.rs b/crates/vcs_data/src/data/local/latest_info.rs
index e4f45b1..bc13ae9 100644
--- a/crates/vcs_data/src/data/local/latest_info.rs
+++ b/crates/vcs_data/src/data/local/latest_info.rs
@@ -5,18 +5,21 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
use tokio::time::Instant;
use crate::{
- constants::CLIENT_FILE_LATEST_INFO,
+ constants::{CLIENT_FILE_LATEST_INFO, CLIENT_FILE_LATEST_INFO_NOSET},
data::{
+ local::{LocalWorkspace, config::LocalConfig},
member::{Member, MemberId},
sheet::{SheetData, SheetName},
},
};
+const ACCOUNT: &str = "{account}";
+
/// # Latest Info
/// Locally cached latest information,
/// used to cache personal information from upstream for querying and quickly retrieving member information.
#[derive(Default, Serialize, Deserialize, ConfigFile)]
-#[cfg_file(path = CLIENT_FILE_LATEST_INFO)]
+#[cfg_file(path = CLIENT_FILE_LATEST_INFO_NOSET)]
pub struct LatestInfo {
// Sheets
/// My sheets, indicating which sheets I can edit
@@ -38,6 +41,13 @@ pub struct LatestInfo {
pub vault_members: Vec<Member>,
}
+impl LatestInfo {
+ /// Get the path to the latest info file for a given workspace and member ID
+ pub fn latest_info_path(local_workspace_path: &PathBuf, member_id: &MemberId) -> PathBuf {
+ local_workspace_path.join(CLIENT_FILE_LATEST_INFO.replace(ACCOUNT, member_id))
+ }
+}
+
#[derive(Default, Serialize, Deserialize)]
pub struct SheetInfo {
pub sheet_name: SheetName,