pub struct FileSystem { /* private fields */ }Expand description
Main filesystem interface for Heroforge repositories
This provides a filesystem-like API over the Heroforge repository storage. All operations are atomic and maintain version history.
§Thread Safety
FileSystem is thread-safe. Multiple threads can read simultaneously,
but writes are serialized through an internal mutex.
§Example
use heroforge_core::Repository;
use heroforge_core::fs::FileSystem;
use std::sync::Arc;
fn main() -> heroforge_core::Result<()> {
let repo = Arc::new(Repository::open_rw("project.forge")?);
let fs = FileSystem::new(repo);
// Read without commit
let exists = fs.exists("README.md")?;
if !exists {
// Write with auto-commit
fs.write_file("README.md", b"# My Project", "admin", "Initialize README")?;
}
Ok(())
}Implementations§
Source§impl FileSystem
impl FileSystem
Sourcepub fn new(repo: Arc<Repository>) -> Self
pub fn new(repo: Arc<Repository>) -> Self
Create a new filesystem interface for a repository
Sourcepub fn status(&self) -> FileSystemStatus
pub fn status(&self) -> FileSystemStatus
Get current status
Sourcepub fn stat(&self, path: &str) -> FsResult<FileMetadata>
pub fn stat(&self, path: &str) -> FsResult<FileMetadata>
Sourcepub fn read_file_string(&self, path: &str) -> FsResult<String>
pub fn read_file_string(&self, path: &str) -> FsResult<String>
Sourcepub fn write_file(
&self,
path: &str,
content: &[u8],
author: &str,
message: &str,
) -> FsResult<String>
pub fn write_file( &self, path: &str, content: &[u8], author: &str, message: &str, ) -> FsResult<String>
Sourcepub fn copy_file(
&self,
src: &str,
dst: &str,
author: &str,
message: &str,
) -> FsResult<String>
pub fn copy_file( &self, src: &str, dst: &str, author: &str, message: &str, ) -> FsResult<String>
Copy a file
Sourcepub fn copy_dir(
&self,
src: &str,
dst: &str,
author: &str,
message: &str,
) -> FsResult<String>
pub fn copy_dir( &self, src: &str, dst: &str, author: &str, message: &str, ) -> FsResult<String>
Copy a directory recursively
Sourcepub fn move_file(
&self,
src: &str,
dst: &str,
author: &str,
message: &str,
) -> FsResult<String>
pub fn move_file( &self, src: &str, dst: &str, author: &str, message: &str, ) -> FsResult<String>
Move/rename a file
Sourcepub fn move_dir(
&self,
src: &str,
dst: &str,
author: &str,
message: &str,
) -> FsResult<String>
pub fn move_dir( &self, src: &str, dst: &str, author: &str, message: &str, ) -> FsResult<String>
Move/rename a directory
Sourcepub fn delete_file(
&self,
path: &str,
author: &str,
message: &str,
) -> FsResult<String>
pub fn delete_file( &self, path: &str, author: &str, message: &str, ) -> FsResult<String>
Delete a file
Sourcepub fn delete_dir(
&self,
path: &str,
author: &str,
message: &str,
) -> FsResult<String>
pub fn delete_dir( &self, path: &str, author: &str, message: &str, ) -> FsResult<String>
Delete a directory recursively
Sourcepub fn chmod(
&self,
path: &str,
permissions: FilePermissions,
author: &str,
message: &str,
) -> FsResult<String>
pub fn chmod( &self, path: &str, permissions: FilePermissions, author: &str, message: &str, ) -> FsResult<String>
Change file permissions
Sourcepub fn chmod_recursive(
&self,
path: &str,
permissions: FilePermissions,
author: &str,
message: &str,
) -> FsResult<String>
pub fn chmod_recursive( &self, path: &str, permissions: FilePermissions, author: &str, message: &str, ) -> FsResult<String>
Change permissions recursively
Sourcepub fn make_executable(
&self,
path: &str,
author: &str,
message: &str,
) -> FsResult<String>
pub fn make_executable( &self, path: &str, author: &str, message: &str, ) -> FsResult<String>
Make file executable
Sourcepub fn symlink(
&self,
link_path: &str,
target_path: &str,
author: &str,
message: &str,
) -> FsResult<String>
pub fn symlink( &self, link_path: &str, target_path: &str, author: &str, message: &str, ) -> FsResult<String>
Create a symbolic link
Sourcepub fn find(&self, pattern: &str) -> FsResult<FindResults>
pub fn find(&self, pattern: &str) -> FsResult<FindResults>
Sourcepub fn disk_usage(&self, path: &str) -> FsResult<u64>
pub fn disk_usage(&self, path: &str) -> FsResult<u64>
Sourcepub fn count_files(&self, pattern: &str) -> FsResult<usize>
pub fn count_files(&self, pattern: &str) -> FsResult<usize>
Sourcepub fn begin_transaction(&self) -> FsResult<Transaction>
pub fn begin_transaction(&self) -> FsResult<Transaction>
Begin a transaction for batch operations
§Returns
A transaction that can be used to group multiple operations
Sourcepub fn end_transaction(&self) -> FsResult<()>
pub fn end_transaction(&self) -> FsResult<()>
End the active transaction
Sourcepub fn has_active_transaction(&self) -> bool
pub fn has_active_transaction(&self) -> bool
Check if a transaction is active
Sourcepub fn active_transaction(&self) -> Option<Transaction>
pub fn active_transaction(&self) -> Option<Transaction>
Get the active transaction (if any)