osfs

package
v6.0.0-...-c2c3cf4 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2025 License: Apache-2.0 Imports: 11 Imported by: 9

Documentation

Overview

Package osfs provides a billy filesystem for the OS.

Index

Constants

This section is empty.

Variables

View Source
var Default = &ChrootOS{}

Default Filesystem representing the root of the os filesystem.

Functions

func New

func New(baseDir string, opts ...Option) billy.Filesystem

New returns a new OS filesystem. By default paths are deduplicated, but still enforced under baseDir. For more info refer to WithDeduplicatePath.

Types

type BoundOS

type BoundOS struct {
	// contains filtered or unexported fields
}

BoundOS is a fs implementation based on the OS filesystem which is bound to a base dir. Prefer this fs implementation over ChrootOS.

Behaviours of note:

  1. Read and write operations can only be directed to files which descends from the base dir.
  2. Symlinks don't have their targets modified, and therefore can point to locations outside the base dir or to non-existent paths.
  3. Readlink and Lstat ensures that the link file is located within the base dir, evaluating any symlinks that file or base dir may contain.

func (*BoundOS) Chroot

func (fs *BoundOS) Chroot(path string) (billy.Filesystem, error)

Chroot returns a new BoundOS filesystem, with the base dir set to the result of joining the provided path with the underlying base dir.

func (*BoundOS) Create

func (fs *BoundOS) Create(filename string) (billy.File, error)

func (*BoundOS) Join

func (fs *BoundOS) Join(elem ...string) string

func (*BoundOS) Lstat

func (fs *BoundOS) Lstat(filename string) (os.FileInfo, error)

func (*BoundOS) MkdirAll

func (fs *BoundOS) MkdirAll(path string, perm fs.FileMode) error

func (*BoundOS) Open

func (fs *BoundOS) Open(filename string) (billy.File, error)

func (*BoundOS) OpenFile

func (fs *BoundOS) OpenFile(filename string, flag int, perm fs.FileMode) (billy.File, error)

func (*BoundOS) ReadDir

func (fs *BoundOS) ReadDir(path string) ([]os.FileInfo, error)
func (fs *BoundOS) Readlink(link string) (string, error)

func (*BoundOS) Remove

func (fs *BoundOS) Remove(filename string) error

func (*BoundOS) RemoveAll

func (fs *BoundOS) RemoveAll(path string) error

func (*BoundOS) Rename

func (fs *BoundOS) Rename(from, to string) error

func (*BoundOS) Root

func (fs *BoundOS) Root() string

Root returns the current base dir of the billy.Filesystem. This is required in order for this implementation to be a drop-in replacement for other upstream implementations (e.g. memory and osfs).

func (*BoundOS) Stat

func (fs *BoundOS) Stat(filename string) (os.FileInfo, error)
func (fs *BoundOS) Symlink(target, link string) error

func (*BoundOS) TempFile

func (fs *BoundOS) TempFile(dir, prefix string) (billy.File, error)

TempFile creates a temporary file. If dir is empty, the file will be created within the OS Temporary dir. If dir is provided it must descend from the current base dir.

type ChrootOS

type ChrootOS struct{}

ChrootOS is a legacy filesystem based on a "soft chroot" of the os filesystem. Although this is still the default os filesystem, consider using BoundOS instead.

Behaviours of note:

  1. A "soft chroot" translates the base dir to "/" for the purposes of the fs abstraction.
  2. Symlinks targets may be modified to be kept within the chroot bounds.
  3. Some file modes does not pass-through the fs abstraction.
  4. The combination of 1 and 2 may cause go-git to think that a Git repository is dirty, when in fact it isn't.

func (*ChrootOS) Capabilities

func (fs *ChrootOS) Capabilities() billy.Capability

Capabilities implements the Capable interface.

func (*ChrootOS) Create

func (fs *ChrootOS) Create(filename string) (billy.File, error)

func (*ChrootOS) Join

func (fs *ChrootOS) Join(elem ...string) string

func (*ChrootOS) Lstat

func (fs *ChrootOS) Lstat(filename string) (os.FileInfo, error)

func (*ChrootOS) MkdirAll

func (fs *ChrootOS) MkdirAll(path string, _ os.FileMode) error

func (*ChrootOS) Open

func (fs *ChrootOS) Open(filename string) (billy.File, error)

func (*ChrootOS) OpenFile

func (fs *ChrootOS) OpenFile(filename string, flag int, perm fs.FileMode) (billy.File, error)

func (*ChrootOS) ReadDir

func (fs *ChrootOS) ReadDir(dir string) ([]os.FileInfo, error)
func (fs *ChrootOS) Readlink(link string) (string, error)

func (*ChrootOS) Remove

func (fs *ChrootOS) Remove(filename string) error

func (*ChrootOS) RemoveAll

func (fs *ChrootOS) RemoveAll(path string) error

func (*ChrootOS) Rename

func (fs *ChrootOS) Rename(from, to string) error

func (*ChrootOS) Stat

func (fs *ChrootOS) Stat(filename string) (os.FileInfo, error)
func (fs *ChrootOS) Symlink(target, link string) error

func (*ChrootOS) TempFile

func (fs *ChrootOS) TempFile(dir, prefix string) (billy.File, error)

type Option

type Option func(*options)

func WithBoundOS

func WithBoundOS() Option

WithBoundOS returns the option of using a Bound filesystem OS.

func WithChrootOS

func WithChrootOS() Option

WithChrootOS returns the option of using a Chroot filesystem OS.

func WithDeduplicatePath

func WithDeduplicatePath(enabled bool) Option

WithDeduplicatePath toggles the deduplication of the base dir in the path. This occurs when absolute links are being used. Assuming base dir /base/dir and an absolute symlink /base/dir/target:

With DeduplicatePath (default): /base/dir/target Without DeduplicatePath: /base/dir/base/dir/target

This option is only used by the BoundOS OS type.

type Type

type Type int
const (
	ChrootOSFS Type = iota
	BoundOSFS
)

Jump to

Keyboard shortcuts

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