afero
afero copied to clipboard
Glob should check pattern is well formed before doing anything else. TestGlobError is broken.
In the current implementation of Glob in afero, if the pattern is ill formed, it does not necessary fails. Glob will return an empty list and nil err, if the pattern identifies a directory that does not exists or if the directory is empty. That is because we suppress all system errors and if the directory is empty we do not ever get to use filepath.Match.
For instance, Glob(fs, "a/b[") should return an error no matter what, but in the current implementation it only returns an error if the identified directory is not empty. This is very inconsistent and confusing.
In contrast, filepath.Glob would return an error because the first thing it does is check the pattern is valid.
The existing test is also broken.