fs

package
v0.5.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: Apache-2.0, BSD-3-Clause, MIT Imports: 12 Imported by: 17 modules, 7 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fs provides a virtual filesystem interface for SCALIBR scans and related helper functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRealPath added in v0.3.1

func GetRealPath(root *ScanRoot, path string, reader io.Reader) (string, error)

GetRealPath copies the file into an isolated temporary directory on the scanning host's filesystem and returns its absolute path. It is up to the caller to delete the temporary directory (filepath.Dir(realPath)) once they are done using it.

Prefer OpenOSPath or OpenOSFile when an isolated copy is not always required.

Sample code to delete the directory: ``` realPath := GetRealPath(...) dir := filepath.Dir(realPath)

if err := os.RemoveAll(dir); err != nil {
    log.Errorf("os.RemoveAll(%q): %v", dir, err)
}

func NewReaderAt added in v0.1.6

func NewReaderAt(ioReader io.Reader) (io.ReaderAt, error)

NewReaderAt converts an io.Reader into an io.ReaderAt.

func OpenOSFile added in v0.5.4

func OpenOSFile(root *ScanRoot, path string, reader io.Reader) (*os.File, func() error, error)

OpenOSFile returns an *os.File handle for the target file along with a cleanup function that closes the file and removes any temporary copy that had to be created. On real filesystems, it returns the *os.File opened directly from root.FS without copying the file to a temporary directory.

func OpenOSPath added in v0.5.4

func OpenOSPath(root *ScanRoot, path string, reader io.Reader) (string, func() error, error)

OpenOSPath returns a host filesystem path for the target file along with a cleanup function that removes any temporary copy that had to be created. On unconfined real filesystems (os.DirFS), it returns the in-place file path without copying; on confined or virtual filesystems, it copies the file into an isolated temporary directory so database engines cannot follow sibling (-wal/-journal/-shm) symlinks.

func SQLiteReadOnlyURI added in v0.5.4

func SQLiteReadOnlyURI(osPath string) string

SQLiteReadOnlyURI encodes a host filesystem path as a read-only, immutable SQLite file: URI. Escaping prevents special characters in host paths (such as '?') from injecting SQLite URI query parameters (e.g. _pragma), and immutable=1 allows reading WAL-mode databases in read-only or unprivileged directories without creating -wal/-shm sidecar files.

Types

type FS

type FS interface {
	fs.FS
	fs.ReadDirFS
	fs.StatFS
}

FS is a filesystem interface that allows the opening of files, reading of directories, and performing stat on files.

FS implementations may return ErrNotImplemented for `Open`, `ReadDir` and `Stat`. Extractor implementations must decide whether the error is fatal or can be ignored.

FS implementations MUST implement io.ReaderAt for opened files to enable random access.

func DirFS

func DirFS(root string) FS

DirFS returns an FS implementation that accesses the real filesystem at the given root, confined to root via os.Root. The underlying os.Root handle is opened lazily on first access and can be released via Close.

func Sub added in v0.5.4

func Sub(fsys FS, dir string) FS

Sub returns an FS corresponding to the subtree rooted at dir within fsys. This is analogous to io/fs.Sub but preserves the scalibr FS interface (ReadDir and Stat). dir must be a slash-separated, relative path. The returned FS performs no validation of the names it is given, so it should only be used with trusted paths.

type ScanRoot

type ScanRoot struct {
	// A virtual filesystem for file access, rooted at the scan root.
	FS FS
	// The path of the scan root. Empty if this is a virtual filesystem and the
	// scanning environment doesn't support the DirectFS requirement.
	Path string
}

ScanRoot defines a root directory to start a scan from. mounted to a local dir.

func RealFSScanRoot

func RealFSScanRoot(path string) *ScanRoot

RealFSScanRoot returns a ScanRoot array the given root path on the real filesystem SCALIBR is running on.

func RealFSScanRoots

func RealFSScanRoots(path string) []*ScanRoot

RealFSScanRoots returns a one-element ScanRoot array representing the given root path on the real filesystem SCALIBR is running on.

func (*ScanRoot) IsVirtual

func (r *ScanRoot) IsVirtual() bool

IsVirtual returns true if the scan root represents the root of a virtual filesystem, i.e. one with no real location on the disk of the scanned host.

func (*ScanRoot) WithAbsolutePath

func (r *ScanRoot) WithAbsolutePath() (*ScanRoot, error)

WithAbsolutePath returns a copy of the ScanRoot with the Path set an absolute path.

Directories

Path Synopsis
Package diriterate provides a utility for iterating over the contents of a directory without loading all of it into memory at once.
Package diriterate provides a utility for iterating over the contents of a directory without loading all of it into memory at once.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL