pub struct FsInterface { /* private fields */ }Expand description
High-level filesystem interface with staging support.
This is the recommended way to interact with Heroforge repositories for filesystem-like operations. It provides:
- Fast writes via staging directory
- Layered reads (staging → database)
- Automatic background commits
- Partial file updates (read-modify-write)
- Thread-safe operations via RwLock
Implementations§
Source§impl FsInterface
impl FsInterface
Sourcepub fn new(repo: Arc<Repository>, author: &str) -> FsResult<Self>
pub fn new(repo: Arc<Repository>, author: &str) -> FsResult<Self>
Create a new FsInterface for a repository.
§Arguments
repo- The repository to operate onauthor- Author name for all commits from this interface
§Example
use heroforge_core::Repository;
use heroforge_core::fs::FsInterface;
use std::sync::Arc;
let repo = Arc::new(Repository::open_rw("project.forge")?);
let fs = FsInterface::new(repo, "developer@example.com")?;Sourcepub fn with_config(
repo: Arc<Repository>,
author: &str,
config: CommitConfig,
) -> FsResult<Self>
pub fn with_config( repo: Arc<Repository>, author: &str, config: CommitConfig, ) -> FsResult<Self>
Create a new FsInterface with custom configuration.
Sourcepub fn without_timer(repo: Arc<Repository>, author: &str) -> FsResult<Self>
pub fn without_timer(repo: Arc<Repository>, author: &str) -> FsResult<Self>
Create a new FsInterface without background commit timer. Useful for testing or manual commit control.
Sourcepub fn status(&self) -> FsInterfaceStatus
pub fn status(&self) -> FsInterfaceStatus
Get the current status
Get the author name
Sourcepub fn has_changes(&self) -> bool
pub fn has_changes(&self) -> bool
Check if there are uncommitted changes
Sourcepub fn exists(&self, path: &str) -> FsResult<bool>
pub fn exists(&self, path: &str) -> FsResult<bool>
Check if a path exists (in staging or database).
Sourcepub fn stat(&self, path: &str) -> FsResult<FileMetadata>
pub fn stat(&self, path: &str) -> FsResult<FileMetadata>
Get file metadata.
Sourcepub fn read_file(&self, path: &str) -> FsResult<Vec<u8>>
pub fn read_file(&self, path: &str) -> FsResult<Vec<u8>>
Read file content as bytes.
Checks staging directory first, then falls back to database.
Sourcepub fn read_file_string(&self, path: &str) -> FsResult<String>
pub fn read_file_string(&self, path: &str) -> FsResult<String>
Read file content as string.
Sourcepub fn find(&self, pattern: &str) -> FsResult<FindResults>
pub fn find(&self, pattern: &str) -> FsResult<FindResults>
Find files matching a glob pattern.
Sourcepub fn disk_usage(&self, path: &str) -> FsResult<u64>
pub fn disk_usage(&self, path: &str) -> FsResult<u64>
Calculate disk usage of a path.
Sourcepub fn count_files(&self, pattern: &str) -> FsResult<usize>
pub fn count_files(&self, pattern: &str) -> FsResult<usize>
Count files matching a pattern.
Sourcepub fn write_file(&self, path: &str, content: &[u8]) -> FsResult<()>
pub fn write_file(&self, path: &str, content: &[u8]) -> FsResult<()>
Write file content.
The file is written to the staging directory immediately.
It will be committed to the database during the next auto-commit
or when commit() is called.
Sourcepub fn write_file_string(&self, path: &str, content: &str) -> FsResult<()>
pub fn write_file_string(&self, path: &str, content: &str) -> FsResult<()>
Write file content from a string.
Sourcepub fn write_at(&self, path: &str, offset: u64, data: &[u8]) -> FsResult<()>
pub fn write_at(&self, path: &str, offset: u64, data: &[u8]) -> FsResult<()>
Write at a specific offset in a file (partial update).
If the file exists only in the database, it will be promoted to staging first. This implements the read-modify-write pattern described in the spec.
Sourcepub fn delete_file(&self, path: &str) -> FsResult<()>
pub fn delete_file(&self, path: &str) -> FsResult<()>
Delete a file.
Sourcepub fn delete_dir(&self, path: &str) -> FsResult<()>
pub fn delete_dir(&self, path: &str) -> FsResult<()>
Delete a directory recursively.
Sourcepub fn commit(&self) -> FsResult<String>
pub fn commit(&self) -> FsResult<String>
Force an immediate commit of all staged changes.
Returns the commit hash, or “no-changes” if nothing was staged.
Sourcepub fn commit_with_message(&self, message: &str) -> FsResult<String>
pub fn commit_with_message(&self, message: &str) -> FsResult<String>
Force a commit with a custom message.
Sourcepub fn switch_branch(&mut self, branch: &str) -> FsResult<()>
pub fn switch_branch(&mut self, branch: &str) -> FsResult<()>
Switch to a different branch.
Forces a commit of any staged changes before switching.