files

package
v0.0.0-...-1388524 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package files contains utilities to handle file IO in a controlled way. In particular, it is meant to keep track of file ownership and rights.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileBase

type FileBase struct {

	// The group ID files should have.
	Gid int
	// The user ID files should have.
	Uid int
	// Whether files created should be group writable or not.
	GroupWritable bool
	// contains filtered or unexported fields
}

A FileBase represents a given directory, and allows operations to be formed on files and directories within it. It makes sure all operations are only performed within that directory, providing extra protection against malicious input or erroneous operations.

func NewFileBase

func NewFileBase(path string) FileBase

NewFileBase returns a FileBase for the given path. By default, the UID and GID of files will be the same as of the current process, and files will not be group writable.

func (*FileBase) Copy

func (fb *FileBase) Copy(srcFile, dstFile string) error

Copy copies the file at the absolute source path into the given filebase subpath.

func (*FileBase) CopyInto

func (fb *FileBase) CopyInto(srcDir string) error

CopyInto copies the contents of the source directory into the file base.

func (*FileBase) Exists

func (fb *FileBase) Exists(subPath string) (bool, error)

Exists checks if the given subpath exists.

func (FileBase) FixMode

func (fb FileBase) FixMode(subPath string) error

FixMode updates the file at the given subpath to be rw for its user and r (or rw depending on if the base is GroupWritable) for its group.

func (*FileBase) FixModeExec

func (fb *FileBase) FixModeExec(subPath string) error

FixMode updates the file at the given subpath to be rwx for its user and rx (or rwx depending on if the base is GroupWritable) for its group.

func (*FileBase) FixOwners

func (fb *FileBase) FixOwners(subPath string) error

FixOwners updates the file at the given subpath to have the correct owner user and group.

func (*FileBase) FullPath

func (fb *FileBase) FullPath(subPath string) (string, error)

FullPath returns the path of the file base after traversing the given relative path. If the path would result in a path above the file base, an error is returned.

func (*FileBase) LinkInto

func (fb *FileBase) LinkInto(fromPath string, toSubPath string) error

LinkInto links the file at the absolute path formPath to the given file base subpath.

func (*FileBase) Mkdir

func (fb *FileBase) Mkdir(subPath string) error

Mkdir creates a directory at the given subpath.

func (*FileBase) Path

func (fb *FileBase) Path() string

Path returns the base path that the FileBase represents.

func (*FileBase) ReadFile

func (fb *FileBase) ReadFile(subPath string) ([]byte, error)

ReadFile returns the contents of the file at the given subpath.

func (*FileBase) Remove

func (fb *FileBase) Remove(subPath string) error

Remove removes the file at the given subpath.

func (*FileBase) RemoveContents

func (fb *FileBase) RemoveContents(subPath string) error

RemoveContents removes all files and directories within the file base.

func (*FileBase) SetMode

func (fb *FileBase) SetMode(subPath string, mode os.FileMode) error

SetMode sets the mode of a file at the given subpath.

func (FileBase) SubBase

func (fb FileBase) SubBase(path string) (FileBase, error)

SubBase returns a new FileBase where the given path has been traversed. The path must be a relative path and may not refer to a path above the relative root, i.e. "../" is not an allowed path.

func (*FileBase) WriteFile

func (fb *FileBase) WriteFile(subPath string, contents []byte) error

WriteFile writes binary data to the file at the given subpath.

Jump to

Keyboard shortcuts

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