Fix bug where the filesystem implementation misreports the amount of bytes written, causing functions such as io.Copy() to return an error
This commit is contained in:
parent
a1a289efc9
commit
1bf8ee4e7a
@ -3,7 +3,6 @@ package blefs
|
|||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"path/filepath"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -291,7 +290,7 @@ func (fl *File) Write(b []byte) (n int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
close(fl.offsetCh)
|
close(fl.offsetCh)
|
||||||
return int(fl.offset), nil
|
return int(fl.amtTferd), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteString converts the string to []byte and calls Write()
|
// WriteString converts the string to []byte and calls Write()
|
||||||
@ -335,23 +334,9 @@ func (fl *File) Close() error {
|
|||||||
return nil
|
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) {
|
func (fl *File) Stat() (fs.FileInfo, error) {
|
||||||
// Get directory in filepath
|
return fl.fs.Stat(fl.path)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fileReadResponse represents a response for a read request
|
// fileReadResponse represents a response for a read request
|
||||||
|
Reference in New Issue
Block a user