Documentation
¶
Index ¶
- Variables
- func AddUser(name string, opts *AddUserOptions) error
- func AtomicWriteFile(filename string, data []byte, perm os.FileMode, flags AtomicWriteFlags) (err error)
- func AtomicWriteFileChown(filename string, data []byte, perm os.FileMode, flags AtomicWriteFlags, ...) (err error)
- func ChDir(newDir string, f func() error) (err error)
- func CopyFile(src, dst string, flags CopyFlag) (err error)
- func CopySpecialFile(path, dest string) error
- func DirUpdated(dirA, dirB, pfx string) map[string]bool
- func EnsureDirState(dir, glob string, content map[string]*FileState) (changed, removed []string, err error)
- func EnsureFileState(filePath string, fileState *FileState) error
- func ExitCode(runErr error) (e int, err error)
- func FileDigest(filename string, hash crypto.Hash) ([]byte, uint64, error)
- func FileExists(path string) bool
- func FilesAreEqual(a, b string) bool
- func IsDevice(mode os.FileMode) bool
- func IsDirectory(path string) bool
- func IsSymlink(path string) bool
- func MkdirAllChown(path string, perm os.FileMode, uid, gid int) error
- func OutputErr(output []byte, err error) error
- func RealUser() (*user.User, error)
- type AddUserOptions
- type AtomicWriteFlags
- type CopyFlag
- type ErrCopySpecialFile
- type FileState
- type Winsize
Constants ¶
This section is empty.
Variables ¶
var ErrSameState = fmt.Errorf("file state has not changed")
ErrSameState is returned when the state of a file has not changed.
Functions ¶
func AddUser ¶
func AddUser(name string, opts *AddUserOptions) error
func AtomicWriteFile ¶
func AtomicWriteFile(filename string, data []byte, perm os.FileMode, flags AtomicWriteFlags) (err error)
AtomicWriteFile updates the filename atomically and works otherwise like io/ioutil.WriteFile()
Note that it won't follow symlinks and will replace existing symlinks with the real file
func AtomicWriteFileChown ¶
func ChDir ¶
ChDir runs runs "f" inside the given directory Note that this will only work reliable in a single-threaded context.
func CopySpecialFile ¶
CopySpecialFile is used to copy all the things that are not files (like device nodes, named pipes etc)
func DirUpdated ¶
DirUpdated compares two directories, and returns which files present in both have been updated, with the given prefix prepended.
Subdirectories are ignored.
This function is to compare the policies and templates in a (framework) snap to be installed, against the policies and templates of one already installed, to then determine what changed. The prefix is because policies and templates are specified with the framework name.
func EnsureDirState ¶
func EnsureDirState(dir, glob string, content map[string]*FileState) (changed, removed []string, err error)
EnsureDirState ensures that directory content matches expectations.
EnsureDirState enumerates all the files in the specified directory that match the provided pattern (glob). Each enumerated file is checked to ensure that the contents, permissions are what is desired. Unexpected files are removed. Missing files are created and differing files are corrected. Files not matching the pattern are ignored.
Note that EnsureDirState only checks for permissions and content. Other security mechanisms, including file ownership and extended attributes are *not* supported.
The content map describes each of the files that are intended to exist in the directory. Map keys must be file names relative to the directory. Sub-directories in the name are not allowed.
If writing any of the files fails, EnsureDirState switches to erase mode where *all* of the files managed by the glob pattern are removed (including those that may have been already written). The return value is an empty list of changed files, the real list of removed files and the first error.
If an error happens while removing files then such a file is not removed but the removal continues until the set of managed files matching the glob is exhausted.
In all cases, the function returns the first error it has encountered.
func EnsureFileState ¶
EnsureFileState ensures that the file is in the expected state. It will not attempt to remove the file if no content is provided.
func ExitCode ¶
ExitCode extract the exit code from the error of a failed cmd.Run() or the original error if its not a exec.ExitError
func FileDigest ¶
FileDigest computes a hash digest of the file using the given hash. It also returns the file size.
func FileExists ¶
FileExists return true if given path can be stat()ed by us. Note that it may return false on e.g. permission issues.
func FilesAreEqual ¶
FilesAreEqual compares the two files' contents and returns whether they are the same.
func IsDirectory ¶
IsDirectory return true if the given path can be stat()ed by us and is a directory. Note that it may return false on e.g. permission issues.
func MkdirAllChown ¶
MkdirAllChown is like os.MkdirAll but it calls os.Chown on any directories it creates.
Types ¶
type AddUserOptions ¶
type AtomicWriteFlags ¶
type AtomicWriteFlags uint
AtomicWriteFlags are a bitfield of flags for AtomicWriteFile
const ( // AtomicWriteFollow makes AtomicWriteFile follow symlinks AtomicWriteFollow AtomicWriteFlags = 1 << iota )
type CopyFlag ¶
type CopyFlag uint8
CopyFlag is used to tweak the behaviour of CopyFile
const ( // CopyFlagDefault is the default behaviour CopyFlagDefault CopyFlag = 0 // CopyFlagSync does a sync after copying the files CopyFlagSync CopyFlag = 1 << iota // CopyFlagOverwrite overwrites the target if it exists CopyFlagOverwrite // CopyFlagPreserveAll preserves mode,owner,time attributes CopyFlagPreserveAll )
type ErrCopySpecialFile ¶
type ErrCopySpecialFile struct {
// contains filtered or unexported fields
}
ErrCopySpecialFile is returned if a special file copy fails
func (ErrCopySpecialFile) Error ¶
func (e ErrCopySpecialFile) Error() string