(
path: &FsPath,
root: &FsPath,
query: &str,
results: &mut Vec<String>,
limit: usize,
)
| 3136 | let limit = query.limit.unwrap_or(100); |
| 3137 | |
| 3138 | fn find_recursive( |
| 3139 | path: &FsPath, |
| 3140 | root: &FsPath, |
| 3141 | query: &str, |
| 3142 | results: &mut Vec<String>, |
| 3143 | limit: usize, |
| 3144 | ) { |
| 3145 | if results.len() >= limit { |
| 3146 | return; |
| 3147 | } |
| 3148 | if path.is_dir() { |
| 3149 | if let Ok(entries) = std::fs::read_dir(path) { |
| 3150 | for entry in entries.flatten() { |
| 3151 | let path_buf = entry.path(); |
| 3152 | if !is_within_root(&path_buf, root) { |
| 3153 | continue; |
| 3154 | } |
| 3155 | let name = entry.file_name().to_string_lossy().to_string(); |
| 3156 | if name.contains(query) { |
| 3157 | results.push(path_buf.to_string_lossy().to_string()); |
| 3158 | } |
| 3159 | if path_buf.is_dir() && results.len() < limit { |
| 3160 | find_recursive(&path_buf, root, query, results, limit); |
| 3161 | } |
| 3162 | } |
| 3163 | } |
| 3164 | } |
| 3165 | } |
| 3166 | |
| 3167 | find_recursive(&base_path, &base_path, &query.query, &mut results, limit); |
| 3168 | Ok(Json(results)) |
no test coverage detected