Hi, On Mon, Sep 07, 2009 at 11:24:48PM +0300, Sergiu Ivanov wrote: > unionfs needs to explicitly enumerate the contents of a directory to > do pattern matching in it. I cannot envision a way to do > multi-component pattern matching without iterating all subdirectories > of stow/ . Well, okay, there could be done some optimization (like > counting the number of components in the pattern and not going deeper > than that), but it does not change the concept considerably.
> BTW, the implied asterisk in the original implementation is achieved > by explicitly going down to the second level under stow/ , i.e. it is > hard-coded in the algorithm, not some patterns, filenames or anything > else. Since this implementation didn't care about multi-component > pattern, I chose not to think of them either. > > Do you have some general idea of how multi-component pattern matching > could be implemented more efficiently than that? Some vague pointer > should suffice for me to adapt the idea to unionfs. How about matching one component at a time? For instance, given `*/*/*' you iterate through all files in the current directory and find matches to `*/' (the slash filters out non-directories). For each match you recurse, making the match the current directory and with the pattern with the tested component removed, e.g. `*/*'. The recursion continues until the pattern is static or there are no matches. (Clarification: by current directory I don't mean the process' CWD, just the directory currently being iterated.) Regards, Fredrik