diff options
Diffstat (limited to 'crates/vcs_data')
| -rw-r--r-- | crates/vcs_data/src/constants.rs | 13 | ||||
| -rw-r--r-- | crates/vcs_data/src/data/local.rs | 2 | ||||
| -rw-r--r-- | crates/vcs_data/src/data/vault.rs | 1 | ||||
| -rw-r--r-- | crates/vcs_data/src/data/vault/service.rs | 43 |
4 files changed, 53 insertions, 6 deletions
diff --git a/crates/vcs_data/src/constants.rs b/crates/vcs_data/src/constants.rs index 5e147c4..7514fe2 100644 --- a/crates/vcs_data/src/constants.rs +++ b/crates/vcs_data/src/constants.rs @@ -12,7 +12,7 @@ pub const VAULT_HOST_NAME: &str = "host"; // Server // Server - Vault (Main) -pub const SERVER_FILE_VAULT: &str = "./vault.toml"; // crates::env::vault::vault_config +pub const SERVER_FILE_VAULT: &str = "./vault.toml"; // Server - Sheets pub const REF_SHEET_NAME: &str = "ref"; @@ -22,8 +22,8 @@ pub const SERVER_FILE_SHEET: &str = "./sheets/{sheet-name}.yaml"; // Server - Members pub const SERVER_PATH_MEMBERS: &str = "./members/"; pub const SERVER_PATH_MEMBER_PUB: &str = "./key/"; -pub const SERVER_FILE_MEMBER_INFO: &str = "./members/{member_id}.toml"; // crates::env::member::manager -pub const SERVER_FILE_MEMBER_PUB: &str = "./key/{member_id}.pem"; // crates::utils::tcp_connection::instance +pub const SERVER_FILE_MEMBER_INFO: &str = "./members/{member_id}.toml"; +pub const SERVER_FILE_MEMBER_PUB: &str = "./key/{member_id}.pem"; // Server - Virtual File Storage pub const SERVER_PATH_VF_TEMP: &str = "./.temp/{temp_name}"; @@ -32,6 +32,9 @@ pub const SERVER_PATH_VF_STORAGE: &str = "./storage/{vf_index}/{vf_id}/"; pub const SERVER_FILE_VF_VERSION_INSTANCE: &str = "./storage/{vf_index}/{vf_id}/{vf_version}.rf"; pub const SERVER_FILE_VF_META: &str = "./storage/{vf_index}/{vf_id}/meta.yaml"; +// Server - Service +pub const SERVER_FILE_LOCKFILE: &str = "./.lock"; + pub const SERVER_FILE_README: &str = "./README.md"; // ------------------------------------------------------------------------------------- @@ -40,10 +43,10 @@ pub const SERVER_FILE_README: &str = "./README.md"; pub const CLIENT_PATH_WORKSPACE_ROOT: &str = "./.jv/"; // Client - Workspace (Main) -pub const CLIENT_FILE_WORKSPACE: &str = "./.jv/workspace.toml"; // crates::env::local::local_config +pub const CLIENT_FILE_WORKSPACE: &str = "./.jv/workspace.toml"; // Client - Other -pub const CLIENT_FILE_IGNOREFILES: &str = ".jgnore .gitignore"; // Support gitignore file. +pub const CLIENT_FILE_IGNOREFILES: &str = "IGNORE_RULES.toml"; pub const CLIENT_FILE_README: &str = "./README.md"; // ------------------------------------------------------------------------------------- diff --git a/crates/vcs_data/src/data/local.rs b/crates/vcs_data/src/data/local.rs index 1c99832..c93bd2b 100644 --- a/crates/vcs_data/src/data/local.rs +++ b/crates/vcs_data/src/data/local.rs @@ -93,7 +93,7 @@ Without these credentials, the server will reject all access requests. } /// Setup local workspace in current directory - pub async fn setup_local_workspacecurrent_dir() -> Result<(), std::io::Error> { + pub async fn setup_local_workspace_current_dir() -> Result<(), std::io::Error> { Self::setup_local_workspace(current_dir()?).await?; Ok(()) } diff --git a/crates/vcs_data/src/data/vault.rs b/crates/vcs_data/src/data/vault.rs index 5d17a81..80ebe1d 100644 --- a/crates/vcs_data/src/data/vault.rs +++ b/crates/vcs_data/src/data/vault.rs @@ -17,6 +17,7 @@ use crate::{ pub mod config; pub mod member; +pub mod service; pub mod sheets; pub mod virtual_file; diff --git a/crates/vcs_data/src/data/vault/service.rs b/crates/vcs_data/src/data/vault/service.rs new file mode 100644 index 0000000..9fdce85 --- /dev/null +++ b/crates/vcs_data/src/data/vault/service.rs @@ -0,0 +1,43 @@ +use std::path::PathBuf; + +use crate::{constants::SERVER_FILE_LOCKFILE, data::vault::Vault}; + +impl Vault { + /// Get the path of the lock file for the current Vault + pub fn lock_file_path(&self) -> PathBuf { + self.vault_path().join(SERVER_FILE_LOCKFILE) + } + + /// Check if the current Vault is locked + pub fn is_locked(&self) -> bool { + self.lock_file_path().exists() + } + + /// Lock the current Vault + pub fn lock(&self) -> Result<(), std::io::Error> { + if self.is_locked() { + return Err(std::io::Error::new( + std::io::ErrorKind::AlreadyExists, + format!( + "Vault is already locked at {}. \ + To unlock, please stop any running services. \ + If you are certain no services are running, \ + please delete this file", + self.lock_file_path().display() + ), + )); + } + std::fs::File::create(self.lock_file_path())?; + Ok(()) + } + + /// Unlock the current Vault + pub fn unlock(&self) -> Result<(), std::io::Error> { + if let Err(e) = std::fs::remove_file(self.lock_file_path()) { + if e.kind() != std::io::ErrorKind::NotFound { + return Err(e); + } + } + Ok(()) + } +} |
