mirror of
https://github.com/versity/versitygw.git
synced 2026-01-05 11:24:52 +00:00
The original Walk function used the native WalkDir and ReadDir which did not guarantee lexicographic ordering of results for cases where including directory slash changes the sort order. This caused incorrect paginated responses because S3 APIs require strict lexicographic ordering where directories with trailing slashes sort correctly relative to files. For example, dir1/a.b/ must come before dir1/a/ in the results, but fs.WalkDir was returning them in filesystem sort order which reversed the order due to not taking in account the trailing "/". This also lead to cases of continuous looping of paginated listobjects results when the marker was set out of order from the expected results. To address this fundamental ordering issue, the entire directory traversal mechanism was replaced with a custom lexicographic sorting approach. The new implementation reads each directory's contents using ReadDir, then sorts the entries using custom sort keys that append trailing slashes to directory paths. This ensures that dir1/a.b/ correctly sorts before dir1/a/, as well as other similar failing cases, according to ASCII character ordering rules. Fixes #1283