summaryrefslogtreecommitdiffhomepage
path: root/pkg/fspath/fspath.go
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2019-12-23 21:31:00 +0000
committergVisor bot <gvisor-bot@google.com>2019-12-23 21:31:00 +0000
commit6ca36534a7488487185aa5bb4922fdcfb2a1bda9 (patch)
treed9155a9c15ca7200e1c0bc0efa7d44d575cea351 /pkg/fspath/fspath.go
parent245d8491449119807b919d3994a62c92210c2cc0 (diff)
parentf45df7505b0e7baf48a37f7c625f05051d144738 (diff)
Merge release-20191213.0-46-gf45df75 (automated)
Diffstat (limited to 'pkg/fspath/fspath.go')
-rwxr-xr-xpkg/fspath/fspath.go24
1 files changed, 14 insertions, 10 deletions
diff --git a/pkg/fspath/fspath.go b/pkg/fspath/fspath.go
index f68752560..9fb3fee24 100755
--- a/pkg/fspath/fspath.go
+++ b/pkg/fspath/fspath.go
@@ -18,19 +18,17 @@ package fspath
import (
"strings"
-
- "gvisor.dev/gvisor/pkg/syserror"
)
const pathSep = '/'
-// Parse parses a pathname as described by path_resolution(7).
-func Parse(pathname string) (Path, error) {
+// Parse parses a pathname as described by path_resolution(7), except that
+// empty pathnames will be parsed successfully to a Path for which
+// Path.Absolute == Path.Dir == Path.HasComponents() == false. (This is
+// necessary to support AT_EMPTY_PATH.)
+func Parse(pathname string) Path {
if len(pathname) == 0 {
- // "... POSIX decrees that an empty pathname must not be resolved
- // successfully. Linux returns ENOENT in this case." -
- // path_resolution(7)
- return Path{}, syserror.ENOENT
+ return Path{}
}
// Skip leading path separators.
i := 0
@@ -41,7 +39,7 @@ func Parse(pathname string) (Path, error) {
return Path{
Absolute: true,
Dir: true,
- }, nil
+ }
}
}
// Skip trailing path separators. This is required by Iterator.Next. This
@@ -64,7 +62,7 @@ func Parse(pathname string) (Path, error) {
},
Absolute: i != 0,
Dir: j != len(pathname)-1,
- }, nil
+ }
}
// Path contains the information contained in a pathname string.
@@ -111,6 +109,12 @@ func (p Path) String() string {
return b.String()
}
+// HasComponents returns true if p contains a non-zero number of path
+// components.
+func (p Path) HasComponents() bool {
+ return p.Begin.Ok()
+}
+
// An Iterator represents either a path component in a Path or a terminal
// iterator indicating that the end of the path has been reached.
//