FsInterface

Struct FsInterface 

Source
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

Source

pub fn new(repo: Arc<Repository>, author: &str) -> FsResult<Self>

Create a new FsInterface for a repository.

§Arguments
  • repo - The repository to operate on
  • author - 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")?;
Source

pub fn with_config( repo: Arc<Repository>, author: &str, config: CommitConfig, ) -> FsResult<Self>

Create a new FsInterface with custom configuration.

Source

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.

Source

pub fn status(&self) -> FsInterfaceStatus

Get the current status

Source

pub fn author(&self) -> String

Get the author name

Source

pub fn branch(&self) -> &str

Get the current branch

Source

pub fn has_changes(&self) -> bool

Check if there are uncommitted changes

Source

pub fn exists(&self, path: &str) -> FsResult<bool>

Check if a path exists (in staging or database).

Source

pub fn is_dir(&self, path: &str) -> FsResult<bool>

Check if a path is a directory.

Source

pub fn is_file(&self, path: &str) -> FsResult<bool>

Check if a path is a file.

Source

pub fn stat(&self, path: &str) -> FsResult<FileMetadata>

Get file metadata.

Source

pub fn read_file(&self, path: &str) -> FsResult<Vec<u8>>

Read file content as bytes.

Checks staging directory first, then falls back to database.

Source

pub fn read_file_string(&self, path: &str) -> FsResult<String>

Read file content as string.

Source

pub fn list_dir(&self, path: &str) -> FsResult<Vec<DirectoryEntry>>

List directory contents.

Source

pub fn find(&self, pattern: &str) -> FsResult<FindResults>

Find files matching a glob pattern.

Source

pub fn disk_usage(&self, path: &str) -> FsResult<u64>

Calculate disk usage of a path.

Source

pub fn count_files(&self, pattern: &str) -> FsResult<usize>

Count files matching a pattern.

Source

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.

Source

pub fn write_file_string(&self, path: &str, content: &str) -> FsResult<()>

Write file content from a string.

Source

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.

Source

pub fn delete_file(&self, path: &str) -> FsResult<()>

Delete a file.

Source

pub fn delete_dir(&self, path: &str) -> FsResult<()>

Delete a directory recursively.

Source

pub fn copy_file(&self, src: &str, dst: &str) -> FsResult<()>

Copy a file.

Source

pub fn move_file(&self, src: &str, dst: &str) -> FsResult<()>

Move a file.

Source

pub fn copy_dir(&self, src: &str, dst: &str) -> FsResult<()>

Copy a directory recursively.

Source

pub fn move_dir(&self, src: &str, dst: &str) -> FsResult<()>

Move a directory recursively.

Source

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.

Source

pub fn commit_with_message(&self, message: &str) -> FsResult<String>

Force a commit with a custom message.

Source

pub fn switch_branch(&mut self, branch: &str) -> FsResult<()>

Switch to a different branch.

Forces a commit of any staged changes before switching.

Trait Implementations§

Source§

impl Drop for FsInterface

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.