Because the exact ordering of the comparison in lfs_bd_cmp is a bit ambiguous, lfs_dir_find_match returned the wrong result when filenames were equal, and only differed in length.
For example:
cmp("a", "aa") should be LFS_CMP_LT
cmp("aaa", "aa") should be LFS_CMP_GT
We're quite lucky that none of the littlefs internals currently depend on the sorted order, otherwise we'd probably be stuck with this weird ordering for backwards compatibility reasons...
Fixed, and added some test cases over directory ordering to prevent regression in the future.
Wild this hasn't been caught until now.
Because the exact ordering of the comparison in lfs_bd_cmp is a bit ambiguous, lfs_dir_find_match returned the wrong result when filenames were equal, and only differed in length.
For example:
cmp("a", "aa")
should be LFS_CMP_LTcmp("aaa", "aa")
should be LFS_CMP_GTWe're quite lucky that none of the littlefs internals currently depend on the sorted order, otherwise we'd probably be stuck with this weird ordering for backwards compatibility reasons...
Fixed, and added some test cases over directory ordering to prevent regression in the future.
Found by @andriyndev Related issue https://github.com/littlefs-project/littlefs/issues/923