utils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const NvidiaCLI = "nvidia-container-cli"

NvidiaCLI is the path to the Nvidia helper binary

Variables

This section is empty.

Functions

func Chtimes

func Chtimes(name string, atime time.Time, mtime time.Time) error

Chtimes changes the access time and modified time of a file at the given path. If the modified time is prior to the Unix Epoch (unixMinTime), or after the end of Unix Time (unixEpochTime), os.Chtimes has undefined behavior. In this case, Chtimes defaults to Unix Epoch, just in case.

func CombineURL

func CombineURL(parts ...string) string

func Copy

func Copy(src, dstDir string, chownRoot bool) error

func Download

func Download(rawurl string, directory string, filename string) (savedname string, err error)

func DownloadDisabledTLS

func DownloadDisabledTLS(rawurl string, directory string, filename string) (savedname string, err error)

func DownloadWithHeader

func DownloadWithHeader(rawurl string, directory string, filename string, header map[string]string) (savedname string, err error)

func EnsureDir

func EnsureDir(path string, perm fs.FileMode) error

ensureDir checks if a path exists and is a directory. If the path does not exist, it tries to create the directory. If the path is a file, it returns an error.

func HttpGet

func HttpGet(url string) (body []byte, statusCode int, err error)

func IsNotExist

func IsNotExist(err error) bool

IsNotExist tells you if err is an error that implies that either the path accessed does not exist (or path components don't exist). This is effectively a more broad version of os.IsNotExist.

func IsURL

func IsURL(str string) bool

func LUtimesNano

func LUtimesNano(path string, ts []syscall.Timespec) error

LUtimesNano is used to change access and modification time of the specified path. It's used for symbol link file because unix.UtimesNano doesn't support a NOFOLLOW flag atm.

func Max

func Max[T Comparable](a, b T) T

func Min

func Min[T Comparable](a, b T) T

func PathExists

func PathExists(path string) bool

func SaveJsonFile

func SaveJsonFile(x interface{}, path string) (err error)

func SecureJoin

func SecureJoin(root, unsafePath string) (string, error)

SecureJoinVFS joins the two given path components (similar to Join) except that the returned path is guaranteed to be scoped inside the provided root path (when evaluated). Any symbolic links in the path are evaluated with the given root treated as the root of the filesystem, similar to a chroot. The filesystem state is evaluated through the given VFS interface (if nil, the standard os.* family of functions are used).

Note that the guarantees provided by this function only apply if the path components in the returned string are not modified (in other words are not replaced with symlinks on the filesystem) after this function has returned. Such a symlink race is necessarily out-of-scope of SecureJoin.

NOTE: Due to the above limitation, Linux users are strongly encouraged to use OpenInRoot instead, which does safely protect against these kinds of attacks. There is no way to solve this problem with SecureJoinVFS because the API is fundamentally wrong (you cannot return a "safe" path string and guarantee it won't be modified afterwards).

Volume names in unsafePath are always discarded, regardless if they are provided via direct input or when evaluating symlinks. Therefore:

"C:\Temp" + "D:\path\to\file.txt" results in "C:\Temp\path\to\file.txt"

func SliceContains

func SliceContains[T comparable](s []T, elem T) bool

func SliceDelete

func SliceDelete[T comparable](s []T, elem T) []T

func SliceDigest

func SliceDigest[T any](s []T) string

func SliceIndex

func SliceIndex[T Comparable](s []T, elem T) int

func URLtoFilename

func URLtoFilename(url string) (filename string)

func UnescapeURL

func UnescapeURL(encodedURL string) (string, error)

func WithGPUs

func WithGPUs(s *specs.Spec) error

Types

type Capability

type Capability string

Capability specifies capabilities for the gpu inside the container Detailed explanation of options can be found: https://github.com/nvidia/nvidia-container-runtime#supported-driver-capabilities

const (
	// Compute capability
	Compute Capability = "compute"
	// Compat32 capability
	Compat32 Capability = "compat32"
	// Graphics capability
	Graphics Capability = "graphics"
	// Utility capability
	Utility Capability = "utility"
	// Video capability
	Video Capability = "video"
	// Display capability
	Display Capability = "display"
)

func AllCaps

func AllCaps() []Capability

AllCaps returns the complete list of supported Nvidia capabilities.

type Comparable

type Comparable interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~float32 | ~float64 | string
}

Jump to

Keyboard shortcuts

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