Skip to content

Commit

Permalink
ensure readEOFSeen reset after reseting cursor with Seek (#215)
Browse files Browse the repository at this point in the history
* ensure readEOFSeen reset after reseting cursor with Seek

* update changelog

* update changelog for next release
  • Loading branch information
dustin-schnee authored Nov 6, 2024
1 parent ee1b14f commit b7d1a07
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [6.22.0] - 2024-11-06
### Fixed
- [#214](https://github.com/C2FO/vfs/issues/214) Fix issue where s3 backend didn't reset `readEOFSeen` flag when resetting the file cursor during Seek operations.

## [6.21.0] - 2024-11-04
### Fixed
- Unit Test improvements: report underlying unit tests errors, always run test cases in a sub-test, always use test suite functions, use more specific assert functions where possible.
Expand Down
5 changes: 5 additions & 0 deletions backend/s3/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,11 @@ func (f *File) Seek(offset int64, whence int) (int64, error) {
}
f.cursorPos = pos

// Reset readEOFSeen if seeking to the beginning of the file
if f.cursorPos == 0 {
f.readEOFSeen = false
}

f.seekCalled = true
return f.cursorPos, nil
}
Expand Down
23 changes: 23 additions & 0 deletions backend/s3/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,29 @@ func (ts *fileTestSuite) TestSeek() {
ts.NoError(err, "Closing file should not produce an error")
}

func (ts *fileTestSuite) TestReadEOFSeenReset() {
contents := "hello world!"
file, err := fs.NewFile("bucket", "/tmp/hello.txt")
ts.NoError(err, "Shouldn't fail creating new file")

s3apiMock.On("HeadObject", mock.AnythingOfType("*s3.HeadObjectInput")).
Return(&s3.HeadObjectOutput{ContentLength: aws.Int64(int64(len(contents)))}, nil).
Maybe()

s3apiMock.On("GetObject", mock.AnythingOfType("*s3.GetObjectInput")).
Return(&s3.GetObjectOutput{Body: io.NopCloser(strings.NewReader(contents))}, nil).
Once()

_, err = io.ReadAll(file)
ts.NoError(err, "Shouldn't fail reading file")
ts.True(file.(*File).readEOFSeen, "readEOFSeen should be true after reading the file")

// Reset cursor to the beginning of the file
_, err = file.Seek(0, io.SeekStart)
ts.NoError(err, "Shouldn't fail seeking file")
ts.False(file.(*File).readEOFSeen, "readEOFSeen should be reset after seeking to the beginning")
}

func (ts *fileTestSuite) TestGetLocation() {
file, err := fs.NewFile("bucket", "/path/hello.txt")
ts.NoError(err, "Shouldn't fail creating new file.")
Expand Down

0 comments on commit b7d1a07

Please sign in to comment.