...

Package filesys

import "sigs.k8s.io/kustomize/kyaml/filesys"
Overview
Index

Overview ▾

Package filesys provides a file system abstraction, a subset of that provided by golang.org/pkg/os, with an on-disk and in-memory representation.

Index ▾

Constants
func InsertPathPart(path string, pos int, part string) string
func IsHiddenFilePath(pattern string) bool
func MakeEmptyDirInMemory() *fsNode
func PathJoin(incoming []string) string
func PathSplit(incoming string) []string
func RemoveHiddenFiles(paths []string) []string
func RootedPath(elem ...string) string
func StripLeadingSeps(s string) string
func StripTrailingSeps(s string) string
type ConfirmedDir
    func ConfirmDir(fSys FileSystem, path string) (ConfirmedDir, error)
    func NewTmpConfirmedDir() (ConfirmedDir, error)
    func (d ConfirmedDir) HasPrefix(path ConfirmedDir) bool
    func (d ConfirmedDir) Join(path string) string
    func (d ConfirmedDir) String() string
type File
type FileSystem
    func MakeFsInMemory() FileSystem
    func MakeFsOnDisk() FileSystem
type FileSystemOrOnDisk
    func (fs FileSystemOrOnDisk) CleanedAbs(path string) (ConfirmedDir, string, error)
    func (fs FileSystemOrOnDisk) Create(path string) (File, error)
    func (fs FileSystemOrOnDisk) Exists(path string) bool
    func (fs FileSystemOrOnDisk) Glob(pattern string) ([]string, error)
    func (fs FileSystemOrOnDisk) IsDir(path string) bool
    func (fs FileSystemOrOnDisk) Mkdir(path string) error
    func (fs FileSystemOrOnDisk) MkdirAll(path string) error
    func (fs FileSystemOrOnDisk) Open(path string) (File, error)
    func (fs FileSystemOrOnDisk) ReadDir(path string) ([]string, error)
    func (fs FileSystemOrOnDisk) ReadFile(path string) ([]byte, error)
    func (fs FileSystemOrOnDisk) RemoveAll(path string) error
    func (fs *FileSystemOrOnDisk) Set(f FileSystem)
    func (fs FileSystemOrOnDisk) Walk(path string, walkFn filepath.WalkFunc) error
    func (fs FileSystemOrOnDisk) WriteFile(path string, data []byte) error

Package files

confirmeddir.go doc.go file.go fileinfo.go fileondisk.go filesystem.go fsnode.go fsondisk.go fsondisk_unix.go util.go

Constants

const (
    Separator = string(filepath.Separator)
    SelfDir   = "."
    ParentDir = ".."
)

func InsertPathPart

func InsertPathPart(path string, pos int, part string) string

InsertPathPart inserts 'part' at position 'pos' in the given filepath. The first position is 0.

E.g. if part == 'PEACH'

             OLD : NEW                    : POS
 --------------------------------------------------------
         {empty} : PEACH                  : irrelevant
               / : /PEACH                 : irrelevant
             pie : PEACH/pie              : 0 (or negative)
            /pie : /PEACH/pie             : 0 (or negative)
             raw : raw/PEACH              : 1 (or larger)
            /raw : /raw/PEACH             : 1 (or larger)
 a/nice/warm/pie : a/nice/warm/PEACH/pie  : 3
/a/nice/warm/pie : /a/nice/warm/PEACH/pie : 3

* An empty part results in no change.

func IsHiddenFilePath

func IsHiddenFilePath(pattern string) bool

func MakeEmptyDirInMemory

func MakeEmptyDirInMemory() *fsNode

MakeEmptyDirInMemory returns an empty directory. The paths of nodes in this object will never report a leading Separator, meaning they aren't "absolute" in the sense defined by https://golang.org/pkg/path/filepath/#IsAbs.

func PathJoin

func PathJoin(incoming []string) string

PathJoin converts a slice of string to a file path. If the first entry is an empty string, then the returned path is absolute (it has a leading slash). Desired: path == PathJoin(PathSplit(path))

func PathSplit

func PathSplit(incoming string) []string

PathSplit converts a file path to a slice of string. If the path is absolute (if the path has a leading slash), then the first entry in the result is an empty string. Desired: path == PathJoin(PathSplit(path))

func RemoveHiddenFiles

func RemoveHiddenFiles(paths []string) []string

Removes paths containing hidden files/folders from a list of paths

func RootedPath

func RootedPath(elem ...string) string

RootedPath returns a rooted path, e.g. "/foo/bar" as opposed to "foo/bar".

func StripLeadingSeps

func StripLeadingSeps(s string) string

StripLeadingSeps trims leading filepath separators from input.

func StripTrailingSeps

func StripTrailingSeps(s string) string

StripTrailingSeps trims trailing filepath separators from input.

type ConfirmedDir

ConfirmedDir is a clean, absolute, delinkified path that was confirmed to point to an existing directory.

type ConfirmedDir string

func ConfirmDir

func ConfirmDir(fSys FileSystem, path string) (ConfirmedDir, error)

ConfirmDir returns an error if the user-specified path is not an existing directory on fSys. Otherwise, ConfirmDir returns path, which can be relative, as a ConfirmedDir and all that implies.

func NewTmpConfirmedDir

func NewTmpConfirmedDir() (ConfirmedDir, error)

NewTmpConfirmedDir returns a temporary dir, else error. The directory is cleaned, no symlinks, etc. so it's returned as a ConfirmedDir.

func (ConfirmedDir) HasPrefix

func (d ConfirmedDir) HasPrefix(path ConfirmedDir) bool

HasPrefix returns true if the directory argument is a prefix of self (d) from the point of view of a file system.

I.e., it's true if the argument equals or contains self (d) in a file path sense.

HasPrefix emulates the semantics of strings.HasPrefix such that the following are true:

strings.HasPrefix("foobar", "foobar")
strings.HasPrefix("foobar", "foo")
strings.HasPrefix("foobar", "")

d := fSys.ConfirmDir("/foo/bar")
d.HasPrefix("/foo/bar")
d.HasPrefix("/foo")
d.HasPrefix("/")

Not contacting a file system here to check for actual path existence.

This is tested on linux, but will have trouble on other operating systems. TODO(monopole) Refactor when #golang/go/18358 closes. See also:

https://github.com/golang/go/issues/18358
https://github.com/golang/dep/issues/296
https://github.com/golang/dep/blob/master/internal/fs/fs.go#L33
https://codereview.appspot.com/5712045

func (ConfirmedDir) Join

func (d ConfirmedDir) Join(path string) string

func (ConfirmedDir) String

func (d ConfirmedDir) String() string

type File

File groups the basic os.File methods.

type File interface {
    io.ReadWriteCloser
    Stat() (os.FileInfo, error)
}

type FileSystem

FileSystem groups basic os filesystem methods. It's supposed be functional subset of https://golang.org/pkg/os

type FileSystem interface {

    // Create a file.
    Create(path string) (File, error)

    // MkDir makes a directory.
    Mkdir(path string) error

    // MkDirAll makes a directory path, creating intervening directories.
    MkdirAll(path string) error

    // RemoveAll removes path and any children it contains.
    RemoveAll(path string) error

    // Open opens the named file for reading.
    Open(path string) (File, error)

    // IsDir returns true if the path is a directory.
    IsDir(path string) bool

    // ReadDir returns a list of files and directories within a directory.
    ReadDir(path string) ([]string, error)

    // CleanedAbs converts the given path into a
    // directory and a file name, where the directory
    // is represented as a ConfirmedDir and all that implies.
    // If the entire path is a directory, the file component
    // is an empty string.
    CleanedAbs(path string) (ConfirmedDir, string, error)

    // Exists is true if the path exists in the file system.
    Exists(path string) bool

    // Glob returns the list of matching files,
    // emulating https://golang.org/pkg/path/filepath/#Glob
    Glob(pattern string) ([]string, error)

    // ReadFile returns the contents of the file at the given path.
    ReadFile(path string) ([]byte, error)

    // WriteFile writes the data to a file at the given path,
    // overwriting anything that's already there.
    WriteFile(path string, data []byte) error

    // Walk walks the file system with the given WalkFunc.
    Walk(path string, walkFn filepath.WalkFunc) error
}

func MakeFsInMemory

func MakeFsInMemory() FileSystem

MakeFsInMemory returns an empty 'file system'. The paths of nodes in this object will always report a leading Separator, meaning they are "absolute" in the sense defined by https://golang.org/pkg/path/filepath/#IsAbs. This is a relevant difference when using Walk, Glob, Match, etc.

func MakeFsOnDisk

func MakeFsOnDisk() FileSystem

MakeFsOnDisk makes an instance of fsOnDisk.

type FileSystemOrOnDisk

FileSystemOrOnDisk satisfies the FileSystem interface by forwarding all of its method calls to the given FileSystem whenever it's not nil. If it's nil, the call is forwarded to the OS's underlying file system.

type FileSystemOrOnDisk struct {
    FileSystem FileSystem
}

func (FileSystemOrOnDisk) CleanedAbs

func (fs FileSystemOrOnDisk) CleanedAbs(path string) (ConfirmedDir, string, error)

func (FileSystemOrOnDisk) Create

func (fs FileSystemOrOnDisk) Create(path string) (File, error)

func (FileSystemOrOnDisk) Exists

func (fs FileSystemOrOnDisk) Exists(path string) bool

func (FileSystemOrOnDisk) Glob

func (fs FileSystemOrOnDisk) Glob(pattern string) ([]string, error)

func (FileSystemOrOnDisk) IsDir

func (fs FileSystemOrOnDisk) IsDir(path string) bool

func (FileSystemOrOnDisk) Mkdir

func (fs FileSystemOrOnDisk) Mkdir(path string) error

func (FileSystemOrOnDisk) MkdirAll

func (fs FileSystemOrOnDisk) MkdirAll(path string) error

func (FileSystemOrOnDisk) Open

func (fs FileSystemOrOnDisk) Open(path string) (File, error)

func (FileSystemOrOnDisk) ReadDir

func (fs FileSystemOrOnDisk) ReadDir(path string) ([]string, error)

func (FileSystemOrOnDisk) ReadFile

func (fs FileSystemOrOnDisk) ReadFile(path string) ([]byte, error)

func (FileSystemOrOnDisk) RemoveAll

func (fs FileSystemOrOnDisk) RemoveAll(path string) error

func (*FileSystemOrOnDisk) Set

func (fs *FileSystemOrOnDisk) Set(f FileSystem)

Set sets the given FileSystem as the target for all the FileSystem method calls.

func (FileSystemOrOnDisk) Walk

func (fs FileSystemOrOnDisk) Walk(path string, walkFn filepath.WalkFunc) error

func (FileSystemOrOnDisk) WriteFile

func (fs FileSystemOrOnDisk) WriteFile(path string, data []byte) error