Documentation ¶
Index ¶
- Variables
- 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 CopyIfDifferent(src, dst string) error
- func CopySpecialFile(path, dest string) error
- func CurrentHomeDir() (string, error)
- func DirUpdated(dirA, dirB, pfx string) map[string]bool
- func ExitCode(runErr error) (e int, err error)
- func FileExists(path string) bool
- func FilesAreEqual(a, b string) bool
- func GetBasicSnapEnvVars(desc interface{}) []string
- func GetDeprecatedBasicSnapEnvVars(desc interface{}) []string
- func GetDeprecatedUserSnapEnvVars(desc interface{}) []string
- func GetUserSnapEnvVars(desc interface{}) []string
- func Getattr(i interface{}, name string) interface{}
- func IsDevice(mode os.FileMode) bool
- func IsDirectory(path string) bool
- func IsSupportedArchitecture(architectures []string) bool
- func IsSymlink(mode os.FileMode) bool
- func MajorMinor(info os.FileInfo) (uint32, uint32, error)
- func MakeMapFromEnvList(env []string) map[string]string
- func Makedev(major, minor uint32) uint32
- func NewSideloadVersion() string
- func RSyncWithDelete(srcDirName, destDirName string) error
- func Sha512sum(infile string) (hexdigest string, err error)
- func ShouldDropPrivs() bool
- func TarIterate(r io.Reader, fn TarIterFunc) error
- func UbuntuArchitecture() string
- func UnpackTar(r io.Reader, targetDir string, fn UnpackTarTransformFunc) error
- func UpdateTimestamp(pathname string) error
- type AtomicWriteFlags
- type CopyFlag
- type ErrCopySpecialFile
- type ErrUnsupportedFileType
- type TarIterFunc
- type UnpackTarTransformFunc
- type Winsize
Constants ¶
This section is empty.
Variables ¶
var ErrNotAbsPath = errors.New("not an absolute path")
ErrNotAbsPath is returned when an absolute path is needed but the received path is not.
var MakeRandomString = func(length int) string { out := "" for i := 0; i < length; i++ { out += string(letters[rand.Intn(len(letters))]) } return out }
MakeRandomString returns a random string of length length
Functions ¶
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 CopyIfDifferent ¶
CopyIfDifferent copies src to dst only if dst is different that src
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) click 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 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 GetBasicSnapEnvVars ¶
func GetBasicSnapEnvVars(desc interface{}) []string
GetBasicSnapEnvVars returns the app-level environment variables for a snap. Despite this being a bit snap-specific, this is in helpers.go because it's used by so many other modules, we run into circular dependencies if it's somewhere more reasonable like the snappy module.
func GetDeprecatedBasicSnapEnvVars ¶
func GetDeprecatedBasicSnapEnvVars(desc interface{}) []string
GetDeprecatedBasicSnapEnvVars returns the app-level deprecated environment variables for a snap. Despite this being a bit snap-specific, this is in helpers.go because it's used by so many other modules, we run into circular dependencies if it's somewhere more reasonable like the snappy module.
func GetDeprecatedUserSnapEnvVars ¶
func GetDeprecatedUserSnapEnvVars(desc interface{}) []string
GetDeprecatedUserSnapEnvVars returns the user-level deprecated environment variables for a snap. Despite this being a bit snap-specific, this is in helpers.go because it's used by so many other modules, we run into circular dependencies if it's somewhere more reasonable like the snappy module.
func GetUserSnapEnvVars ¶
func GetUserSnapEnvVars(desc interface{}) []string
GetUserSnapEnvVars returns the user-level environment variables for a snap. Despite this being a bit snap-specific, this is in helpers.go because it's used by so many other modules, we run into circular dependencies if it's somewhere more reasonable like the snappy module.
func Getattr ¶
func Getattr(i interface{}, name string) interface{}
Getattr get the attribute of the given name
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 IsSupportedArchitecture ¶
IsSupportedArchitecture returns true if the system architecture is in the list of architectures.
func MajorMinor ¶
MajorMinor returns the major/minor number of the given os.FileInfo
func MakeMapFromEnvList ¶
MakeMapFromEnvList takes a string list of the form "key=value" and returns a map[string]string from that list This is useful for os.Environ() manipulation
func NewSideloadVersion ¶
func NewSideloadVersion() string
NewSideloadVersion returns a version number such that later calls should return versions that compare larger.
func RSyncWithDelete ¶
RSyncWithDelete syncs srcDir to destDir
func ShouldDropPrivs ¶
func ShouldDropPrivs() bool
ShouldDropPrivs returns true if the application runs with sufficient privileges so that it should drop them
func TarIterate ¶
func TarIterate(r io.Reader, fn TarIterFunc) error
TarIterate will take a io.Reader and call the fn callback on each tar archive member
func UbuntuArchitecture ¶
func UbuntuArchitecture() string
UbuntuArchitecture returns the debian equivalent architecture for the currently running architecture.
If the architecture does not map any debian architecture, the GOARCH is returned.
func UnpackTar ¶
func UnpackTar(r io.Reader, targetDir string, fn UnpackTarTransformFunc) error
UnpackTar unpacks the given tar file into the target directory
func UpdateTimestamp ¶
UpdateTimestamp updates the timestamp of the file at pathname. It does not create it if it does not exist. It does not dereference it if it is a symlink. It's like `touch -c -h pathname`.
pathname must be absolute.
Types ¶
type AtomicWriteFlags ¶
type AtomicWriteFlags uint
AtomicWriteFlags are a bitfield of flags for AtomicWriteFile
const ( // AtomicWriteFollow makes AtomicWriteFile follows symlinks AtomicWriteFollow AtomicWriteFlags = 1 << iota )
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
type ErrUnsupportedFileType ¶
ErrUnsupportedFileType is returned when trying to extract a file that is not a regular file, a directory, or a symlink.
func (ErrUnsupportedFileType) Error ¶
func (e ErrUnsupportedFileType) Error() string
type TarIterFunc ¶
TarIterFunc is called for each file inside a tar archive
type UnpackTarTransformFunc ¶
UnpackTarTransformFunc can be used to change the names during unpack or to return a error for files that are not acceptable