It would be nifty if we had a function that could find a file UP from a given point in a directory structure.
e.g. search_up( $(this.promise_dirname), ".git/config", inf );
- User must provide a path to start searching from. This directory itself should be searched.
- User must provide a path to search for (this path is relative to the currently searched directory
- User can provide the number of levels to search, if not provided, it should search to the root of the file system (real inf, not CFEngine inf of 999999999).
- When number of levels up to search is 0, the search is limited to the first directory.
One place this would be immediately useful for me is for acceptance tests in core. Most acceptance tests include dcs.cf.sub via a relative path up from the current location. It's really annoying to get that path correct, it would be much easier to search_up( $(this.promise_dirname), "dcs.cf.sub", inf );
I propose search_up because that is the hip way to refer to searching (based on my anecdotal evidence observing my own children 9 and 11 years old).
search_up() searches up the directory tree structure for a file, .e.g. search_up("/tmp/deep/dir", ".git/config", inf) would search up the directory tree as many as inf levels (999999999) starting at /tmp/deep/dir, then /tmp/deep, then /tmp/ looking for .git/config. It should not be possible for the array to have more than the number of levels UP to search elements, nor should it be possible to have more than the number of parent directories until you reach the root of the file system. In this example case, no more than 999999999 elements in the array would be possible, though we hit the limit of the file system after searching 3 paths. The function should search across file system boundaries.
Should search_up() return a data container, string, or list?
- A string is very limited, getting us just one result, a list or a data container provide a bit more flexibility.
- Data container has the benefit of being able to reference a position directly, e.g. $(dc) for the first result where as a specific list element would need to be accessed with nth() list
- A data container array and a list can both be iterated directly
Given these considerations, a data container array seems to be the best choice.