| 636 | |
| 637 | |
| 638 | void CAICHHashSet::LoadRootHashCacheLocked() |
| 639 | { |
| 640 | // Walk known2.met once, collecting every root hash. Replaces the |
| 641 | // per-call in-file linear scan that turned bulk-hashing N files into |
| 642 | // O(N^2) on-disk work (issue #579). |
| 643 | s_rootHashCache.clear(); |
| 644 | s_rootHashCacheLoaded = true; // marked early so a partial read still ends the loop |
| 645 | |
| 646 | const wxString fullpath = thePrefs::GetConfigDir() + KNOWN2_MET_FILENAME; |
| 647 | if (!wxFile::Exists(fullpath)) { |
| 648 | return; |
| 649 | } |
| 650 | |
| 651 | CFile file(fullpath, CFile::read); |
| 652 | if (!file.IsOpened()) { |
| 653 | // Couldn't open: don't claim the cache is valid; SaveHashSet |
| 654 | // will retry on the next invocation. |
| 655 | s_rootHashCacheLoaded = false; |
| 656 | return; |
| 657 | } |
| 658 | |
| 659 | try { |
| 660 | const uint64 nFileSize = file.GetLength(); |
| 661 | if (nFileSize == 0) { |
| 662 | return; |
| 663 | } |
| 664 | const uint8 header = file.ReadUInt8(); |
| 665 | if (header != KNOWN2_MET_VERSION) { |
| 666 | AddDebugLogLineC(logSHAHashSet, |
| 667 | "AICH cache load: unexpected known2.met version, leaving cache empty"); |
| 668 | return; |
| 669 | } |
| 670 | while (file.GetPosition() < nFileSize) { |
| 671 | CAICHHash rootHash; |
| 672 | rootHash.Read(&file); |
| 673 | const uint32 nHashCount = file.ReadUInt32(); |
| 674 | const uint64 skipBytes = |
| 675 | static_cast<uint64>(nHashCount) * HASHSIZE; |
| 676 | if (file.GetPosition() + skipBytes > nFileSize) { |
| 677 | // known2.met is truncated past this entry; stop here. |
| 678 | // CAICHSyncTask will handle the actual truncation/recovery. |
| 679 | AddDebugLogLineC(logSHAHashSet, |
| 680 | "AICH cache load: known2.met truncated mid-entry"); |
| 681 | break; |
| 682 | } |
| 683 | file.Seek(static_cast<wxFileOffset>(skipBytes), wxFromCurrent); |
| 684 | s_rootHashCache.insert(rootHash); |
| 685 | } |
| 686 | } catch (const CSafeIOException& e) { |
| 687 | AddDebugLogLineC(logSHAHashSet, |
| 688 | "IO error walking known2.met for AICH cache: " + e.what()); |
| 689 | // Keep whatever we collected; stay marked loaded so we don't |
| 690 | // re-scan on every SaveHashSet call (and risk the same error). |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | |
| 695 | bool CAICHHashSet::SaveHashSet() |
nothing calls this directly
no test coverage detected