Fix Readdir() and Name()#59
Conversation
Statik's Readdir did not behave in the same way as a http.FileSystem's Readdir. Similarly, the Name function in http.FileSystem returned the base name, and not a full file path. This commit fixes both issues, making both Name and Readdir behave in the same way as in http.Dir()
|
Not sure why travis succeeded on one test, yet failed on another. The failure happens in Open, which works identically in this version (the file map keys were not changed). This is some form of timing issue, which I am able to intermittently repeat by running the tests many times. I will try to see why it is happening later today. |
Folders were created in a for loop iterating over map keys. This led to an instability in newer golang versions, since adding to a map while looping over it can either produce the key again or not produce it. In order to successfully generate a folder structure, it was implicitly assumed that each folder has a file, which would not require recursing from a file down to its ancestor folders. When running without such a requirement, the elements added in the loop sometimes recursed, if their key was produced again in the loop, and sometimes did not. This caused an intermittent issue with tests sometimes failing to find a folder.
|
It turned out the issue was that folders were added in a for loop over map keys, and sometimes recursed into their ancestors (if the added key was produced again in the loop) and sometimes did not (if it wasn't). This issue was initially hidden from tests because each folder had at least one file in it, meaning that recursive creation of parents was not necessary. The tests I added for Readdir had this structure, which exposed this secondary bug. The above commit fixes it, meaning that this PR fixes 3 issues:
|
|
Fixed in #61 |
Statik's
Readdirdid not behave in the same way as ahttp.FileSystem's Readdir. Similarly, theNamefunction inhttp.FileSystemreturned the base name, and not a full file path.This commit fixes both issues, making both
NameandReaddirbehave in the same way as when running the raw filesystem directly usinghttp.Dir()The commit is an extension of #55, which was a first step towards replicating the correct behaviour, but failed to account for the
Name()issue, and did not include the necessary extraTrimto get rid of leading slash.The corresponding tests ensure that the results are identical for
http.Dir()and statik.Closes #58