Documentation
¶
Overview ¶
Package fileset contains an abstraction for a set of files.
Index ¶
- type Excluder
- type File
- type Set
- func (s *Set) Add(f File) error
- func (s *Set) AddFromDisk(fsPath, setPath string, exclude Excluder) error
- func (s *Set) AddFromMemory(setPath string, blob []byte, f *File) error
- func (s *Set) AddSymlink(setPath, target string) error
- func (s *Set) Enumerate(cb func(f File) error) error
- func (s *Set) File(setPath string) (File, bool)
- func (s *Set) Files() []File
- func (s *Set) Len() int
- func (s *Set) Materialize(root string) error
- func (s *Set) Overlay() *Set
- func (s *Set) ToTar(w *tar.Writer) error
- func (s *Set) ToTarGz(w io.Writer) error
- func (s *Set) ToTarGzFile(path string) (sha256hex string, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type File ¶
type File struct { Path string // file path using "/" separator Directory bool // true if this is a directory SymlinkTarget string // non-empty if this is a symlink Size int64 // size of the file, only for regular files Writable bool // true if the file is writable, only for regular files Executable bool // true if the file is executable, only for regular files Body func() (io.ReadCloser, error) // emits the body, only for regular files }
File is a file inside a file set.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set represents a set of regular files, directories and symlinks.
Such set can be constructed from existing files on disk (perhaps scattered across many directories), and it then can be either materialized on disk in some root directory, or written into a tarball.
A set can optionally have an overlay set. Files in the overlay set are always written to the output instead of files in the main set. This is useful for emitting "overrides" that work regardless in which order files are added to the main set.
func (*Set) Add ¶
Add adds a file or directory to the set, overriding an existing one, if any.
Adds all intermediary directories, if necessary.
Returns an error if the file path is invalid (e.g. starts with "../"").
func (*Set) AddFromDisk ¶
AddFromDisk adds a given file or directory to the set.
A file or directory located at 'fsPath' on disk will become 'setPath' in the set. Directories are added recursively. Symlinks are always expanded into whatever they point to. Broken symlinks are silently skipped. To add a symlink explicitly use AddSymlink.
func (*Set) AddFromMemory ¶
AddFromMemory adds the given blob to the set as a file.
'blob' is retained as a pointer, the memory is not copied.
'f', if not nil, is used to populate the file metadata. If nil, the blob is added as a non-executable read-only file.
func (*Set) AddSymlink ¶
AddSymlink adds a relative symlink to the set.
Doesn't verify that the target exists in the set.
func (*Set) Enumerate ¶
Enumerate calls the callback for each file in the set, in alphabetical order.
Returns whatever error the callback returns.
func (*Set) File ¶
File returns an existing file in the set, if any.
If there's no such file returns `File{}, false`.
func (*Set) Materialize ¶
Materialize dumps all files in this set into the given directory.
The directory will be created if it doesn't exist. If it exists, the contents of 's' will be written on top of whatever is in the directory already.
Doesn't cleanup on errors.
func (*Set) Overlay ¶
Overlay returns a set of files that "override" files in the main set when the set is materialized or enumerated.
Note that overriding regular files with directories in the overlay set is not supported and will result in errors when trying to materialize such set.