| 295 | |
| 296 | |
| 297 | int CaseCache::lookup(LPCWSTR path, wstring& result_path, bool force_not_found) |
| 298 | { |
| 299 | |
| 300 | if (!wcscmp(path, L"\\") || !wcscmp(path, L"\\*")) { |
| 301 | result_path = path; |
| 302 | return CASE_CACHE_FOUND; |
| 303 | } |
| 304 | |
| 305 | int ret; |
| 306 | |
| 307 | wstring dir; |
| 308 | wstring file; |
| 309 | |
| 310 | if (!get_dir_and_file_from_path(path, &dir, &file)) |
| 311 | return CASE_CACHE_ERROR; |
| 312 | |
| 313 | wstring ucdir; |
| 314 | wstring ucfile; |
| 315 | |
| 316 | if (!touppercase(dir.c_str(), ucdir)) |
| 317 | return CASE_CACHE_ERROR; |
| 318 | |
| 319 | wstring file_without_stream; |
| 320 | wstring stream; |
| 321 | |
| 322 | get_file_stream(file.c_str(), &file_without_stream, &stream); |
| 323 | |
| 324 | if (!touppercase(file_without_stream.c_str(), ucfile)) |
| 325 | return CASE_CACHE_ERROR; |
| 326 | |
| 327 | lock(); |
| 328 | |
| 329 | m_lookups++; |
| 330 | |
| 331 | try { |
| 332 | |
| 333 | auto it = m_map.find(ucdir); |
| 334 | |
| 335 | if (it == m_map.end()) { |
| 336 | ret = CASE_CACHE_MISS; |
| 337 | } else { |
| 338 | |
| 339 | CaseCacheNode *node = it->second; |
| 340 | |
| 341 | if (!check_node_clean(node)) { |
| 342 | remove_node(it); |
| 343 | ret = CASE_CACHE_MISS; |
| 344 | } else { |
| 345 | |
| 346 | update_lru(node); |
| 347 | |
| 348 | auto nit = force_not_found ? node->m_files.end() : node->m_files.find(ucfile); |
| 349 | |
| 350 | bool isRoot = wcscmp(node->m_path.c_str(), L"\\") == 0; |
| 351 | |
| 352 | if (nit != node->m_files.end()) { |
| 353 | result_path = node->m_path + (isRoot ? L"" : L"\\") + nit->second + stream; |
| 354 | ret = CASE_CACHE_FOUND; |
no test coverage detected