fusefrontend: fix setting xattrs on directories

Directories cannot be opened read-write. Retry with RDONLY.
This commit is contained in:
Jakob Unterwurzacher 2019-01-04 22:22:24 +01:00
parent 3365cfc02b
commit eff35e60b6
2 changed files with 18 additions and 0 deletions

View File

@ -71,6 +71,10 @@ func (fs *FS) SetXAttr(relPath string, attr string, data []byte, flags int, cont
// O_NONBLOCK to not block on FIFOs.
fd, err := fs.openBackingFile(relPath, syscall.O_WRONLY|syscall.O_NONBLOCK)
// Directories cannot be opened read-write. Retry.
if err == syscall.EISDIR {
fd, err = fs.openBackingFile(relPath, syscall.O_RDONLY|syscall.O_DIRECTORY|syscall.O_NONBLOCK)
}
if err != nil {
return fuse.ToStatus(err)
}
@ -100,6 +104,10 @@ func (fs *FS) RemoveXAttr(relPath string, attr string, context *fuse.Context) fu
// O_NONBLOCK to not block on FIFOs.
fd, err := fs.openBackingFile(relPath, syscall.O_WRONLY|syscall.O_NONBLOCK)
// Directories cannot be opened read-write. Retry.
if err == syscall.EISDIR {
fd, err = fs.openBackingFile(relPath, syscall.O_RDONLY|syscall.O_DIRECTORY|syscall.O_NONBLOCK)
}
if err != nil {
return fuse.ToStatus(err)
}

View File

@ -124,6 +124,16 @@ func TestSetGetRmFifo(t *testing.T) {
setGetRmList(fn)
}
// Test xattr set, get, rm on a directory. This should not fail with EISDIR.
func TestSetGetRmDir(t *testing.T) {
fn := test_helpers.DefaultPlainDir + "/TestSetGetRmDir"
err := syscall.Mkdir(fn, 0700)
if err != nil {
t.Fatalf("creating fifo failed: %v", err)
}
setGetRmList(fn)
}
func TestXattrSetEmpty(t *testing.T) {
attr := "user.foo"
fn := test_helpers.DefaultPlainDir + "/TestXattrSetEmpty1"