diff options
Diffstat (limited to 'systems/workspace')
| -rw-r--r-- | systems/workspace/Cargo.toml | 1 | ||||
| -rw-r--r-- | systems/workspace/src/workspace/error.rs | 4 | ||||
| -rw-r--r-- | systems/workspace/src/workspace/manager.rs | 51 |
3 files changed, 55 insertions, 1 deletions
diff --git a/systems/workspace/Cargo.toml b/systems/workspace/Cargo.toml index c394bb3..c601370 100644 --- a/systems/workspace/Cargo.toml +++ b/systems/workspace/Cargo.toml @@ -8,6 +8,7 @@ asset_system = { path = "../_asset" } config_system = { path = "../_config" } constants = { path = "../_constants" } framework = { path = "../_framework" } +sheet_system = { path = "../sheet" } serde.workspace = true thiserror.workspace = true diff --git a/systems/workspace/src/workspace/error.rs b/systems/workspace/src/workspace/error.rs index 495558b..0910392 100644 --- a/systems/workspace/src/workspace/error.rs +++ b/systems/workspace/src/workspace/error.rs @@ -1,5 +1,6 @@ use asset_system::error::{DataApplyError, DataReadError, DataWriteError, HandleLockError}; use framework::space::error::SpaceError; +use sheet_system::index_source::error::IDAliasError; #[derive(thiserror::Error, Debug)] pub enum WorkspaceOperationError { @@ -26,6 +27,9 @@ pub enum WorkspaceOperationError { #[error("Data apply error: {0}")] DataApply(#[from] DataApplyError), + + #[error("ID alias error: {0}")] + IDAliasError(#[from] IDAliasError), } impl From<SpaceError> for WorkspaceOperationError { diff --git a/systems/workspace/src/workspace/manager.rs b/systems/workspace/src/workspace/manager.rs index 9e319a1..528f266 100644 --- a/systems/workspace/src/workspace/manager.rs +++ b/systems/workspace/src/workspace/manager.rs @@ -1,7 +1,8 @@ use crate::workspace::{Workspace, config::WorkspaceConfig, error::WorkspaceOperationError}; use asset_system::asset::ReadOnlyAsset; -use constants::workspace::files::workspace_file_config; +use constants::workspace::{dirs::workspace_dir_id_mapping, files::workspace_file_config}; use framework::space::Space; +use sheet_system::index_source::{IndexSource, alias::IndexSourceAliasesManager}; pub struct WorkspaceManager { space: Space<Workspace>, @@ -35,4 +36,52 @@ impl WorkspaceManager { let asset = ReadOnlyAsset::from(config_path); Ok(asset) } + + /// Attempt to convert an index source to a remote namespace. + /// This method takes an `IndexSource` and tries to map it to a remote namespace + /// using the workspace's ID alias directory. If not found, the original + /// `IndexSource` is returned as a fallback. + /// + /// - `index_source` - The index source to convert + /// - `Result<IndexSource, WorkspaceOperationError>` - The converted index source on success, + /// or the original index source if alias fails. Returns an error if there's + /// a problem accessing the workspace directory. + pub async fn try_to_remote_index( + &self, + index_source: IndexSource, + ) -> Result<IndexSource, WorkspaceOperationError> { + let aliases_dir = self.get_space().local_path(workspace_dir_id_mapping())?; + Ok(match index_source.to_remote_namespace(aliases_dir).await { + Ok(index_source) => index_source, + Err((index_source, _)) => index_source, + }) + } + + /// Write a alias between local and remote IDs + pub async fn write_id_alias( + &self, + local_id: u32, + remote_id: u32, + ) -> Result<(), WorkspaceOperationError> { + let aliases_dir = self.get_space().local_path(workspace_dir_id_mapping())?; + IndexSourceAliasesManager::write_alias(aliases_dir, local_id, remote_id) + .await + .map_err(|e| WorkspaceOperationError::IDAliasError(e)) + } + + /// Delete a alias between local and remote IDs + pub async fn delete_id_alias(&self, local_id: u32) -> Result<(), WorkspaceOperationError> { + let aliases_dir = self.get_space().local_path(workspace_dir_id_mapping())?; + IndexSourceAliasesManager::delete_alias(aliases_dir, local_id) + .await + .map_err(|e| WorkspaceOperationError::IDAliasError(e)) + } + + /// Check if a alias exists between local and remote IDs + pub async fn id_aliases_exists(&self, local_id: u32) -> Result<bool, WorkspaceOperationError> { + let aliases_dir = self.get_space().local_path(workspace_dir_id_mapping())?; + IndexSourceAliasesManager::alias_exists(aliases_dir, local_id) + .await + .map_err(|e| WorkspaceOperationError::IDAliasError(e)) + } } |
