Commit bd0fe66d authored by Kirill Smelkov's avatar Kirill Smelkov

Merge remote-tracking branch 'origin/master' into t

* origin/master:
  fs: add Options.{UID,GID} for setting default owners
  fs: always set Mode correctly for Setattr output
parents 9d5f7e99 cf139fc4
......@@ -462,4 +462,10 @@ type Options struct {
// DefaultPermissions sets null file permissions to 755 (dirs)
// or 644 (other files.)
DefaultPermissions bool
// If nonzero, replace default (zero) UID with the given UID
UID uint32
// If nonzero, replace default (zero) GID with the given GID
GID uint32
}
......@@ -152,6 +152,12 @@ func (b *rawBridge) setAttr(out *fuse.Attr) {
out.Mode |= 0111
}
}
if b.options.UID != 0 && out.Uid == 0 {
out.Uid = b.options.UID
}
if b.options.GID != 0 && out.Gid == 0 {
out.Gid = b.options.GID
}
}
func (b *rawBridge) setAttrTimeout(out *fuse.AttrOut) {
......@@ -427,14 +433,15 @@ func (b *rawBridge) SetAttr(cancel <-chan struct{}, in *fuse.SetAttrIn, out *fus
f = nil
}
var errno = syscall.ENOTSUP
if fops, ok := n.ops.(NodeSetattrer); ok {
return errnoToStatus(fops.Setattr(ctx, f, in, out))
}
if fops, ok := f.(FileSetattrer); ok {
return errnoToStatus(fops.Setattr(ctx, in, out))
errno = fops.Setattr(ctx, f, in, out)
} else if fops, ok := f.(FileSetattrer); ok {
errno = fops.Setattr(ctx, in, out)
}
return fuse.ENOTSUP
out.Mode = n.stableAttr.Mode | (out.Mode & 07777)
return errnoToStatus(errno)
}
func (b *rawBridge) Rename(cancel <-chan struct{}, input *fuse.RenameIn, oldName string, newName string) fuse.Status {
......
......@@ -38,6 +38,35 @@ func testMount(t *testing.T, root InodeEmbedder, opts *Options) (string, *fuse.S
}
}
func TestDefaultOwner(t *testing.T) {
want := "hello"
root := &Inode{}
mntDir, _, clean := testMount(t, root, &Options{
FirstAutomaticIno: 1,
OnAdd: func(ctx context.Context) {
n := root.EmbeddedInode()
ch := n.NewPersistentInode(
ctx,
&MemRegularFile{
Data: []byte(want),
},
StableAttr{})
n.AddChild("file", ch, false)
},
UID: 42,
GID: 43,
})
defer clean()
var st syscall.Stat_t
if err := syscall.Lstat(mntDir+"/file", &st); err != nil {
t.Fatalf("Lstat: %v", err)
} else if st.Uid != 42 || st.Gid != 43 {
t.Fatalf("Got Lstat %d, %d want 42,43", st.Uid, st.Gid)
}
}
func TestDataFile(t *testing.T) {
want := "hello"
root := &Inode{}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment