4. Better error handling

This commit is contained in:
Yannick Ulrich 2023-02-26 13:08:14 +00:00
parent a27cc090dd
commit 9b9ab67217

View File

@ -256,6 +256,10 @@ func (fh *bytesFileWriteHandle) Write(ctx context.Context, data []byte, off int6
var _ = (fs.FileFlusher)((*bytesFileWriteHandle)(nil))
func (fh *bytesFileWriteHandle) Flush(ctx context.Context) (errno syscall.Errno) {
if len(fh.content) == 0 {
return 0
}
log.Info("Attempting flush").Str("path", fh.path).Send()
fp, err := myfs.Create(fh.path, uint32(len(fh.content)))
if err != nil {
@ -268,6 +272,11 @@ func (fh *bytesFileWriteHandle) Flush(ctx context.Context) (errno syscall.Errno)
fp.Close()
return syscall.EROFS
}
if int(nread) != len(fh.content) {
log.Error("Flush failed: write").Str("path", fh.path).Int("expect", len(fh.content)).Int("got", int(nread)).Send()
fp.Close()
return syscall.EROFS
}
err = fp.Close()
if err != nil {
log.Error("Flush failed: close").Str("path", fh.path).Err(err).Send()