Skip to main content

VirtualFileSystem

Struct VirtualFileSystem 

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

Virtual filesystem manager for lessons

Implementations§

Source§

impl VirtualFileSystem

Source

pub fn new(lesson_id: &str, session_id: &str) -> Result<Self>

Create a new virtual filesystem for a lesson

Source

pub fn resolve_path(&self, virtual_path: &str) -> Result<PathBuf>

Get the real filesystem path for a virtual path.

All ./.. components are resolved lexically and the result is guaranteed to be contained within the sandbox root; paths that would escape it (e.g. ../../../../etc/hostname) return an error.

Source

pub fn get_current_dir(&self) -> &Path

Get current directory (virtual path)

Source

pub fn get_current_dir_real(&self) -> PathBuf

Get current directory (real filesystem path)

Source

pub fn change_directory(&mut self, path: &str) -> Result<String>

Change directory (returns new virtual path)

Source

pub fn list_directory(&self, path: Option<&str>) -> Result<Vec<DirEntry>>

List directory contents

Source

pub fn get_tree(&self, max_depth: usize) -> Vec<TreeNode>

Get directory tree structure

Source

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

Read file contents (cat command)

Source

pub fn create_directory(&self, path: &str, parents: bool) -> Result<()>

Create directory (mkdir command)

Source

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

Create or update file (touch command)

Source

pub fn remove(&self, path: &str, recursive: bool, force: bool) -> Result<()>

Remove file or directory (rm command)

Source

pub fn move_item(&self, source: &str, destination: &str) -> Result<()>

Move or rename file/directory (mv command)

Source

pub fn copy( &self, source: &str, destination: &str, recursive: bool, ) -> Result<()>

Copy file or directory (cp command)

Source

pub fn grep_file( &self, pattern: &str, path: &str, case_insensitive: bool, ) -> Result<Vec<(usize, String)>>

Search a file for lines containing pattern (grep command).

Returns the matching lines as (line_number, line) pairs (line numbers are 1-based). Matching is plain substring search; pass case_insensitive for -i behavior.

Source

pub fn head_file(&self, path: &str, n: usize) -> Result<String>

Return the first n lines of a file (head command)

Source

pub fn tail_file(&self, path: &str, n: usize) -> Result<String>

Return the last n lines of a file (tail command)

Source

pub fn wc_file(&self, path: &str) -> Result<(usize, usize, usize)>

Count lines, words and bytes of a file (wc command).

Returns (lines, words, bytes).

Source

pub fn write_file(&self, path: &str, content: &str, append: bool) -> Result<()>

Write content to file (for echo redirection, etc.)

Source

pub fn seed_setup(&self, files: &[SetupFile]) -> Result<()>

Seed lesson starter files (the lesson’s setup list) into the sandbox, creating parent directories as needed. Paths are resolved through the same containment checks as every other operation, so a malicious setup path cannot escape the sandbox.

Source

pub fn cleanup(&self) -> Result<()>

Clean up virtual filesystem

Trait Implementations§

Source§

impl Drop for VirtualFileSystem

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.