From 5af53d1dc68cfd5470152c18564b0fad8e70e67e Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Mon, 29 Aug 2022 14:05:33 -0700 Subject: [PATCH] Fix bug where the filesystem implementation misreports the amount of bytes written, causing functions such as io.Copy() to return an error --- blefs/file.go | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/blefs/file.go b/blefs/file.go index 4a4ee4e..bbe65da 100644 --- a/blefs/file.go +++ b/blefs/file.go @@ -3,7 +3,6 @@ package blefs import ( "io" "io/fs" - "path/filepath" "time" ) @@ -291,7 +290,7 @@ func (fl *File) Write(b []byte) (n int, err error) { } close(fl.offsetCh) - return int(fl.offset), nil + return int(fl.amtTferd), nil } // WriteString converts the string to []byte and calls Write() @@ -335,23 +334,9 @@ func (fl *File) Close() error { return nil } -// Stat does a RedDir() and finds the current file in the output +// Stat does a ReadDir() and finds the current file in the output func (fl *File) Stat() (fs.FileInfo, error) { - // Get directory in filepath - dir := filepath.Dir(fl.path) - // Read directory - dirEntries, err := fl.fs.ReadDir(dir) - if err != nil { - return nil, err - } - for _, entry := range dirEntries { - // If file name is base name of path - if entry.Name() == filepath.Base(fl.path) { - // Return file info - return entry.Info() - } - } - return nil, ErrFileNotExists + return fl.fs.Stat(fl.path) } // fileReadResponse represents a response for a read request