copier

package
v1.42.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: Apache-2.0 Imports: 28 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConditionalRemove added in v1.41.0

func ConditionalRemove(root, directory string, options ConditionalRemoveOptions) ([]string, error)

ConditionalRemove removes the set of named items if they're present and currently match the additional conditions, returning the list of items it removed. Directories will also only be removed if they have no contents, and will be left in place otherwise.

func Eval added in v1.19.7

func Eval(root string, directory string, _ EvalOptions) (string, error)

Eval evaluates the directory's path, including any intermediate symbolic links. If root is specified and the current OS supports it, and the calling process has the necessary privileges, evaluation is performed in a chrooted context. If the directory is specified as an absolute path, it should either be the root directory or a subdirectory of the root directory. Otherwise, the directory is treated as a path relative to the root directory.

func Get

func Get(root string, directory string, options GetOptions, globs []string, bulkWriter io.Writer) error

Get produces an archive containing items that match the specified glob patterns and writes it to bulkWriter. If root and directory are both not specified, the current root directory is used, and relative names in the globs list are treated as being relative to the current working directory. If root is specified and the current OS supports it, and the calling process has the necessary privileges, the contents are read in a chrooted context. If the directory is specified as an absolute path, it should either be the root directory or a subdirectory of the root directory. Otherwise, the directory is treated as a path relative to the root directory. Relative names in the glob list are treated as being relative to the directory.

func Lgetxattrs

func Lgetxattrs(path string) (map[string]string, error)

Lgetxattrs returns a map of the relevant extended attributes set on the given file.

func Lsetxattrs

func Lsetxattrs(path string, xattrs map[string]string) error

Lsetxattrs sets the relevant members of the specified extended attributes on the given file.

func Mkdir

func Mkdir(root string, directory string, options MkdirOptions) error

Mkdir ensures that the specified directory exists. Any directories which need to be created will be given the specified ownership and permissions. If root and directory are both not specified, the current root directory is used. If root is specified and the current OS supports it, and the calling process has the necessary privileges, the directory is created in a chrooted context. If the directory is specified as an absolute path, it should either be the root directory or a subdirectory of the root directory. Otherwise, the directory is treated as a path relative to the root directory.

func Put

func Put(root string, directory string, options PutOptions, bulkReader io.Reader) error

Put extracts an archive from the bulkReader at the specified directory. If root and directory are both not specified, the current root directory is used. If root is specified and the current OS supports it, and the calling process has the necessary privileges, the contents are written in a chrooted context. If the directory is specified as an absolute path, it should either be the root directory or a subdirectory of the root directory. Otherwise, the directory is treated as a path relative to the root directory.

func Remove added in v1.21.0

func Remove(root string, item string, options RemoveOptions) error

Remove removes the specified directory or item, traversing any intermediate symbolic links. If the root directory is not specified, the current root directory is used. If root is specified and the current OS supports it, and the calling process has the necessary privileges, the remove() is performed in a chrooted context. If the item to remove is specified as an absolute path, it should either be in the root directory or in a subdirectory of the root directory. Otherwise, the directory is treated as a path relative to the root directory.

Types

type ConditionalRemoveOptions added in v1.41.0

type ConditionalRemoveOptions struct {
	UIDMap, GIDMap []idtools.IDMap // map from containerIDs to hostIDs in the chroot
	Paths          []ConditionalRemovePath
}

ConditionalRemoveOptions controls parts of ConditionalRemove()'s behavior.

type ConditionalRemovePath added in v1.41.0

type ConditionalRemovePath struct {
	Path    string          // a pathname, relative to the Directory, possibly relative to the root
	ModTime *time.Time      // mtime to expect this item to have, if it's a condition
	Mode    *os.FileMode    // mode to expect this item to have, if it's a condition
	Owner   *idtools.IDPair // owner to expect this item to have, if it's a condition
}

ConditionalRemovePath is a single item being passed to an ConditionalRemove() call.

type EnsureOptions added in v1.41.0

type EnsureOptions struct {
	UIDMap, GIDMap []idtools.IDMap // map from containerIDs to hostIDs in the chroot
	Paths          []EnsurePath
}

EnsureOptions controls parts of Ensure()'s behavior.

type EnsureParentPath added in v1.41.1

type EnsureParentPath = ConditionalRemovePath

EnsureParentPath is a parent (or grandparent, or...) directory of an item created by Ensure(), along with information about it, from before the item in question was created. If the information about this directory hasn't changed when commit-time rolls around, it's most likely that this directory is only being considered for inclusion in the layer because it was pulled up, and it was not actually changed.

func Ensure added in v1.41.0

func Ensure(root, directory string, options EnsureOptions) ([]string, []EnsureParentPath, error)

Ensure ensures that the specified mount point targets exist under the root. If the root directory is not specified, the current root directory is used. If root is specified and the current OS supports it, and the calling process has the necessary privileges, the operation is performed in a chrooted context. Returns a slice with the pathnames of items that needed to be created and a slice of affected parent directories and information about them.

type EnsurePath added in v1.41.0

type EnsurePath struct {
	Path     string          // a pathname, relative to the Directory, possibly relative to the root
	Typeflag byte            // can be either TypeReg or TypeDir, everything else is currently ignored
	ModTime  *time.Time      // mtime to set on newly-created items, default is to leave them be
	Chmod    *os.FileMode    // mode, defaults to 000 for files and 700 for directories
	Chown    *idtools.IDPair // owner settings to set on newly-created items, defaults to 0:0
}

EnsurePath is a single item being passed to an Ensure() call.

type EvalOptions added in v1.19.7

type EvalOptions struct{}

EvalOptions controls parts of Eval()'s behavior.

type GetOptions

type GetOptions struct {
	UIDMap, GIDMap     []idtools.IDMap   // map from hostIDs to containerIDs in the output archive
	Excludes           []string          // contents to pretend don't exist, using the OS-specific path separator
	ExpandArchives     bool              // extract the contents of named items that are archives
	ChownDirs          *idtools.IDPair   // set ownership on directories. no effect on archives being extracted
	ChmodDirs          *os.FileMode      // set permissions on directories. no effect on archives being extracted
	ChownFiles         *idtools.IDPair   // set ownership of files. no effect on archives being extracted
	ChmodFiles         *os.FileMode      // set permissions on files. no effect on archives being extracted
	Parents            bool              // maintain the sources parent directory in the destination
	StripSetuidBit     bool              // strip the setuid bit off of items being copied. no effect on archives being extracted
	StripSetgidBit     bool              // strip the setgid bit off of items being copied. no effect on archives being extracted
	StripStickyBit     bool              // strip the sticky bit off of items being copied. no effect on archives being extracted
	StripXattrs        bool              // don't record extended attributes of items being copied. no effect on archives being extracted
	KeepDirectoryNames bool              // don't strip the top directory's basename from the paths of items in subdirectories
	Rename             map[string]string // rename items with the specified names, or under the specified names
	NoDerefSymlinks    bool              // don't follow symlinks when globs match them
	IgnoreUnreadable   bool              // ignore errors reading items, instead of returning an error
	NoCrossDevice      bool              // if a subdirectory is a mountpoint with a different device number, include it but skip its contents
	Timestamp          *time.Time        // timestamp to force on all contents
}

GetOptions controls parts of Get()'s behavior.

type MkdirOptions

type MkdirOptions struct {
	UIDMap, GIDMap []idtools.IDMap // map from containerIDs to hostIDs when creating directories
	ModTimeNew     *time.Time      // set mtime and atime of newly-created directories
	ChownNew       *idtools.IDPair // set ownership of newly-created directories
	ChmodNew       *os.FileMode    // set permissions on newly-created directories
}

MkdirOptions controls parts of Mkdir()'s behavior.

type PutOptions

type PutOptions struct {
	UIDMap, GIDMap       []idtools.IDMap   // map from containerIDs to hostIDs when writing contents to disk
	DefaultDirOwner      *idtools.IDPair   // set ownership of implicitly-created directories, default is ChownDirs, or 0:0 if ChownDirs not set
	DefaultDirMode       *os.FileMode      // set permissions on implicitly-created directories, default is ChmodDirs, or 0755 if ChmodDirs not set
	ChownDirs            *idtools.IDPair   // set ownership of newly-created directories
	ChmodDirs            *os.FileMode      // set permissions on newly-created directories
	ChownFiles           *idtools.IDPair   // set ownership of newly-created files
	ChmodFiles           *os.FileMode      // set permissions on newly-created files
	StripSetuidBit       bool              // strip the setuid bit off of items being written
	StripSetgidBit       bool              // strip the setgid bit off of items being written
	StripStickyBit       bool              // strip the sticky bit off of items being written
	StripXattrs          bool              // don't bother trying to set extended attributes of items being copied
	IgnoreXattrErrors    bool              // ignore any errors encountered when attempting to set extended attributes
	IgnoreDevices        bool              // ignore items which are character or block devices
	NoOverwriteDirNonDir bool              // instead of quietly overwriting directories with non-directories, return an error
	NoOverwriteNonDirDir bool              // instead of quietly overwriting non-directories with directories, return an error
	Rename               map[string]string // rename items with the specified names, or under the specified names
}

PutOptions controls parts of Put()'s behavior.

type RemoveOptions added in v1.21.0

type RemoveOptions struct {
	All bool // if Directory is a directory, remove its contents as well
}

RemoveOptions controls parts of Remove()'s behavior.

type StatForItem

type StatForItem struct {
	Error           string `json:",omitempty"`
	Name            string
	Size            int64       // dereferenced value for symlinks
	Mode            os.FileMode // dereferenced value for symlinks
	ModTime         time.Time   // dereferenced value for symlinks
	UID, GID        int64       // usually in the uint32 range, set to -1 if unknown
	IsSymlink       bool
	IsDir           bool   // dereferenced value for symlinks
	IsRegular       bool   // dereferenced value for symlinks
	IsArchive       bool   // dereferenced value for symlinks
	ImmediateTarget string `json:",omitempty"` // raw link content
}

StatForItem encode results for a single filesystem item, as returned by Stat().

type StatOptions

type StatOptions struct {
	UIDMap, GIDMap   []idtools.IDMap // map from hostIDs to containerIDs when returning results
	CheckForArchives bool            // check for and populate the IsArchive bit in returned values
	Excludes         []string        // contents to pretend don't exist, using the OS-specific path separator
}

StatOptions controls parts of Stat()'s behavior.

type StatsForGlob

type StatsForGlob struct {
	Error   string                  `json:",omitempty"` // error if the Glob pattern was malformed
	Glob    string                  // input pattern to which this result corresponds
	Globbed []string                // a slice of zero or more names that match the glob
	Results map[string]*StatForItem // one for each Globbed value if there are any, or for Glob
}

StatsForGlob encode results for a single glob pattern passed to Stat().

func Stat

func Stat(root string, directory string, options StatOptions, globs []string) ([]*StatsForGlob, error)

Stat globs the specified pattern in the specified directory and returns its results. If root and directory are both not specified, the current root directory is used, and relative names in the globs list are treated as being relative to the current working directory. If root is specified and the current OS supports it, and the calling process has the necessary privileges, the stat() is performed in a chrooted context. If the directory is specified as an absolute path, it should either be the root directory or a subdirectory of the root directory. Otherwise, the directory is treated as a path relative to the root directory. Relative names in the glob list are treated as being relative to the directory.

Jump to

Keyboard shortcuts

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