summaryrefslogtreecommitdiff
path: root/systems
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-03-15 19:01:44 +0800
committer魏曹先生 <1992414357@qq.com>2026-03-15 19:01:44 +0800
commit2c61872cea2ad06e2d49f1ddd457ebc9b795fb7d (patch)
tree9f7e3416782e4fc368597e1189e272ec9b364c86 /systems
parentcc9bf0e13d75b9938b67da5df8135369374dc36d (diff)
Move ID alias methods to separate module
Diffstat (limited to 'systems')
-rw-r--r--systems/workspace/src/workspace/manager.rs53
-rw-r--r--systems/workspace/src/workspace/manager/id_aliases.rs54
2 files changed, 57 insertions, 50 deletions
diff --git a/systems/workspace/src/workspace/manager.rs b/systems/workspace/src/workspace/manager.rs
index 528f266..adee9b7 100644
--- a/systems/workspace/src/workspace/manager.rs
+++ b/systems/workspace/src/workspace/manager.rs
@@ -1,8 +1,9 @@
use crate::workspace::{Workspace, config::WorkspaceConfig, error::WorkspaceOperationError};
use asset_system::asset::ReadOnlyAsset;
-use constants::workspace::{dirs::workspace_dir_id_mapping, files::workspace_file_config};
+use constants::workspace::files::workspace_file_config;
use framework::space::Space;
-use sheet_system::index_source::{IndexSource, alias::IndexSourceAliasesManager};
+
+pub mod id_aliases;
pub struct WorkspaceManager {
space: Space<Workspace>,
@@ -36,52 +37,4 @@ 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))
- }
}
diff --git a/systems/workspace/src/workspace/manager/id_aliases.rs b/systems/workspace/src/workspace/manager/id_aliases.rs
new file mode 100644
index 0000000..f3f83d2
--- /dev/null
+++ b/systems/workspace/src/workspace/manager/id_aliases.rs
@@ -0,0 +1,54 @@
+use constants::workspace::dirs::workspace_dir_id_mapping;
+use sheet_system::index_source::{IndexSource, alias::IndexSourceAliasesManager};
+
+use crate::workspace::{error::WorkspaceOperationError, manager::WorkspaceManager};
+
+impl WorkspaceManager {
+ /// 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))
+ }
+}