Skip to main content

VirtualFs

Struct VirtualFs 

Source
pub struct VirtualFs { /* private fields */ }
Expand description

Sandboxed filesystem for a single knowledge base.

All file operations are constrained to the root directory. Path traversal attempts are rejected.

Implementations§

Source§

impl VirtualFs

Source

pub fn new(root: PathBuf) -> Result<Self>

Create a new VirtualFs rooted at the given directory.

Creates the directory if it doesn’t exist.

Source

pub fn with_quota(self, quota_kb: i64) -> Self

Set a storage quota in kilobytes (0 = unlimited).

Source

pub fn root(&self) -> &Path

Get the root path.

Source

pub fn quota_kb(&self) -> i64

Get the configured quota in KB (0 = unlimited).

Source

pub fn safe_path(&self, dir: &str, filename: &str) -> Result<PathBuf, FsError>

Build a safe absolute path from a directory and filename.

Rejects path traversal attempts (e.g., ../../etc/passwd).

Source

pub fn read_path(&self, path: &str) -> Result<String, FsError>

Read file content by POSIX-style relative path. path examples: “Rust.md”, “brain/Rust.md”, “journal/2024.08 August.md”

Source

pub fn write_path(&self, path: &str, content: &str) -> Result<(), FsError>

Write file content by POSIX-style relative path.

Source

pub fn delete_path(&self, path: &str) -> Result<(), FsError>

Delete file by POSIX-style relative path.

Source

pub fn rename_path(&self, old_path: &str, new_path: &str) -> Result<(), FsError>

Rename/move file by POSIX-style relative paths.

Source

pub fn exists_path(&self, path: &str) -> Result<bool, FsError>

Check if file exists by POSIX-style relative path.

Source

pub fn mtime_path(&self, path: &str) -> Result<i64, FsError>

Get mtime by POSIX-style relative path.

Source

pub fn exists(&self, dir: &str, filename: &str) -> Result<bool, FsError>

Check if a file or directory exists.

Source

pub fn read(&self, dir: &str, filename: &str) -> Result<String, FsError>

Read file contents as a string.

Source

pub fn write( &self, dir: &str, filename: &str, content: &str, ) -> Result<(), FsError>

Write content to a file, creating parent directories as needed.

Source

pub fn read_bytes(&self, dir: &str, filename: &str) -> Result<Vec<u8>, FsError>

Read a file as raw bytes.

Source

pub fn write_bytes( &self, dir: &str, filename: &str, data: &[u8], ) -> Result<(), FsError>

Write raw bytes to a file, creating parent directories as needed. Respects the configured quota (same logic as write()).

Source

pub fn read_path_bytes(&self, path: &str) -> Result<Vec<u8>, FsError>

Read a file by POSIX path as raw bytes.

Source

pub fn write_path_bytes(&self, path: &str, data: &[u8]) -> Result<(), FsError>

Write raw bytes to a file by POSIX path.

Source

pub fn del(&self, dir: &str, filename: &str) -> Result<(), FsError>

Delete a file.

Source

pub fn rename( &self, old_dir: &str, old_filename: &str, new_dir: &str, new_filename: &str, ) -> Result<(), FsError>

Rename/move a file.

Source

pub fn make_dir(&self, dir: &str) -> Result<(), FsError>

Create a directory.

Source

pub fn touch(&self, dir: &str, filename: &str) -> Result<(), FsError>

Touch a file: create if missing, update mtime if present.

Source

pub fn ctime(&self, dir: &str, filename: &str) -> Result<i64, FsError>

Get the ctime/mtime of a file in milliseconds since epoch.

Source

pub fn mtime(&self, dir: &str, filename: &str) -> Result<i64, FsError>

Get the modification time of a file in milliseconds since epoch.

Source

pub fn mtimes( &self, root: &str, extensions: &[&str], ) -> Result<HashMap<String, i64>, FsError>

Recursively collect mtimes for all files with given extensions.

Source

pub fn files_and_dirs(&self, dir: &str) -> Result<Vec<FileEntry>, FsError>

List files and directories in a directory.

Source

pub fn dirs(&self) -> Result<Vec<FileEntry>, FsError>

List only directories in the root.

Source

pub fn is_multiline(&self, dir: &str, filename: &str) -> Result<bool, FsError>

Check if a file has non-whitespace content.

Source

pub fn create_system_dirs(&self) -> Result<(), FsError>

Create the standard system directories (archive, media, journal).

Source

pub fn unhash(&self, dir: &str, filename_hash: &str) -> Result<String, FsError>

Reverse a hash to find the original filename.

Source

pub fn search_files_by_name( &self, query: &str, ) -> Result<Vec<FileEntry>, FsError>

Search files by name across the entire knowledge base.

Trait Implementations§

Source§

impl Clone for VirtualFs

Source§

fn clone(&self) -> VirtualFs

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VirtualFs

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

Source§

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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more