diff options
| author | 魏曹先生 <1992414357@qq.com> | 2025-10-29 15:24:46 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2025-10-29 15:24:46 +0800 |
| commit | eb167d3792e6af987425508dc806595f6be1f79c (patch) | |
| tree | 178eebe31f03683a6950d37562409827d5ac43bb /crates/vcs_data/src/data/local.rs | |
| parent | 805a2e38b09267f57213310af602c4ad4b51a5ac (diff) | |
Make config fields thread-safe with Arc<Mutex>
- Change LocalWorkspace config to Arc<Mutex<LocalConfig>> - Change Vault
config to Arc<VaultConfig> - Add config accessor methods for both
structs - Update initialization methods to wrap config in Arc/Mutex
Diffstat (limited to 'crates/vcs_data/src/data/local.rs')
| -rw-r--r-- | crates/vcs_data/src/data/local.rs | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/crates/vcs_data/src/data/local.rs b/crates/vcs_data/src/data/local.rs index c93bd2b..fb43042 100644 --- a/crates/vcs_data/src/data/local.rs +++ b/crates/vcs_data/src/data/local.rs @@ -1,7 +1,7 @@ -use std::{env::current_dir, path::PathBuf}; +use std::{env::current_dir, path::PathBuf, sync::Arc}; use cfg_file::config::ConfigFile; -use tokio::fs; +use tokio::{fs, sync::Mutex}; use crate::{ constants::{CLIENT_FILE_README, CLIENT_FILE_WORKSPACE}, @@ -12,7 +12,7 @@ use crate::{ pub mod config; pub struct LocalWorkspace { - config: LocalConfig, + config: Arc<Mutex<LocalConfig>>, local_path: PathBuf, } @@ -25,13 +25,19 @@ impl LocalWorkspace { /// Initialize local workspace. pub fn init(config: LocalConfig, local_path: impl Into<PathBuf>) -> Option<Self> { let local_path = find_local_path(local_path)?; - Some(Self { config, local_path }) + Some(Self { + config: Arc::new(Mutex::new(config)), + local_path, + }) } /// Initialize local workspace in the current directory. pub fn init_current_dir(config: LocalConfig) -> Option<Self> { let local_path = current_local_path()?; - Some(Self { config, local_path }) + Some(Self { + config: Arc::new(Mutex::new(config)), + local_path, + }) } /// Setup local workspace @@ -92,6 +98,11 @@ Without these credentials, the server will reject all access requests. Ok(()) } + /// Get a reference to the local configuration. + pub fn config(&self) -> Arc<Mutex<LocalConfig>> { + self.config.clone() + } + /// Setup local workspace in current directory pub async fn setup_local_workspace_current_dir() -> Result<(), std::io::Error> { Self::setup_local_workspace(current_dir()?).await?; |
