fusefronted: dirCache: fix bug handling ""

Bug looked like this:

  $ ls -l .
  total 0
  drwxrwxr-x. 2 jakob jakob 60 Jan  3 15:42 foo
  -rw-rw-r--. 1 jakob jakob  0 Jan  3 15:46 x

  $ ls -l .
  ls: cannot access '.': No such file or directory

(only happened when "" was in the dirCache)
This commit is contained in:
Jakob Unterwurzacher 2019-01-03 15:59:54 +01:00
parent bb9884549b
commit fcdb4bec09
2 changed files with 16 additions and 0 deletions

View File

@ -33,6 +33,10 @@ func (fs *FS) openBackingDir(relPath string) (dirfd int, cName string, err error
// Cache lookup
dirfd, iv := fs.dirCache.Lookup(dirRelPath)
if dirfd > 0 {
// If relPath is empty, cName is ".".
if relPath == "" {
return dirfd, ".", nil
}
name := filepath.Base(relPath)
cName = fs.nameTransform.EncryptAndHashName(name, iv)
return dirfd, cName, nil

View File

@ -37,6 +37,18 @@ func TestOpenBackingDir(t *testing.T) {
if cName != "." {
t.Fatal("cName should be .")
}
syscall.Close(dirfd)
// Again, but populate the cache for "" by looking up a non-existing file
fs.GetAttr("xyz1234", nil)
dirfd, cName, err = fs.openBackingDir("")
if err != nil {
t.Fatal(err)
}
if cName != "." {
t.Fatal("cName should be .")
}
err = syscallcompat.Faccessat(dirfd, cName, unix.R_OK)
if err != nil {
t.Error(err)