5. Use defer for closing file

This commit is contained in:
Yannick Ulrich 2023-02-26 13:09:00 +00:00
parent 9b9ab67217
commit c142d97ee8

View File

@ -335,6 +335,8 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
return nil, 0, syscall.EROFS
}
defer fp.Close()
buf := make([]byte, f.self.size);
nread, err := fp.Read(buf)
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()
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{
content: buf,