From 9b9ab672170f1357e3318009316d3c1cfebbbbb2 Mon Sep 17 00:00:00 2001 From: Yannick Ulrich Date: Sun, 26 Feb 2023 13:08:14 +0000 Subject: [PATCH] 4. Better error handling --- fuse.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fuse.go b/fuse.go index 7921f97..2a7f6eb 100644 --- a/fuse.go +++ b/fuse.go @@ -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()