osfs

package
v5.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: Apache-2.0 Imports: 11 Imported by: 361

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 added in v5.5.0

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 added in v5.5.0

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

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

func (*BoundOS) Create added in v5.5.0

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

func (*BoundOS) Join added in v5.5.0

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

func (*BoundOS) Lstat added in v5.5.0

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

func (*BoundOS) MkdirAll added in v5.5.0

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

func (*BoundOS) Open added in v5.5.0

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

func (*BoundOS) OpenFile added in v5.5.0

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

func (*BoundOS) ReadDir added in v5.5.0

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

func (*BoundOS) Remove added in v5.5.0

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

func (*BoundOS) RemoveAll added in v5.5.0

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

func (*BoundOS) Rename added in v5.5.0

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

func (*BoundOS) Root added in v5.5.0

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 added in v5.5.0

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

func (*BoundOS) TempFile added in v5.5.0

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 added in v5.5.0

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 added in v5.5.0

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

Capabilities implements the Capable interface.

func (*ChrootOS) Create added in v5.5.0

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

func (*ChrootOS) Join added in v5.5.0

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

func (*ChrootOS) Lstat added in v5.5.0

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

func (*ChrootOS) MkdirAll added in v5.5.0

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

func (*ChrootOS) Open added in v5.5.0

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

func (*ChrootOS) OpenFile added in v5.5.0

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

func (*ChrootOS) ReadDir added in v5.5.0

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

func (*ChrootOS) Remove added in v5.5.0

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

func (*ChrootOS) RemoveAll added in v5.5.0

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

func (*ChrootOS) Rename added in v5.5.0

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

func (*ChrootOS) Stat added in v5.5.0

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

func (*ChrootOS) TempFile added in v5.5.0

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

type Option added in v5.5.0

type Option func(*options)

func WithBoundOS added in v5.5.0

func WithBoundOS() Option

WithBoundOS returns the option of using a Bound filesystem OS.

func WithChrootOS added in v5.5.0

func WithChrootOS() Option

WithChrootOS returns the option of using a Chroot filesystem OS.

func WithDeduplicatePath added in v5.5.0

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 added in v5.5.0

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