The pkg/vfs
package in the apko project is used for working with virtual filesystems. It provides a way to overlay one filesystem on top of another, allowing for things like permission and ownership changes that do not require physical root access. The VFS
struct is the main component of the package, which tracks an underlying BaseFS
.
The VFS
struct has several methods for interacting with the filesystem, including:
Stat(path string) (os.FileInfo, error)
: returns file information for the given pathCreate(path string) (io.WriteCloser, error)
: creates a new file at the given pathOpen(path string) (fs.File, error)
: opens the file at the given pathReadFile(path string) ([]byte, error)
: reads the contents of the file at the given pathReadDir(path string) ([]fs.DirEntry, error)
: returns a list of directory entries for the given path
The package also includes the BaseFS
interface, which is required for an underlay filesystem used with VFS
. This interface includes the following methods:
fs.FS
: the standard filesystem interfacefs.ReadDirFS
: the filesystem interface for reading directoriesfs.ReadFileFS
: the filesystem interface for reading filesfs.StatFS
: the filesystem interface for getting file informationCreate(path string) (io.WriteCloser, error)
: creates a new fileRemove(path string) error
: removes the file at the given pathRemoveAll(path string) error
: removes all files and directories at the given path
The pkg/vfs
package also includes functions for converting file modes to stat modes, such as fileModeToStatMode
, which is implemented differently for different operating systems (e.g. fsmode.go
for non-Linux and non-Darwin systems, fsmode_linux.go
for Linux systems, and fsmode_darwin.go
for Darwin systems).
Sources:
- https://github.com/chainguard-dev/apko/blob/main/pkg/vfs/vfs.go
- https://github.com/chainguard-dev/apko/blob/main/pkg/vfs/fsmode.go
- https://github.com/chainguard-dev/apko/blob/main/pkg/vfs/fsmode_linux.go
- https://github.com/chainguard-dev/apko/blob/main/pkg/vfs/fsmode_darwin.go
- https://github.com/chainguard-dev/apko/blob/main/pkg/vfs/basefs.go