fileio

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2021 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConcatDirectoryContents added in v0.1.9

func ConcatDirectoryContents(sourceDir string) ([]byte, error)

ConcatDirectoryContents concatenates all regular files inside the source directory and returns their concatenated contents.

func ReaderToFile

func ReaderToFile(r io.Reader, dst string) error

ReaderToFile copies the data from a reader to a destination file.

Types

type Copier

type Copier struct {
	// contains filtered or unexported fields
}

Copier provides helper functions that copy files and directories to specified locations. Common behaviors regardless of the parameters:

  • If target diretory's ancestors do not exist, they will be created with default 0755 permission and owned by root.
  • If target directory already exists, its permission and owner will be preserved.
  • Symlinks are copied with original targets (not guaranteed to be valid).

Then there are 4 scenarios for handling file/directory permissions: - ADD/COPY without flags, from context:

  • If target directory doesn't exist, it will be created with default 0755 permission and owned by root.
  • For directories and files under source, permissions will be preserved, and owners will be root.
  • Use dstDirOwner without overwrite and dstFileAndChildrenOwner with overwrite, set uid:gid to 0:0.

- ADD/COPY --from, without other flags:

  • If target directory doesn't exist, it will be created with default 0755 permission and owned by root.
  • For directories and files under source, permissions and owners will be preserved.
  • Leave dstDirOwner and dstFileAndChildrenOwner empty.

- ADD/COPY --chown, with or wihout --from:

  • If target directory doesn't exist, it will be created with default 0755 permission and owned by given uid/gid.
  • For directories and files under source, permissions are kept, but owner will be changed to given uid/gid.
  • Use dstDirOwner without overwrite and dstFileAndChildrenOwner with overwrite.

- ADD/COPY --from --archive:

  • If target directory doesn't exist, it will be created with default 0755 permission and owned by source dir's uid/gid (directly given as copier parameters).
  • For directories and files under source, permissions and owners will be preserved.
  • Use dstDirOwner without overwrite and source dir's uid/gid.

func NewCopier

func NewCopier(blacklist []string, opts ...CopyOption) *Copier

NewCopier initializes a new copier object. Files from provided blacklist will be ignored.

func (*Copier) CopyDir

func (c *Copier) CopyDir(source, target string) error

CopyDir recursively copies the directory at source to target. The source directory must exist, and the target doesn't need to exist but must be a directory if it does. Existing children files/dirs will be overwritten. Permissions and owners depend on copier attributes.

Note: If src contains dst, this function would break infinite loop silently. This is needed to defend against scenarios like:

COPY --from=stage1 / /

where / will be stashed to some child directory at the end of stage1, and causes infinite loop.

func (*Copier) CopyFile

func (c *Copier) CopyFile(source, target string) error

CopyFile copies the content and permissions of the file at src to dst. If the target file exists, its contents and permissions might be overwritten, depending on copier attributes. For symlinks, the link target will be copied as-is.

type CopyOption added in v0.2.0

type CopyOption func(*Copier)

func WithDstDirOwner added in v0.2.0

func WithDstDirOwner(uid, gid int, overwrite bool) CopyOption

func WithDstFileAndChildrenOwner added in v0.2.0

func WithDstFileAndChildrenOwner(uid, gid int, overwrite bool) CopyOption

type Owner added in v0.2.0

type Owner struct {
	// contains filtered or unexported fields
}

Owner is a tuple of uid+gid, and a flag to indicate whether to overwrite existing owner.

Jump to

Keyboard shortcuts

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