5. Use defer for closing file
This commit is contained in:
parent
9b9ab67217
commit
c142d97ee8
7
fuse.go
7
fuse.go
@ -335,6 +335,8 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
|
|||||||
return nil, 0, syscall.EROFS
|
return nil, 0, syscall.EROFS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer fp.Close()
|
||||||
|
|
||||||
buf := make([]byte, f.self.size);
|
buf := make([]byte, f.self.size);
|
||||||
nread, err := fp.Read(buf)
|
nread, err := fp.Read(buf)
|
||||||
if err != nil || nread != int(f.self.size) {
|
if err != nil || nread != int(f.self.size) {
|
||||||
@ -342,11 +344,6 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
|
|||||||
fp.Close()
|
fp.Close()
|
||||||
return nil, 0, syscall.EROFS
|
return nil, 0, syscall.EROFS
|
||||||
}
|
}
|
||||||
err = fp.Close()
|
|
||||||
if err != nil {
|
|
||||||
log.Error("Closing file failed").Str("path", f.path).Err(err).Send();
|
|
||||||
return nil, 0, syscall.EROFS
|
|
||||||
}
|
|
||||||
|
|
||||||
fh = &bytesFileReadHandle{
|
fh = &bytesFileReadHandle{
|
||||||
content: buf,
|
content: buf,
|
||||||
|
Loading…
Reference in New Issue
Block a user