summaryrefslogtreecommitdiff
path: root/vendor/github.com/opencontainers/runtime-tools/filepath
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/opencontainers/runtime-tools/filepath')
-rw-r--r--vendor/github.com/opencontainers/runtime-tools/filepath/abs.go4
-rw-r--r--vendor/github.com/opencontainers/runtime-tools/filepath/clean.go26
2 files changed, 22 insertions, 8 deletions
diff --git a/vendor/github.com/opencontainers/runtime-tools/filepath/abs.go b/vendor/github.com/opencontainers/runtime-tools/filepath/abs.go
index c19bba26a..e4ab7453f 100644
--- a/vendor/github.com/opencontainers/runtime-tools/filepath/abs.go
+++ b/vendor/github.com/opencontainers/runtime-tools/filepath/abs.go
@@ -1,7 +1,6 @@
package filepath
import (
- "errors"
"regexp"
"strings"
)
@@ -11,9 +10,6 @@ var windowsAbs = regexp.MustCompile(`^[a-zA-Z]:\\.*$`)
// Abs is a version of path/filepath's Abs with an explicit operating
// system and current working directory.
func Abs(os, path, cwd string) (_ string, err error) {
- if os == "windows" {
- return "", errors.New("Abs() does not support windows yet")
- }
if IsAbs(os, path) {
return Clean(os, path), nil
}
diff --git a/vendor/github.com/opencontainers/runtime-tools/filepath/clean.go b/vendor/github.com/opencontainers/runtime-tools/filepath/clean.go
index b70c575f2..d5dd65ae1 100644
--- a/vendor/github.com/opencontainers/runtime-tools/filepath/clean.go
+++ b/vendor/github.com/opencontainers/runtime-tools/filepath/clean.go
@@ -30,6 +30,9 @@ func Clean(os, path string) string {
// Eliminate each inner .. path name element (the parent directory)
// along with the non-.. element that precedes it.
for i := 1; i < len(elements); i++ {
+ if i == 1 && abs && sep == '\\' {
+ continue
+ }
if i > 0 && elements[i] == ".." {
elements = append(elements[:i-1], elements[i+1:]...)
i -= 2
@@ -39,16 +42,31 @@ func Clean(os, path string) string {
// Eliminate .. elements that begin a rooted path:
// that is, replace "/.." by "/" at the beginning of a path,
// assuming Separator is '/'.
- if abs && len(elements) > 0 {
- for elements[0] == ".." {
- elements = elements[1:]
+ offset := 0
+ if sep == '\\' {
+ offset = 1
+ }
+ if abs {
+ for len(elements) > offset && elements[offset] == ".." {
+ elements = append(elements[:offset], elements[offset+1:]...)
}
}
cleaned := strings.Join(elements, string(sep))
if abs {
- cleaned = fmt.Sprintf("%c%s", sep, cleaned)
+ if sep == '/' {
+ cleaned = fmt.Sprintf("%c%s", sep, cleaned)
+ } else if len(elements) == 1 {
+ cleaned = fmt.Sprintf("%s%c", cleaned, sep)
+ }
}
+
+ // If the result of this process is an empty string, Clean returns
+ // the string ".".
+ if len(cleaned) == 0 {
+ cleaned = "."
+ }
+
if cleaned == path {
return path
}