pub struct VirtualFileSystem { /* private fields */ }Expand description
Virtual filesystem manager for lessons
Implementations§
Source§impl VirtualFileSystem
impl VirtualFileSystem
Sourcepub fn new(lesson_id: &str, session_id: &str) -> Result<Self>
pub fn new(lesson_id: &str, session_id: &str) -> Result<Self>
Create a new virtual filesystem for a lesson
Sourcepub fn resolve_path(&self, virtual_path: &str) -> Result<PathBuf>
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.
Sourcepub fn get_current_dir(&self) -> &Path
pub fn get_current_dir(&self) -> &Path
Get current directory (virtual path)
Sourcepub fn get_current_dir_real(&self) -> PathBuf
pub fn get_current_dir_real(&self) -> PathBuf
Get current directory (real filesystem path)
Sourcepub fn change_directory(&mut self, path: &str) -> Result<String>
pub fn change_directory(&mut self, path: &str) -> Result<String>
Change directory (returns new virtual path)
Sourcepub fn list_directory(&self, path: Option<&str>) -> Result<Vec<DirEntry>>
pub fn list_directory(&self, path: Option<&str>) -> Result<Vec<DirEntry>>
List directory contents
Sourcepub fn create_directory(&self, path: &str, parents: bool) -> Result<()>
pub fn create_directory(&self, path: &str, parents: bool) -> Result<()>
Create directory (mkdir command)
Sourcepub fn touch_file(&self, path: &str) -> Result<()>
pub fn touch_file(&self, path: &str) -> Result<()>
Create or update file (touch command)
Sourcepub fn remove(&self, path: &str, recursive: bool, force: bool) -> Result<()>
pub fn remove(&self, path: &str, recursive: bool, force: bool) -> Result<()>
Remove file or directory (rm command)
Sourcepub fn move_item(&self, source: &str, destination: &str) -> Result<()>
pub fn move_item(&self, source: &str, destination: &str) -> Result<()>
Move or rename file/directory (mv command)
Sourcepub fn copy(
&self,
source: &str,
destination: &str,
recursive: bool,
) -> Result<()>
pub fn copy( &self, source: &str, destination: &str, recursive: bool, ) -> Result<()>
Copy file or directory (cp command)
Sourcepub fn grep_file(
&self,
pattern: &str,
path: &str,
case_insensitive: bool,
) -> Result<Vec<(usize, String)>>
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.
Sourcepub fn head_file(&self, path: &str, n: usize) -> Result<String>
pub fn head_file(&self, path: &str, n: usize) -> Result<String>
Return the first n lines of a file (head command)
Sourcepub fn tail_file(&self, path: &str, n: usize) -> Result<String>
pub fn tail_file(&self, path: &str, n: usize) -> Result<String>
Return the last n lines of a file (tail command)
Sourcepub fn wc_file(&self, path: &str) -> Result<(usize, usize, usize)>
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).
Sourcepub fn write_file(&self, path: &str, content: &str, append: bool) -> Result<()>
pub fn write_file(&self, path: &str, content: &str, append: bool) -> Result<()>
Write content to file (for echo redirection, etc.)
Sourcepub fn seed_setup(&self, files: &[SetupFile]) -> Result<()>
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.