mount: check possible nil entry case

This commit is contained in:
chrislu 2022-07-22 15:33:37 -07:00
parent 0716092b39
commit a5c94acd4f
2 changed files with 10 additions and 1 deletions

View file

@ -48,7 +48,7 @@ func (wfs *WFS) SetAttr(cancel <-chan struct{}, input *fuse.SetAttrIn, out *fuse
defer fh.entryLock.Unlock() defer fh.entryLock.Unlock()
} }
if size, ok := input.GetSize(); ok { if size, ok := input.GetSize(); ok && entry != nil {
glog.V(4).Infof("%v setattr set size=%v chunks=%d", path, size, len(entry.Chunks)) glog.V(4).Infof("%v setattr set size=%v chunks=%d", path, size, len(entry.Chunks))
if size < filer.FileSize(entry) { if size < filer.FileSize(entry) {
// fmt.Printf("truncate %v \n", fullPath) // fmt.Printf("truncate %v \n", fullPath)
@ -141,6 +141,9 @@ func (wfs *WFS) setAttrByPbEntry(out *fuse.Attr, inode uint64, entry *filer_pb.E
out.Size = filer.FileSize(entry) out.Size = filer.FileSize(entry)
out.Blocks = (out.Size + blockSize - 1) / blockSize out.Blocks = (out.Size + blockSize - 1) / blockSize
setBlksize(out, blockSize) setBlksize(out, blockSize)
if entry == nil {
return
}
out.Mtime = uint64(entry.Attributes.Mtime) out.Mtime = uint64(entry.Attributes.Mtime)
out.Ctime = uint64(entry.Attributes.Mtime) out.Ctime = uint64(entry.Attributes.Mtime)
out.Atime = uint64(entry.Attributes.Mtime) out.Atime = uint64(entry.Attributes.Mtime)

View file

@ -106,6 +106,9 @@ func (wfs *WFS) SetXAttr(cancel <-chan struct{}, input *fuse.SetXAttrIn, attr st
if status != fuse.OK { if status != fuse.OK {
return status return status
} }
if entry == nil {
return fuse.ENOENT
}
if fh != nil { if fh != nil {
fh.entryLock.Lock() fh.entryLock.Lock()
defer fh.entryLock.Unlock() defer fh.entryLock.Unlock()
@ -181,6 +184,9 @@ func (wfs *WFS) RemoveXAttr(cancel <-chan struct{}, header *fuse.InHeader, attr
if status != fuse.OK { if status != fuse.OK {
return status return status
} }
if entry == nil {
return fuse.OK
}
if fh != nil { if fh != nil {
fh.entryLock.Lock() fh.entryLock.Lock()
defer fh.entryLock.Unlock() defer fh.entryLock.Unlock()