fix: Handle seeking over limits

This commit is contained in:
Felicitas Pojtinger
2022-01-26 00:21:48 +01:00
parent e93e9f7635
commit b3db4988d7

View File

@@ -292,7 +292,8 @@ func (f *File) seekWithoutLocking(offset int64, whence int) (int64, error) {
})
if f.info.IsDir() {
return -1, config.ErrIsDirectory
// Noop
return 0, nil
}
if f.writeBuf != nil {
@@ -353,7 +354,17 @@ func (f *File) seekWithoutLocking(offset int64, whence int) (int64, error) {
written, err := io.CopyN(io.Discard, f.readOpReader, dst-int64(f.readOpReader.BytesRead))
if err == io.EOF {
return written, io.EOF
// Noop
switch whence {
case io.SeekStart:
return offset, nil
case io.SeekCurrent:
return int64(f.readOpReader.BytesRead) + offset, nil
case io.SeekEnd:
return int64(f.info.Size()) - offset, nil
default:
return -1, config.ErrNotImplemented
}
}
if err != nil {