fileset

package
v0.0.0-...-e560ebb Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package fileset contains an abstraction for a set of files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Excluder

type Excluder func(absPath string, isDir bool) bool

Excluder takes an absolute path to a file on disk and returns true or false.

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.

func (*Set) Add

func (s *Set) Add(f File) error

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

func (s *Set) AddFromDisk(fsPath, setPath string, exclude Excluder) error

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

func (s *Set) AddFromMemory(setPath string, blob []byte, f *File) error

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 (s *Set) AddSymlink(setPath, target string) error

AddSymlink adds a relative symlink to the set.

Doesn't verify that the target exists in the set.

func (*Set) Enumerate

func (s *Set) Enumerate(cb func(f File) error) error

Enumerate calls the callback for each file in the set, in alphabetical order.

Returns whatever error the callback returns.

func (*Set) Files

func (s *Set) Files() []File

Files returns all files in the set, in alphabetical order.

func (*Set) Len

func (s *Set) Len() int

Len returns number of files in the set.

func (*Set) Materialize

func (s *Set) Materialize(root string) error

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) ToTar

func (s *Set) ToTar(w *tar.Writer) error

ToTar dumps all files in this set into a tar.Writer.

func (*Set) ToTarGz

func (s *Set) ToTarGz(w io.Writer) error

ToTarGz writes a *.tar.gz with files in the set to an io.Writer.

Uses default compression level.

func (*Set) ToTarGzFile

func (s *Set) ToTarGzFile(path string) (sha256hex string, err error)

ToTarGzFile writes a *.tar.gz with files in the set to a file on disk.

Calculates its SHA256 on the fly and returns the digest as a hex string.

Jump to

Keyboard shortcuts

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