Skip to content

vfs.vfs_nested #

Nested Filesystem Implementation (vfs_nested)

A virtual filesystem implementation that allows mounting multiple VFS implementations at different path prefixes, creating a unified filesystem view.

Features

  • Mount multiple VFS implementations
  • Path-based routing to appropriate implementations
  • Transparent operation across mounted filesystems
  • Hierarchical organization
  • Cross-implementation file operations
  • Virtual root directory showing mount points

Implementation Details

Structure

vfs_nested/
├── vfsnested.v          # Core implementation
└── nested_test.v        # Implementation tests

Key Components

  • NestedVFS: Main implementation struct that manages mounted filesystems
  • RootEntry: Special entry type representing the root directory
  • MountEntry: Special entry type representing mounted filesystem points

Usage

import vfs
import vfs_nested

fn main() ! {
    mut nested := vfs_nested.new()
    mut local_fs := vfs.new_vfs('local', '/tmp/local')!
    nested.add_vfs('/local', local_fs)!
    nested.file_create('/local/test.txt')!
}

Limitations

  • Cannot rename/move files across different implementations
  • Symlinks must be contained within a single implementation
  • No atomic operations across implementations
  • Mount points are fixed after creation

fn new #

fn new() &NestedVFS

new creates a new NestedVFS instance

fn (RootEntry) is_dir #

fn (self &RootEntry) is_dir() bool

is_dir returns true if the entry is a directory

fn (RootEntry) is_file #

fn (self &RootEntry) is_file() bool

is_file returns true if the entry is a file

struct MountEntry #

struct MountEntry {
pub mut:
	metadata vfs.Metadata
	impl     vfs.VFSImplementation
}

fn (MountEntry) is_dir #

fn (self &MountEntry) is_dir() bool

is_dir returns true if the entry is a directory

fn (MountEntry) is_file #

fn (self &MountEntry) is_file() bool

is_file returns true if the entry is a file

struct NestedEntry #

struct NestedEntry {
pub mut:
	original vfs.FSEntry
	prefix   string
}

NestedEntry wraps an FSEntry from a sub VFS and prefixes its path

fn (NestedEntry) is_dir #

fn (self &NestedEntry) is_dir() bool

is_dir returns true if the entry is a directory

fn (NestedEntry) is_file #

fn (self &NestedEntry) is_file() bool

is_file returns true if the entry is a file

struct NestedVFS #

struct NestedVFS {
mut:
	vfs_map map[string]vfs.VFSImplementation @[skip] // Map of path prefixes to VFS implementations
}

NestedVFS represents a VFS that can contain multiple nested VFS instances

fn (NestedVFS) add_vfs #

fn (mut self NestedVFS) add_vfs(prefix string, impl vfs.VFSImplementation) !

add_vfs adds a new VFS implementation at the specified path prefix

fn (NestedVFS) root_get #

fn (mut self NestedVFS) root_get() !vfs.FSEntry

Implementation of VFSImplementation interface

fn (NestedVFS) delete #

fn (mut self NestedVFS) delete(path string) !

fn (NestedVFS) file_create #

fn (mut self NestedVFS) file_create(path string) !vfs.FSEntry

fn (NestedVFS) file_read #

fn (mut self NestedVFS) file_read(path string) ![]u8

fn (NestedVFS) file_write #

fn (mut self NestedVFS) file_write(path string, data []u8) !

fn (NestedVFS) file_delete #

fn (mut self NestedVFS) file_delete(path string) !

fn (NestedVFS) dir_create #

fn (mut self NestedVFS) dir_create(path string) !vfs.FSEntry

fn (NestedVFS) dir_list #

fn (mut self NestedVFS) dir_list(path string) ![]vfs.FSEntry

fn (NestedVFS) dir_delete #

fn (mut self NestedVFS) dir_delete(path string) !

fn (NestedVFS) exists #

fn (mut self NestedVFS) exists(path string) bool

fn (NestedVFS) get #

fn (mut self NestedVFS) get(path string) !vfs.FSEntry

fn (NestedVFS) rename #

fn (mut self NestedVFS) rename(old_path string, new_path string) !vfs.FSEntry

fn (NestedVFS) copy #

fn (mut self NestedVFS) copy(src_path string, dst_path string) !vfs.FSEntry

fn (NestedVFS) move #

fn (mut self NestedVFS) move(src_path string, dst_path string) !vfs.FSEntry

fn (NestedVFS) destroy #

fn (mut self NestedVFS) destroy() !