Functions | |
| pub fn | find_file (name:impl AsRef< Path >) -> Option< PathBuf > |
Find name by walking up from the current working directory. | |
| pub fn | find_file_from (name:impl AsRef< Path >, start:&Path) -> Option< PathBuf > |
Find name by walking up from start instead of the current working directory. | |
| fn | find_named_within (dir:&Path, name:&Path, depth:usize, budget:&mut usize) -> Option< PathBuf > |
Look for the bare filename name in dir and in its subdirectories down to depth further levels. | |
| fn | absolutize (path:&Path) -> PathBuf |
Turn a path into an absolute one without requiring it to exist (it always does at the call sites), preferring canonicalize and falling back to the current directory join when canonicalisation is unavailable. | |
| fn | finds_relative_path_in_ancestor () |
| fn | finds_bare_filename_in_subdirectory_of_ancestor () |
| fn | returns_none_when_absent () |
| fn | descent_does_not_exceed_configured_depth () |
| fn | prefers_direct_hit_over_subdirectory () |
Variables | |
| pub const | MAX_PARENT_LEVELS |
| How many parent directories to climb before giving up. | |
| pub const | MAX_DESCENT_DEPTH |
How many subdirectory levels below each ancestor are scanned when name is a bare filename rather than a relative path. | |
| pub const | MAX_DIRECTORIES_SCANNED |
The total number of directories a single [find_file_from] search will read before giving up. | |
| mod | tests |
Function Documentation
◆ absolutize()
| fn absolutize | ( | path:& | Path | ) | -> PathBuf |
Turn a path into an absolute one without requiring it to exist (it always does at the call sites), preferring canonicalize and falling back to the current directory join when canonicalisation is unavailable.
◆ descent_does_not_exceed_configured_depth()
| fn descent_does_not_exceed_configured_depth | ( | ) |
◆ find_file()
| pub fn find_file | ( | name:impl AsRef< Path > | ) | -> Option< PathBuf > |
Find name by walking up from the current working directory.
name may be either a bare filename (for example "51Degrees-LiteV4.1.hash") or a relative path (for example "cxx/data/device-detection/51Degrees-LiteV4.1.hash").
Starting at the current working directory and climbing through up to [MAX_PARENT_LEVELS] ancestors, each ancestor is checked for name:
- If
namecontains a path separator it is treated as a relative path and joined directly onto the ancestor, so a known layout resolves in oneexistscheck per ancestor. - If
nameis a bare filename it is looked for directly in the ancestor and then in subdirectories up to [MAX_DESCENT_DEPTH] deep.
Returns the first match as an absolute path, or None if the file is not found within the bounded search. The walk climbs to the parent when the current directory does not contain the file, using a bounded climb and a shallow descent so the search is deterministic.
◆ find_file_from()
| pub fn find_file_from | ( | name:impl AsRef< Path > | , |
| start:& | Path ) -> Option< PathBuf > |
◆ find_named_within()
Look for the bare filename name in dir and in its subdirectories down to depth further levels.
Returns the first match as an absolute path.
budget is decremented for each directory whose listing is read and the scan stops once it reaches zero, so a single search reads at most [MAX_DIRECTORIES_SCANNED] directories no matter how the tree is shaped.
◆ finds_bare_filename_in_subdirectory_of_ancestor()
| fn finds_bare_filename_in_subdirectory_of_ancestor | ( | ) |
◆ finds_relative_path_in_ancestor()
| fn finds_relative_path_in_ancestor | ( | ) |
◆ prefers_direct_hit_over_subdirectory()
| fn prefers_direct_hit_over_subdirectory | ( | ) |
◆ returns_none_when_absent()
| fn returns_none_when_absent | ( | ) |
Variable Documentation
◆ MAX_DESCENT_DEPTH
| pub const MAX_DESCENT_DEPTH |
How many subdirectory levels below each ancestor are scanned when name is a bare filename rather than a relative path.
The example data files sit up to three directories below a common ancestor (for example cxx/data/device-detection/<file>), so a shallow scan finds them without the cost of a full recursive descent of large sibling repositories.
◆ MAX_DIRECTORIES_SCANNED
| pub const MAX_DIRECTORIES_SCANNED |
The total number of directories a single [find_file_from] search will read before giving up.
This bounds the cost of the bare-filename subdirectory scan so the search can never hang on a pathologically large tree (for example when an ancestor is a drive root). It makes the search deterministic. A relative-path search is unaffected because it never reads a directory listing.
◆ MAX_PARENT_LEVELS
| pub const MAX_PARENT_LEVELS |
How many parent directories to climb before giving up.
This bounds the search so a missing file fails quickly rather than walking to the filesystem root. Twenty levels comfortably covers any realistic checkout depth, including a CI agent's nested workspace path.
◆ tests
| mod tests |
