-
Notifications
You must be signed in to change notification settings - Fork 49
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
Why does readdir not return an alphabetized list? #37
Comments
Caused by isomorphic-git/lightning-fs#37 Also, extensively test using LightningFS in Node as well as native fs module. This has made the test quite unbearably complicated.
Hmm. No I guess it returns them in the order they were added. Directories are stored as Line 163 in d3f78e8
My experience has been that Node's A quick googling shows some examples of the craziness in Node / libuv:
So the short answer is: it doesn't return a sorted list because isomorphic-git always sorts the results of readdir so I never noticed or thought about it. In a kind of sick twist then, if we add sorting to LightningFS, that means every readdir list will end up being sorted twice, and that could actually make performance worse, so I kinda hate to do that. :-( That sucks. I'll make a note in the README, because that's a definite "gotcha". |
Makes sense, thank you! |
I ran into unexpected behavior in an app because LightningFS'
readdir
can return non-sorted strings. The following example shows the issue in Node.js (make sure younpm install --save-dev fake-indexeddb
first), but the issue was first identified in the browser (Firefox and Safari):The script above writes to a set of fifteen files (whose names are between '0' and '14') in random order, and then prints the output of
readdir
. Running this script several times shows the issue: an unsorted list of files:This behavior persists whether I use numeric or alphanumeric filenames.
In contrast, if I use Node's
fs
module,readdir
returns sorted strings.Is this an IndexedDB limitation? If it is, a
sort
on eachreaddir
may be too expensive. But if not, maybe there's a workaround in the library itself?Loving the LightningFS + isomorphic-git lifestyle, thank you for your continued hard work on these projects!
The text was updated successfully, but these errors were encountered: