Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyLayer(dest string, layer ArchiveReader) (int64, error)
- func ApplyUncompressedLayer(dest string, layer ArchiveReader) (int64, error)
- func AssertsDirectory(path string) bool
- func CanonicalTarNameForPath(p string) (string, error)
- func ChangesSize(newDir string, changes []Change) int64
- func CmdStream(cmd *exec.Cmd, input io.Reader) (io.ReadCloser, error)
- func CompressStream(dest io.WriteCloser, compression Compression) (io.WriteCloser, error)
- func CopyFileWithTar(src, dst string) (err error)
- func CopyResource(srcPath, dstPath string) error
- func CopyTo(content ArchiveReader, srcInfo CopyInfo, dstPath string) error
- func CopyWithTar(src, dst string) error
- func DecompressStream(archive io.Reader) (io.ReadCloser, error)
- func HasTrailingPathSeparator(path string) bool
- func IsArchive(header []byte) bool
- func PreserveTrailingDotOrSeparator(cleanedPath, originalPath string) string
- func SpecifiesCurrentDir(path string) bool
- func SplitPathDirEntry(path string) (dir, base string)
- func Tar(path string, compression Compression) (io.ReadCloser, error)
- func TarUntar(src, dst string) error
- func TarWithOptions(srcPath string, options *TarOptions) (io.ReadCloser, error)
- func Unpack(decompressedArchive io.Reader, dest string, options *TarOptions) error
- func UnpackLayer(dest string, layer ArchiveReader) (size int64, err error)
- func Untar(tarArchive io.Reader, dest string, options *TarOptions) error
- func UntarPath(src, dst string) error
- func UntarUncompressed(tarArchive io.Reader, dest string, options *TarOptions) error
- type Archive
- func ExportChanges(dir string, changes []Change) (Archive, error)
- func Generate(input ...string) (Archive, error)
- func PrepareArchiveCopy(srcContent ArchiveReader, srcInfo, dstInfo CopyInfo) (dstDir string, content Archive, err error)
- func TarResource(sourceInfo CopyInfo) (content Archive, err error)
- func TarResourceRebase(sourcePath, rebaseName string) (content Archive, err error)
- type ArchiveReader
- type Archiver
- type Change
- type ChangeType
- type Compression
- type CopyInfo
- type FileInfo
- type TarChownOptions
- type TarOptions
- type TempArchive
Constants ¶
const ( ChangeModify = iota ChangeAdd ChangeDelete )
Variables ¶
var ( ErrNotDirectory = errors.New("not a directory") ErrDirNotExists = errors.New("no such directory") ErrCannotCopyDir = errors.New("cannot copy directory") ErrInvalidCopySource = errors.New("invalid copy source content") )
Errors used or returned by this file.
var (
ErrNotImplemented = errors.New("Function not implemented")
)
Functions ¶
func ApplyLayer ¶
func ApplyLayer(dest string, layer ArchiveReader) (int64, error)
ApplyLayer parses a diff in the standard layer format from `layer`, and applies it to the directory `dest`. The stream `layer` can be compressed or uncompressed. Returns the size in bytes of the contents of the layer.
func ApplyUncompressedLayer ¶ added in v1.8.0
func ApplyUncompressedLayer(dest string, layer ArchiveReader) (int64, error)
ApplyUncompressedLayer parses a diff in the standard layer format from `layer`, and applies it to the directory `dest`. The stream `layer` can only be uncompressed. Returns the size in bytes of the contents of the layer.
func AssertsDirectory ¶ added in v1.8.0
AssertsDirectory returns whether the given path is asserted to be a directory, i.e., the path ends with a trailing '/' or `/.`, assuming a path separator of `/`.
func CanonicalTarNameForPath ¶ added in v1.6.0
CanonicalTarNameForPath returns platform-specific filepath to canonical posix-style path for tar archival. p is relative path.
func ChangesSize ¶
ChangesSize calculates the size in bytes of the provided changes, based on newDir.
func CmdStream ¶
CmdStream executes a command, and returns its stdout as a stream. If the command fails to run or doesn't complete successfully, an error will be returned, including anything written on stderr.
func CompressStream ¶
func CompressStream(dest io.WriteCloser, compression Compression) (io.WriteCloser, error)
func CopyFileWithTar ¶
CopyFileWithTar emulates the behavior of the 'cp' command-line for a single file. It copies a regular file from path `src` to path `dst`, and preserves all its metadata.
Destination handling is in an operating specific manner depending where the daemon is running. If `dst` ends with a trailing slash the final destination path will be `dst/base(src)` (Linux) or `dst\base(src)` (Windows).
func CopyResource ¶ added in v1.8.0
CopyResource performs an archive copy from the given source path to the given destination path. The source path MUST exist and the destination path's parent directory must exist.
func CopyTo ¶ added in v1.8.0
func CopyTo(content ArchiveReader, srcInfo CopyInfo, dstPath string) error
CopyTo handles extracting the given content whose entries should be sourced from srcInfo to dstPath.
func CopyWithTar ¶
CopyWithTar creates a tar archive of filesystem path `src`, and unpacks it at filesystem path `dst`. The archive is streamed directly with fixed buffering and no intermediary disk IO.
func DecompressStream ¶
func DecompressStream(archive io.Reader) (io.ReadCloser, error)
func HasTrailingPathSeparator ¶ added in v1.8.0
HasTrailingPathSeparator returns whether the given path ends with the system's path separator character.
func PreserveTrailingDotOrSeparator ¶ added in v1.8.0
PreserveTrailingDotOrSeparator returns the given cleaned path (after processing using any utility functions from the path or filepath stdlib packages) and appends a trailing `/.` or `/` if its corresponding original path (from before being processed by utility functions from the path or filepath stdlib packages) ends with a trailing `/.` or `/`. If the cleaned path already ends in a `.` path segment, then another is not added. If the clean path already ends in a path separator, then another is not added.
func SpecifiesCurrentDir ¶ added in v1.8.0
SpecifiesCurrentDir returns whether the given path specifies a "current directory", i.e., the last path segment is `.`.
func SplitPathDirEntry ¶ added in v1.8.0
SplitPathDirEntry splits the given path between its directory name and its basename by first cleaning the path but preserves a trailing "." if the original path specified the current directory.
func Tar ¶
func Tar(path string, compression Compression) (io.ReadCloser, error)
Tar creates an archive from the directory at `path`, and returns it as a stream of bytes.
func TarUntar ¶
TarUntar is a convenience function which calls Tar and Untar, with the output of one piped into the other. If either Tar or Untar fails, TarUntar aborts and returns the error.
func TarWithOptions ¶
func TarWithOptions(srcPath string, options *TarOptions) (io.ReadCloser, error)
TarWithOptions creates an archive from the directory at `path`, only including files whose relative paths are included in `options.IncludeFiles` (if non-nil) or not in `options.ExcludePatterns`.
func Unpack ¶ added in v1.3.3
func Unpack(decompressedArchive io.Reader, dest string, options *TarOptions) error
func UnpackLayer ¶ added in v1.3.3
func UnpackLayer(dest string, layer ArchiveReader) (size int64, err error)
func Untar ¶
func Untar(tarArchive io.Reader, dest string, options *TarOptions) error
Untar reads a stream of bytes from `archive`, parses it as a tar archive, and unpacks it into the directory at `dest`. The archive may be compressed with one of the following algorithms:
identity (uncompressed), gzip, bzip2, xz.
FIXME: specify behavior when target path exists vs. doesn't exist.
func UntarPath ¶
UntarPath is a convenience function which looks for an archive at filesystem path `src`, and unpacks it at `dst`.
func UntarUncompressed ¶ added in v1.8.0
func UntarUncompressed(tarArchive io.Reader, dest string, options *TarOptions) error
Untar reads a stream of bytes from `archive`, parses it as a tar archive, and unpacks it into the directory at `dest`. The archive must be an uncompressed stream.
Types ¶
type Archive ¶
type Archive io.ReadCloser
func ExportChanges ¶
ExportChanges produces an Archive from the provided changes, relative to dir.
func Generate ¶
Generate generates a new archive from the content provided as input.
`files` is a sequence of path/content pairs. A new file is added to the archive for each pair. If the last pair is incomplete, the file is created with an empty content. For example:
Generate("foo.txt", "hello world", "emptyfile")
The above call will return an archive with 2 files:
- ./foo.txt with content "hello world"
- ./empty with empty content
FIXME: stream content instead of buffering FIXME: specify permissions and other archive metadata
func PrepareArchiveCopy ¶ added in v1.8.0
func PrepareArchiveCopy(srcContent ArchiveReader, srcInfo, dstInfo CopyInfo) (dstDir string, content Archive, err error)
PrepareArchiveCopy prepares the given srcContent archive, which should contain the archived resource described by srcInfo, to the destination described by dstInfo. Returns the possibly modified content archive along with the path to the destination directory which it should be extracted to.
func TarResource ¶ added in v1.8.0
TarResource archives the resource described by the given CopyInfo to a Tar archive. A non-nil error is returned if sourcePath does not exist or is asserted to be a directory but exists as another type of file.
This function acts as a convenient wrapper around TarWithOptions, which requires a directory as the source path. TarResource accepts either a directory or a file path and correctly sets the Tar options.
func TarResourceRebase ¶ added in v1.8.0
TarResourceRebase is like TarResource but renames the first path element of items in the resulting tar archive to match the given rebaseName if not "".
type ArchiveReader ¶
type Archiver ¶ added in v1.3.2
type Archiver struct {
Untar func(io.Reader, string, *TarOptions) error
}
Archiver allows the reuse of most utility functions of this package with a pluggable Untar function.
func (*Archiver) CopyFileWithTar ¶ added in v1.3.2
func (*Archiver) CopyWithTar ¶ added in v1.3.2
type Change ¶
type Change struct { Path string Kind ChangeType }
func Changes ¶
Changes walks the path rw and determines changes for the files in the path, with respect to the parent layers
func ChangesDirs ¶
ChangesDirs compares two directories and generates an array of Change objects describing the changes. If oldDir is "", then all files in newDir will be Add-Changes.
type ChangeType ¶
type ChangeType int
type Compression ¶
type Compression int
const ( Uncompressed Compression = iota Bzip2 Gzip Xz )
func DetectCompression ¶
func DetectCompression(source []byte) Compression
func (*Compression) Extension ¶
func (compression *Compression) Extension() string
type CopyInfo ¶ added in v1.8.0
CopyInfo holds basic info about the source or destination path of a copy operation.
func CopyInfoDestinationPath ¶ added in v1.8.0
CopyInfoDestinationPath stats the given path to create a CopyInfo struct representing that resource for the destination of an archive copy operation. The given path should be an absolute local path.
func CopyInfoSourcePath ¶ added in v1.8.0
CopyInfoSourcePath stats the given path to create a CopyInfo struct representing that resource for the source of an archive copy operation. The given path should be an absolute local path. A source path has all symlinks evaluated that appear before the last path separator ("/" on Unix). As it is to be a copy source, the path must exist.
type TarChownOptions ¶ added in v1.8.0
type TarChownOptions struct {
UID, GID int
}
type TarOptions ¶
type TarOptions struct { IncludeFiles []string ExcludePatterns []string Compression Compression NoLchown bool ChownOpts *TarChownOptions IncludeSourceDir bool // When unpacking, specifies whether overwriting a directory with a // non-directory is allowed and vice versa. NoOverwriteDirNonDir bool // For each include when creating an archive, the included name will be // replaced with the matching name from this map. RebaseNames map[string]string }
type TempArchive ¶
type TempArchive struct { *os.File Size int64 // Pre-computed from Stat().Size() as a convenience // contains filtered or unexported fields }
func NewTempArchive ¶
func NewTempArchive(src Archive, dir string) (*TempArchive, error)
NewTempArchive reads the content of src into a temporary file, and returns the contents of that file as an archive. The archive can only be read once - as soon as reading completes, the file will be deleted.
func (*TempArchive) Close ¶ added in v1.4.0
func (archive *TempArchive) Close() error
Close closes the underlying file if it's still open, or does a no-op to allow callers to try to close the TempArchive multiple times safely.