From fbd9cabd93b0eac097772436c64b5bcff6a5e4f4 Mon Sep 17 00:00:00 2001 From: Tommi Virtanen Date: Mon, 31 Aug 2015 18:03:59 -0700 Subject: [PATCH] fuse/ipns, fuse/readonly: Let the fuse library set defaults for Attr Without this, all entries will have nlink==0, which confuses a bunch of tools. Most dramatically, systemd-nspawn enters a busy loop in its lock utility function. License: MIT Signed-off-by: Tommi Virtanen --- fuse/ipns/ipns_unix.go | 20 ++++++++------------ fuse/ipns/link_unix.go | 4 +--- fuse/readonly/readonly_unix.go | 3 +-- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/fuse/ipns/ipns_unix.go b/fuse/ipns/ipns_unix.go index fd3e3a39e..91c3db55d 100644 --- a/fuse/ipns/ipns_unix.go +++ b/fuse/ipns/ipns_unix.go @@ -109,7 +109,7 @@ func CreateRoot(ipfs *core.IpfsNode, keys []ci.PrivKey, ipfspath, ipnspath strin // Attr returns file attributes. func (*Root) Attr(ctx context.Context, a *fuse.Attr) error { log.Debug("Root Attr") - *a = fuse.Attr{Mode: os.ModeDir | 0111} // -rw+x + a.Mode = os.ModeDir | 0111 // -rw+x return nil } @@ -219,11 +219,9 @@ type File struct { // Attr returns the attributes of a given node. func (d *Directory) Attr(ctx context.Context, a *fuse.Attr) error { log.Debug("Directory Attr") - *a = fuse.Attr{ - Mode: os.ModeDir | 0555, - Uid: uint32(os.Getuid()), - Gid: uint32(os.Getgid()), - } + a.Mode = os.ModeDir | 0555 + a.Uid = uint32(os.Getuid()) + a.Gid = uint32(os.Getgid()) return nil } @@ -235,12 +233,10 @@ func (fi *File) Attr(ctx context.Context, a *fuse.Attr) error { // In this case, the dag node in question may not be unixfs return fmt.Errorf("fuse/ipns: failed to get file.Size(): %s", err) } - *a = fuse.Attr{ - Mode: os.FileMode(0666), - Size: uint64(size), - Uid: uint32(os.Getuid()), - Gid: uint32(os.Getgid()), - } + a.Mode = os.FileMode(0666) + a.Size = uint64(size) + a.Uid = uint32(os.Getuid()) + a.Gid = uint32(os.Getgid()) return nil } diff --git a/fuse/ipns/link_unix.go b/fuse/ipns/link_unix.go index a8414a365..d45ce0283 100644 --- a/fuse/ipns/link_unix.go +++ b/fuse/ipns/link_unix.go @@ -16,9 +16,7 @@ type Link struct { func (l *Link) Attr(ctx context.Context, a *fuse.Attr) error { log.Debug("Link attr.") - *a = fuse.Attr{ - Mode: os.ModeSymlink | 0555, - } + a.Mode = os.ModeSymlink | 0555 return nil } diff --git a/fuse/readonly/readonly_unix.go b/fuse/readonly/readonly_unix.go index ffd32b369..ac5535947 100644 --- a/fuse/readonly/readonly_unix.go +++ b/fuse/readonly/readonly_unix.go @@ -46,7 +46,7 @@ type Root struct { // Attr returns file attributes. func (*Root) Attr(ctx context.Context, a *fuse.Attr) error { - *a = fuse.Attr{Mode: os.ModeDir | 0111} // -rw+x + a.Mode = os.ModeDir | 0111 // -rw+x return nil } @@ -118,7 +118,6 @@ func (s *Node) Attr(ctx context.Context, a *fuse.Attr) error { a.Size = uint64(len(s.cached.GetData())) a.Uid = uint32(os.Getuid()) a.Gid = uint32(os.Getgid()) - default: return fmt.Errorf("Invalid data type - %s", s.cached.GetType()) }