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 ¶
- type FileBase
- func (fb *FileBase) Copy(srcFile, dstFile string) error
- func (fb *FileBase) CopyInto(srcDir string) error
- func (fb *FileBase) Exists(subPath string) (bool, error)
- func (fb FileBase) FixMode(subPath string) error
- func (fb *FileBase) FixModeExec(subPath string) error
- func (fb *FileBase) FixOwners(subPath string) error
- func (fb *FileBase) FullPath(subPath string) (string, error)
- func (fb *FileBase) LinkInto(fromPath string, toSubPath string) error
- func (fb *FileBase) Mkdir(subPath string) error
- func (fb *FileBase) Path() string
- func (fb *FileBase) ReadFile(subPath string) ([]byte, error)
- func (fb *FileBase) Remove(subPath string) error
- func (fb *FileBase) RemoveContents(subPath string) error
- func (fb *FileBase) SetMode(subPath string, mode os.FileMode) error
- func (fb FileBase) SubBase(path string) (FileBase, error)
- func (fb *FileBase) WriteFile(subPath string, contents []byte) error
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 ¶
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 ¶
Copy copies the file at the absolute source path into the given filebase subpath.
func (*FileBase) CopyInto ¶
CopyInto copies the contents of the source directory into the file base.
func (FileBase) FixMode ¶
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 ¶
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 ¶
FixOwners updates the file at the given subpath to have the correct owner user and group.
func (*FileBase) FullPath ¶
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 ¶
LinkInto links the file at the absolute path formPath to the given file base subpath.
func (*FileBase) RemoveContents ¶
RemoveContents removes all files and directories within the file base.