2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-07 03:20:49 +00:00

Merge pull request #3141 from MichaelEischer/fix-fuse-dir-owner

fuse: Properly set uid/gid for directories
This commit is contained in:
Alexander Neumann 2020-12-01 16:06:24 +01:00 committed by GitHub
commit 43cf301450
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 4 deletions

View File

@ -0,0 +1,8 @@
Bugfix: Use correct directory owner in fuse mount
Restic 0.10.0 changed the fuse mount to always report the current user
as the owner of directories within the fuse mount, which is incorrect.
We have changed this back to use the correct owner of a directory.
https://github.com/restic/restic/issues/2563
https://github.com/restic/restic/pull/3141

View File

@ -111,8 +111,11 @@ func (d *dir) Attr(ctx context.Context, a *fuse.Attr) error {
debug.Log("Attr()")
a.Inode = d.inode
a.Mode = os.ModeDir | d.node.Mode
a.Uid = d.root.uid
a.Gid = d.root.gid
if !d.root.cfg.OwnerIsRoot {
a.Uid = d.node.UID
a.Gid = d.node.GID
}
a.Atime = d.node.AccessTime
a.Ctime = d.node.ChangeTime
a.Mtime = d.node.ModTime

View File

@ -187,6 +187,37 @@ func TestFuseFile(t *testing.T) {
}
}
func TestFuseDir(t *testing.T) {
repo, cleanup := repository.TestRepository(t)
defer cleanup()
root := &Root{repo: repo, blobCache: newBlobCache(blobCacheSize)}
node := &restic.Node{
Mode: 0755,
UID: 42,
GID: 43,
AccessTime: time.Unix(1606773731, 0),
ChangeTime: time.Unix(1606773732, 0),
ModTime: time.Unix(1606773733, 0),
}
parentInode := fs.GenerateDynamicInode(0, "parent")
inode := fs.GenerateDynamicInode(1, "foo")
d, err := newDir(context.TODO(), root, inode, parentInode, node)
rtest.OK(t, err)
// don't open the directory as that would require setting up a proper tree blob
attr := fuse.Attr{}
rtest.OK(t, d.Attr(context.TODO(), &attr))
rtest.Equals(t, inode, attr.Inode)
rtest.Equals(t, node.UID, attr.Uid)
rtest.Equals(t, node.GID, attr.Gid)
rtest.Equals(t, node.AccessTime, attr.Atime)
rtest.Equals(t, node.ChangeTime, attr.Ctime)
rtest.Equals(t, node.ModTime, attr.Mtime)
}
// Test top-level directories for their UID and GID.
func TestTopUidGid(t *testing.T) {
repo, cleanup := repository.TestRepository(t)
@ -222,8 +253,9 @@ func testTopUidGid(t *testing.T, cfg Config, repo restic.Repository, uid, gid ui
snapshotdir, err := idsdir.(fs.NodeStringLookuper).Lookup(ctx, snapID)
rtest.OK(t, err)
// restic.TestCreateSnapshot does not set the UID/GID thus it must be always zero
err = snapshotdir.Attr(ctx, &attr)
rtest.OK(t, err)
rtest.Equals(t, uid, attr.Uid)
rtest.Equals(t, gid, attr.Gid)
rtest.Equals(t, uint32(0), attr.Uid)
rtest.Equals(t, uint32(0), attr.Gid)
}