aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/opencontainers/runtime-tools/filepath/clean.go
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2017-12-18 13:53:42 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2017-12-18 21:19:30 +0000
commit34572abc707f2684cfcbfb64222497aeb842d662 (patch)
tree53d6190c5cb9d9142bdd18627fda2437c5ae7f14 /vendor/github.com/opencontainers/runtime-tools/filepath/clean.go
parent5770dc2640c216525ab84031e3712fcc46b3b087 (diff)
downloadpodman-34572abc707f2684cfcbfb64222497aeb842d662.tar.gz
podman-34572abc707f2684cfcbfb64222497aeb842d662.tar.bz2
podman-34572abc707f2684cfcbfb64222497aeb842d662.zip
Vendor in latest storage, image and runtime-tools
Need to pull in the latest containers/storage and containers/image to fix lots of issues. Also want to update runtime-tools to take advantage of newer generate code. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com> Closes: #152 Approved by: rhatdan
Diffstat (limited to 'vendor/github.com/opencontainers/runtime-tools/filepath/clean.go')
-rw-r--r--vendor/github.com/opencontainers/runtime-tools/filepath/clean.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/vendor/github.com/opencontainers/runtime-tools/filepath/clean.go b/vendor/github.com/opencontainers/runtime-tools/filepath/clean.go
new file mode 100644
index 000000000..b70c575f2
--- /dev/null
+++ b/vendor/github.com/opencontainers/runtime-tools/filepath/clean.go
@@ -0,0 +1,56 @@
+package filepath
+
+import (
+ "fmt"
+ "strings"
+)
+
+// Clean is an explicit-OS version of path/filepath's Clean.
+func Clean(os, path string) string {
+ abs := IsAbs(os, path)
+ sep := Separator(os)
+ elements := strings.Split(path, string(sep))
+
+ // Replace multiple Separator elements with a single one.
+ for i := 0; i < len(elements); i++ {
+ if len(elements[i]) == 0 {
+ elements = append(elements[:i], elements[i+1:]...)
+ i--
+ }
+ }
+
+ // Eliminate each . path name element (the current directory).
+ for i := 0; i < len(elements); i++ {
+ if elements[i] == "." && len(elements) > 1 {
+ elements = append(elements[:i], elements[i+1:]...)
+ i--
+ }
+ }
+
+ // 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 > 0 && elements[i] == ".." {
+ elements = append(elements[:i-1], elements[i+1:]...)
+ i -= 2
+ }
+ }
+
+ // 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:]
+ }
+ }
+
+ cleaned := strings.Join(elements, string(sep))
+ if abs {
+ cleaned = fmt.Sprintf("%c%s", sep, cleaned)
+ }
+ if cleaned == path {
+ return path
+ }
+ return Clean(os, cleaned)
+}