mirror of
https://github.com/containers/podman.git
synced 2025-11-14 01:57:58 +08:00
vendor c/common
Also update the e2e pull test to account for the changes when pulling from the dir transport. Images pulled via the dir transport are not tagged anymore; the path is not a reliable source. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
24
vendor/github.com/containers/common/pkg/util/util.go
generated
vendored
Normal file
24
vendor/github.com/containers/common/pkg/util/util.go
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
package util
|
||||
|
||||
import "regexp"
|
||||
|
||||
// StringInSlice determines if a string is in a string slice, returns bool
|
||||
func StringInSlice(s string, sl []string) bool {
|
||||
for _, i := range sl {
|
||||
if i == s {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// StringMatchRegexSlice determines if a given string matches one of the given regexes, returns bool
|
||||
func StringMatchRegexSlice(s string, re []string) bool {
|
||||
for _, r := range re {
|
||||
m, err := regexp.MatchString(r, s)
|
||||
if err == nil && m {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
80
vendor/github.com/containers/common/pkg/util/util_supported.go
generated
vendored
Normal file
80
vendor/github.com/containers/common/pkg/util/util_supported.go
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
// +build linux darwin
|
||||
|
||||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
"github.com/containers/storage/pkg/unshare"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var (
|
||||
rootlessRuntimeDirOnce sync.Once
|
||||
rootlessRuntimeDir string
|
||||
)
|
||||
|
||||
// GetRuntimeDir returns the runtime directory
|
||||
func GetRuntimeDir() (string, error) {
|
||||
var rootlessRuntimeDirError error
|
||||
|
||||
rootlessRuntimeDirOnce.Do(func() {
|
||||
runtimeDir := os.Getenv("XDG_RUNTIME_DIR")
|
||||
if runtimeDir != "" {
|
||||
st, err := os.Stat(runtimeDir)
|
||||
if err != nil {
|
||||
rootlessRuntimeDirError = err
|
||||
return
|
||||
}
|
||||
if int(st.Sys().(*syscall.Stat_t).Uid) != os.Geteuid() {
|
||||
rootlessRuntimeDirError = fmt.Errorf("XDG_RUNTIME_DIR directory %q is not owned by the current user", runtimeDir)
|
||||
return
|
||||
}
|
||||
}
|
||||
uid := fmt.Sprintf("%d", unshare.GetRootlessUID())
|
||||
if runtimeDir == "" {
|
||||
tmpDir := filepath.Join("/run", "user", uid)
|
||||
if err := os.MkdirAll(tmpDir, 0700); err != nil {
|
||||
logrus.Debugf("unable to make temp dir: %v", err)
|
||||
}
|
||||
st, err := os.Stat(tmpDir)
|
||||
if err == nil && int(st.Sys().(*syscall.Stat_t).Uid) == os.Geteuid() && st.Mode().Perm() == 0700 {
|
||||
runtimeDir = tmpDir
|
||||
}
|
||||
}
|
||||
if runtimeDir == "" {
|
||||
tmpDir := filepath.Join(os.TempDir(), fmt.Sprintf("podman-run-%s", uid))
|
||||
if err := os.MkdirAll(tmpDir, 0700); err != nil {
|
||||
logrus.Debugf("unable to make temp dir %v", err)
|
||||
}
|
||||
st, err := os.Stat(tmpDir)
|
||||
if err == nil && int(st.Sys().(*syscall.Stat_t).Uid) == os.Geteuid() && st.Mode().Perm() == 0700 {
|
||||
runtimeDir = tmpDir
|
||||
}
|
||||
}
|
||||
if runtimeDir == "" {
|
||||
home := os.Getenv("HOME")
|
||||
if home == "" {
|
||||
rootlessRuntimeDirError = errors.New("neither XDG_RUNTIME_DIR nor HOME was set non-empty")
|
||||
return
|
||||
}
|
||||
resolvedHome, err := filepath.EvalSymlinks(home)
|
||||
if err != nil {
|
||||
rootlessRuntimeDirError = errors.Wrap(err, "cannot resolve home")
|
||||
return
|
||||
}
|
||||
runtimeDir = filepath.Join(resolvedHome, "rundir")
|
||||
}
|
||||
rootlessRuntimeDir = runtimeDir
|
||||
})
|
||||
|
||||
if rootlessRuntimeDirError != nil {
|
||||
return "", rootlessRuntimeDirError
|
||||
}
|
||||
return rootlessRuntimeDir, nil
|
||||
}
|
||||
12
vendor/github.com/containers/common/pkg/util/util_windows.go
generated
vendored
Normal file
12
vendor/github.com/containers/common/pkg/util/util_windows.go
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
// +build windows
|
||||
|
||||
package util
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// getRuntimeDir returns the runtime directory
|
||||
func GetRuntimeDir() (string, error) {
|
||||
return "", errors.New("this function is not implemented for windows")
|
||||
}
|
||||
Reference in New Issue
Block a user