pig/workspace/vfs
Virtual filesystem operations for pig workspace.
File and directory operations backed by SQLite tables:
vfs_inode— file metadata (mode, size, mtime)vfs_dentry— directory tree (name -> inode mapping)vfs_data— file content (chunked blobs)
Types
Errors from VFS operations.
pub type Error {
SqlError(sqlight.Error)
NotFound(path: String)
NotEmpty(path: String)
AlreadyExists(path: String)
InvalidPath(path: String)
}
Constructors
-
SqlError(sqlight.Error) -
NotFound(path: String) -
NotEmpty(path: String) -
AlreadyExists(path: String) -
InvalidPath(path: String)
Values
pub fn delete_file(
conn: sqlight.Connection,
path: String,
) -> Result(Nil, Error)
Delete a file or empty directory.
pub fn grep(
conn: sqlight.Connection,
pattern: String,
path: String,
include: String,
max_results: Int,
) -> Result(List(GrepMatch), Error)
Search file contents for a substring pattern.
Returns matching lines with their file path and line number.
The database does the heavy lifting: a single SQL query uses a
recursive CTE to walk the directory tree, reassembles file content
from chunks via group_concat, and filters with LIKE. Only files
that contain a match are read back into Gleam for line-level
extraction.
Parameters:
- pattern: substring to search for
- path: directory to search under (empty or “/” for root, can be a file)
- include: GLOB pattern to filter file paths (e.g., “*.py”)
- max_results: maximum number of matching lines (0 = unlimited)
pub fn list_directory(
conn: sqlight.Connection,
path: String,
) -> Result(List(String), Error)
List entries in a directory, sorted alphabetically.
pub fn mkdir(
conn: sqlight.Connection,
path: String,
) -> Result(Nil, Error)
Create a directory at the given path.
pub fn read_file(
conn: sqlight.Connection,
path: String,
) -> Result(String, Error)
Read the full content of a file.
pub fn read_file_lines(
conn: sqlight.Connection,
path: String,
offset: Int,
limit: Int,
) -> Result(String, Error)
Read lines with offset/limit, formatted as “N\tline_content” (0-indexed).
pub fn write_file(
conn: sqlight.Connection,
path: String,
content: String,
) -> Result(Nil, Error)
Write content to a file. Creates if missing, overwrites if exists.