Ensure Close is always called

This commit is contained in:
Yannick Ulrich 2023-02-21 19:58:02 +00:00
parent 1a5970a041
commit afaa5990c4

View File

@ -246,6 +246,11 @@ func (fh *bytesFileWriteHandle) Flush(ctx context.Context) (errno syscall.Errno)
fp.Close()
return syscall.EROFS
}
err = fp.Close()
if err != nil {
log.Error("Flush failed: close").Str("path", fh.path).Err(err).Send()
return syscall.EROFS
}
log.Info("Flush done").Str("path", fh.path).Int("size", len(fh.content)).Send()
return 0
@ -303,6 +308,12 @@ func (f *ITNode) Open(ctx context.Context, openFlags uint32) (fh fs.FileHandle,
nread, err := fp.Read(buf)
if err != nil || nread != int(f.self.size) {
log.Error("Reading file failed").Str("path", f.path).Err(err).Send();
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
}