Skip to content
This repository has been archived by the owner on Jun 25, 2022. It is now read-only.

virtualfile.read can lead to infinite loops #249

Open
ghost opened this issue Nov 8, 2019 · 0 comments
Open

virtualfile.read can lead to infinite loops #249

ghost opened this issue Nov 8, 2019 · 0 comments
Labels
bug Something isn't working

Comments

@ghost
Copy link

ghost commented Nov 8, 2019

I had an issue while using Packr with Gomigrate. The issue being that file content was being output twice which is a combination of how Gomigrate reads files and that virtaulfile(s) reset their internal cursror/file position to 0 after a complete read. The correct behaviour here is return 0 bytes and EOF when a file has been completely read.

The issue is better explained in the link below but can be recreated exactly in Packr.

GeertJohan/go.rice#108

Code (largely copied from the above link)

`var DefaultBufferSize = uint(1000000)

func main() {
box := packr.Folder("./embedded-migrate/migrations")

f, err := box.Open("1_tabOne_up.sql")
if err != nil {
	panic(err)
}
defer f.Close()

b := bufio.NewReaderSize(f, int(DefaultBufferSize))
b.Peek(int(DefaultBufferSize))

bs, err := ioutil.ReadAll(b)
if err != nil {
	panic(err)
}
log.Printf("%s", bs)

}`

Which outputs the file content twice.

@stanislas-m stanislas-m added the bug Something isn't working label Dec 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant