syscallcompat: OpenNofollow: fix relPath="" case

Sometimes want to open baseDir itself. This case
was broken, fix it.
This commit is contained in:
Jakob Unterwurzacher 2017-12-05 23:08:55 +01:00
parent 47b13e0a8d
commit e604ce6dea
2 changed files with 11 additions and 0 deletions

View File

@ -27,6 +27,10 @@ func OpenNofollow(baseDir string, relPath string, flags int, mode uint32) (fd in
if err != nil {
return -1, err
}
// Caller wanted to open baseDir itself?
if relPath == "" {
return dirfd, nil
}
// Split the path into components and separate intermediate directories
// and the final basename
parts := strings.Split(relPath, "/")

View File

@ -34,4 +34,11 @@ func TestOpenNofollow(t *testing.T) {
if err != syscall.ELOOP {
t.Errorf("expected ELOOP, got %v", err)
}
// Check to see that the base dir can be opened as well
fd, err = OpenNofollow(tmpDir, "", syscall.O_RDONLY, 0)
if err != nil {
t.Errorf("cannot open base dir: %v", err)
} else {
syscall.Close(fd)
}
}