util

package
v0.0.0-...-cac7d87 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 10 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const SelfUpdateBackupSuffix = ".selfupdate-backup"

SelfUpdateBackupSuffix is appended to the running trdl binary's path while go-update swaps in a new version (see pkg/client.doSelfUpdate). It is our own convention rather than go-update's default ".<name>.old", so that the resolver below strips a suffix we control instead of matching against go-update's internals.

Variables

This section is empty.

Functions

func AtomicWriteFile

func AtomicWriteFile(dst string, data []byte, perm os.FileMode, tmpDir string) error

AtomicWriteFile writes data to dst atomically by first writing to a temporary file in tmpDir, then renaming. This is safe for concurrent use across processes.

func Exec

func Exec(path string, args []string) error

func ExpandPath

func ExpandPath(path string) (string, error)

func IsDirExist

func IsDirExist(path string) (bool, error)

func IsNotDirectoryErr

func IsNotDirectoryErr(err error) bool

func IsRegularFileExist

func IsRegularFileExist(path string) (bool, error)

func MurmurHash

func MurmurHash(args ...string) string

func ResolveTrdlOnDiskBinaryPath

func ResolveTrdlOnDiskBinaryPath() (string, error)

ResolveTrdlOnDiskBinaryPath returns an absolute path to a trdl binary that is (or is about to be) sitting on disk under a stable, non-transient name, suitable for two uses:

  • embedding into the generated source_script, so that later shells re- sourcing the file can exec that path;
  • forking the "trdl update" background process from "trdl use", so the child exec starts from a filename that will still exist.

On Linux /proc/self/exe (and therefore os.Executable) follows the running binary's inode across rename(2). While one trdl process is inside inconshreveable/go-update apply.go it renames "trdl" -> the OldSavePath we pass in ("trdl"+SelfUpdateBackupSuffix), swaps in the new binary as "trdl", and we then unlink the backup. A concurrent trdl process that reads os.Executable across that window observes the backup path, and — unfixed — embeds it into the source_script written by "trdl use". Later shells sourcing that file hit an about-to-be-unlinked path with "No such file or directory".

This helper resolves os.Executable freshly (no init-time cache, which used to fossilize a bad backup path for the whole life of any process that observed it once) and, if the path ends in SelfUpdateBackupSuffix, returns the stable sibling without the suffix. By the time a downstream shell exec's the embedded path the swap is long since done — go-update never lingers in the microsecond window between its two rename(2) calls.

Note the returned path may point at a *different* binary than the caller's own inode after self-update. That is intentional: we want the path a subsequent shell exec will resolve to, which is the new trdl on disk, not our ephemeral old inode.

func Sha512Checksum

func Sha512Checksum(data []byte) string

Types

type Metafile

type Metafile struct {
	// contains filtered or unexported fields
}

func NewMetafile

func NewMetafile(filePath string) Metafile

func (Metafile) Delete

func (f Metafile) Delete(locker lockgate.Locker) error

func (Metafile) Exists

func (f Metafile) Exists(locker lockgate.Locker) (exists bool, err error)

func (Metafile) HasBeenModifiedWithinPeriod

func (f Metafile) HasBeenModifiedWithinPeriod(locker lockgate.Locker, period time.Duration) (s bool, err error)

func (Metafile) Reset

func (f Metafile) Reset(locker lockgate.Locker) error

Jump to

Keyboard shortcuts

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