Documentation ¶
Index ¶
- func AddExtraUser(name string, sshKeys []string) error
- func AtomicWriteFile(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 CurrentHomeDir() (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 ExitCode(runErr error) (e int, err 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 IsUIDInAny(uid uint32, groups ...string) bool
- type AtomicWriteFlags
- type CopyFlag
- type ErrCopySpecialFile
- type FileState
- type Group
- type Winsize
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddExtraUser ¶
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 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 CurrentHomeDir ¶
CurrentHomeDir returns the homedir of the current user. It looks at $HOME first and then at passwd
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 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 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 IsUIDInAny ¶
IsUIDInAny checks whether the given user belongs to any of the given groups
Types ¶
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