utils

package
v0.0.0-...-9ba49b0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	System = InitializeSystemFunctions()
	Bold   = color.New(color.Bold)

	StdinReader = bufio.NewReader(os.Stdin)
)

Functions

func AtomicallyWrite

func AtomicallyWrite(path string, data []byte) (err error)

func FilterEnv

func FilterEnv(keys []string) []string

FilterEnv selects only the specified variables from the environment and returns those key/value pairs, in the key=value format expected by os/exec.Cmd.Env.

func GetAddMirrorsConfig

func GetAddMirrorsConfig() string

func GetCoordinatorPostUpgradeBackupDir

func GetCoordinatorPostUpgradeBackupDir(backupDir string) string

func GetCoordinatorPreUpgradeBackupDir

func GetCoordinatorPreUpgradeBackupDir(backupDir string) string

func GetDataMigrationSeedDir

func GetDataMigrationSeedDir() string

func GetDefaultGeneratedDataMigrationScriptsDir

func GetDefaultGeneratedDataMigrationScriptsDir() (string, error)

func GetGpupgradePath

func GetGpupgradePath() (string, error)

func GetInitsystemConfig

func GetInitsystemConfig() string

func GetJSONFile

func GetJSONFile(stateDir string, fileName string) (path string, err error)

Returns path to a JSON file, and if one does not exist it creates an empty JSON file.

func GetLogDir

func GetLogDir() (string, error)

func GetOldTablespacesFile

func GetOldTablespacesFile(backupDir string) string

GetOldTablespacesFile is the file location used when backing up the user defined coordinator tablespaces. To upgrade tablespaces from 5->6 the --old-tablespaces-file is needed by pg_upgrade.

func GetPgUpgradeDir

func GetPgUpgradeDir(role string, contentID int32, pgUpgradeTimeStamp string, targetVersion string) (string, error)

func GetStateDir

func GetStateDir() string

func GetStateDirOldTablespacesFile

func GetStateDirOldTablespacesFile() string

GetStateDirOldTablespacesFile is the file location used when creating the old tablespaces file. To upgrade tablespaces from 5->6 the --old-tablespaces-file is needed by pg_upgrade.

func GetTablespaceBackupDir

func GetTablespaceBackupDir(backupDir string) string

func Move

func Move(src string, dst string) error

Calling os.Rename for a directory is allowed only when both the source and the destination path are on the top layer of filesystem. Otherwise, it returns EXDEV error ("cross-device link not permitted"). To avoid such case, use the Move utility instead of os.Rename. Found this issue on docker containers, when os.Rename was being used to archive the gpupgrade log directory.

func RemoveDuplicates

func RemoveDuplicates(input []string) []string

RemoveDuplicates removes any duplicates while preserving order

func ResetSystemFunctions

func ResetSystemFunctions()

func Sanitize

func Sanitize(ports []int) []int

Sanitize sorts and deduplicates a slice of ints.

Types

type NextActionErr

type NextActionErr struct {
	Err        error
	NextAction string
}

NextActionErr attaches the Help method to an existing error. This is used to tell the CLI's top level to print additional helper text AFTER the error message is printed.

func NewNextActionErr

func NewNextActionErr(err error, nextAction string) NextActionErr

func (NextActionErr) Error

func (n NextActionErr) Error() string

func (NextActionErr) Help

func (n NextActionErr) Help() string

type SystemFunctions

type SystemFunctions struct {
	Current      func() (*user.User, error)
	Getenv       func(key string) string
	Getpid       func() int
	Hostname     func() (string, error)
	IsNotExist   func(err error) bool
	LookupIP     func(host string) ([]net.IP, error)
	MkdirAll     func(path string, perm os.FileMode) error
	Now          func() time.Time
	Open         func(name string) (*os.File, error)
	OpenFile     func(name string, flag int, perm os.FileMode) (*os.File, error)
	Remove       func(name string) error
	RemoveAll    func(name string) error
	Rename       func(oldpath, newpath string) error
	ReadFile     func(filename string) ([]byte, error)
	ReadFileFS   func(fs.FS, string) ([]byte, error)
	WriteFile    func(filename string, data []byte, perm os.FileMode) error
	Stat         func(name string) (os.FileInfo, error)
	FilePathGlob func(pattern string) ([]string, error)
	Create       func(name string) (*os.File, error)
	Mkdir        func(name string, perm os.FileMode) error
	Symlink      func(oldname, newname string) error
	Lstat        func(name string) (os.FileInfo, error)
	ReadDirFS    func(fsys fs.FS, name string) ([]fs.DirEntry, error)
	StatFS       func(fsys fs.FS, name string) (fs.FileInfo, error)
	DirFS        func(dir string) fs.FS
}

func InitializeSystemFunctions

func InitializeSystemFunctions() *SystemFunctions

type TableRows

type TableRows [][]string

TableRows attaches sort.Interface to a slice of string slices.

func (TableRows) Len

func (t TableRows) Len() int

func (TableRows) Less

func (t TableRows) Less(i, j int) bool

func (TableRows) Swap

func (t TableRows) Swap(i, j int)

Directories

Path Synopsis
Package daemon provides utilities for programs that need to fork themselves into the background (for instance, a persistent server).
Package daemon provides utilities for programs that need to fork themselves into the background (for instance, a persistent server).

Jump to

Keyboard shortcuts

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