diff options
Diffstat (limited to 'libpod/util.go')
-rw-r--r-- | libpod/util.go | 40 |
1 files changed, 5 insertions, 35 deletions
diff --git a/libpod/util.go b/libpod/util.go index 3a15f9e39..b60575264 100644 --- a/libpod/util.go +++ b/libpod/util.go @@ -9,8 +9,7 @@ import ( "strings" "time" - "github.com/containers/image/signature" - "github.com/containers/image/types" + "github.com/containers/libpod/libpod/define" "github.com/fsnotify/fsnotify" spec "github.com/opencontainers/runtime-spec/specs-go" "github.com/pkg/errors" @@ -23,17 +22,6 @@ const ( DefaultTransport = "docker://" ) -// OpenExclusiveFile opens a file for writing and ensure it doesn't already exist -func OpenExclusiveFile(path string) (*os.File, error) { - baseDir := filepath.Dir(path) - if baseDir != "" { - if _, err := os.Stat(baseDir); err != nil { - return nil, err - } - } - return os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666) -} - // FuncTimer helps measure the execution time of a function // For debug purposes, do not leave in code // used like defer FuncTimer("foo") @@ -42,24 +30,6 @@ func FuncTimer(funcName string) { fmt.Printf("%s executed in %d ms\n", funcName, elapsed) } -// CopyStringStringMap deep copies a map[string]string and returns the result -func CopyStringStringMap(m map[string]string) map[string]string { - n := map[string]string{} - for k, v := range m { - n[k] = v - } - return n -} - -// GetPolicyContext creates a signature policy context for the given signature policy path -func GetPolicyContext(path string) (*signature.PolicyContext, error) { - policy, err := signature.DefaultPolicy(&types.SystemContext{SignaturePolicyPath: path}) - if err != nil { - return nil, err - } - return signature.NewPolicyContext(policy) -} - // RemoveScientificNotationFromFloat returns a float without any // scientific notation if the number has any. // golang does not handle conversion of float64s that have scientific @@ -126,7 +96,7 @@ func WaitForFile(path string, chWait chan error, timeout time.Duration) (bool, e return false, errors.Wrapf(err, "checking file %s", path) } case <-timeoutChan: - return false, errors.Wrapf(ErrInternal, "timed out waiting for file %s", path) + return false, errors.Wrapf(define.ErrInternal, "timed out waiting for file %s", path) } } } @@ -156,15 +126,15 @@ func sortMounts(m []spec.Mount) []spec.Mount { func validPodNSOption(p *Pod, ctrPod string) error { if p == nil { - return errors.Wrapf(ErrInvalidArg, "pod passed in was nil. Container may not be associated with a pod") + return errors.Wrapf(define.ErrInvalidArg, "pod passed in was nil. Container may not be associated with a pod") } if ctrPod == "" { - return errors.Wrapf(ErrInvalidArg, "container is not a member of any pod") + return errors.Wrapf(define.ErrInvalidArg, "container is not a member of any pod") } if ctrPod != p.ID() { - return errors.Wrapf(ErrInvalidArg, "pod passed in is not the pod the container is associated with") + return errors.Wrapf(define.ErrInvalidArg, "pod passed in is not the pod the container is associated with") } return nil } |