-
-
Notifications
You must be signed in to change notification settings - Fork 685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
internal/file: VirtualFS
's Open
should always a new entry for "."
#3081
Comments
Unfortunately I cannot change this for backward compatibility. I might revisit this for v3 later. |
Hmm, on second thought, this sounds a bug. Which platform did you try this? |
Apparently everyplatform has this issue, right? I'll take a look. Thanks, |
virtualFSRoot
and dir
don't implement fs.ReadDirFile
correctly
https://pkg.go.dev/io/fs#ReadDirFile type ReadDirFile interface {
File
// ReadDir reads the contents of the directory and returns
// a slice of up to n DirEntry values in directory order.
// Subsequent calls on the same file will yield further DirEntry values.
//
// If n > 0, ReadDir returns at most n DirEntry structures.
// In this case, if ReadDir returns an empty slice, it will return
// a non-nil error explaining why.
// At the end of a directory, the error is io.EOF.
// (ReadDir must return io.EOF itself, not an error wrapping io.EOF.)
//
// If n <= 0, ReadDir returns all the DirEntry values from the directory
// in a single slice. In this case, if ReadDir succeeds (reads all the way
// to the end of the directory), it returns the slice and a nil error.
// If it encounters an error before the end of the directory,
// ReadDir returns the DirEntry list read until that point and a non-nil error.
ReadDir(n int) ([]DirEntry, error)
} So, if n <= 0, all the entries must be returned whatever the internal offset is. |
I tested on linux and in the browser, so that covers the two possible implementations in ebiten. I agree with your interpretation of ReadDir when n <= 0. I'm not quite sure what the designers of fs intended if the user did this
|
https://go.dev/play/p/PqKzzuemepx Interestingly, |
I reported this. golang/go#69301 IIUC, either the implementation or the documentation is wrong. |
Also the golang File.readdir implementation specifically mentions this behavior, but that means some other code in their implementation fails to account for it. https://cs.opensource.google/go/go/+/refs/tags/go1.23.0:src/os/dir_unix.go;l=103
I interpret this to mean 'if the public interface ReadDir(n) is passed an n value <= 0 then the public method shall return all entries in a single slice, but the low level implementation of File.readdir is under no such constraint to treat n that way.' |
So this can be interpreted as 1) all the entries from the first whatever the offset is, or 2) all the remaining entries after the offset. Thought the actual |
Back to the original issue, this should always returns the number of files. This is a bug in Ebitengine diff --git a/examples/dropfile/main.go b/examples/dropfile/main.go
index f78c27dab..cce148047 100644
--- a/examples/dropfile/main.go
+++ b/examples/dropfile/main.go
@@ -79,6 +79,14 @@ func (g *Game) Update() error {
}
g.m.Unlock()
}
+
+ for i := 0; i < 3; i++ {
+ ents, err := fs.ReadDir(files, ".")
+ if err != nil {
+ panic(err)
+ }
+ println(len(ents)) // This should always returns the number of dropped files, not 0
+ }
}()
}
return nil |
virtualFSRoot
and dir
don't implement fs.ReadDirFile
correctlyVirtualFS
's Open should always a new entry for "."
VirtualFS
's Open should always a new entry for "."VirtualFS
's Open
should always a new entry for "."
Doesn't file_js.go need a similar fix? |
No. This should already work. |
Operating System
What feature would you like to be added?
fs.ReadDir(ebiten.DroppedFiles)
returns a slice of all the files that have been dropped so far, but calling fs.ReadDir() again (within the same update tick) returns an empty slice.Why is this needed?
It is useful to be able to get back the list of files in the DroppedFiles filesystem without having to cache the results manually.
fs.ReadDir()
passes -1 for the count toroot.ReadDir(int)
. Both file_js.go and file_notjs.go keep track of the number of files that ReadDir() has returned in theoffset
field. Ifcount
< 0 then the offset could remain the same.file_notjs.go
And a similar change in file_js.go
The text was updated successfully, but these errors were encountered: