Vfs - chainguard-dev/apko

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 path
  • Create(path string) (io.WriteCloser, error): creates a new file at the given path
  • Open(path string) (fs.File, error): opens the file at the given path
  • ReadFile(path string) ([]byte, error): reads the contents of the file at the given path
  • ReadDir(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 interface
  • fs.ReadDirFS: the filesystem interface for reading directories
  • fs.ReadFileFS: the filesystem interface for reading files
  • fs.StatFS: the filesystem interface for getting file information
  • Create(path string) (io.WriteCloser, error): creates a new file
  • Remove(path string) error: removes the file at the given path
  • RemoveAll(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: