| skipped 22 lines |
23 | 23 | | |
24 | 24 | | // A function to find the closest file |
25 | 25 | | // Starting from current directory |
26 | | - | // Recusively until it finds the file or reach root directory `/` |
| 26 | + | // Recusively until it finds the file or reach root directory |
27 | 27 | | fn find_closest_files(_current_dir: &PathBuf, name: &str, stop_on_first: bool) -> Vec<PathBuf> { |
28 | 28 | | let mut closest_file: Vec<PathBuf> = Vec::new(); |
29 | | - | let stop_dir = "/".to_string(); |
30 | 29 | | let mut current_dir = _current_dir.clone(); |
31 | 30 | | |
32 | 31 | | loop { |
| skipped 4 lines |
37 | 36 | | break; |
38 | 37 | | } |
39 | 38 | | } |
40 | | - | |
41 | | - | if current_dir.to_str().unwrap() == stop_dir { |
42 | | - | break; |
| 39 | + | match current_dir.parent() { |
| 40 | + | Some(p) => current_dir = p.to_path_buf(), |
| 41 | + | None => break, |
43 | 42 | | } |
44 | | - | |
45 | | - | current_dir = current_dir.parent().unwrap().to_path_buf(); |
46 | 43 | | } |
47 | 44 | | |
48 | 45 | | closest_file |
| skipped 142 lines |