MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / InitController

Method InitController

view/sharedcache/core/SharedCacheView.cpp:803–962  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

801}
802
803bool SharedCacheView::InitController()
804{
805 auto primaryFilePath = GetPrimaryFilePath();
806 if (!primaryFilePath.has_value())
807 {
808 m_logger->LogError("Failed to get primary file path!");
809 return false;
810 }
811 std::string primaryFileDir = std::filesystem::path(*primaryFilePath).parent_path().string();
812
813 // Get the primary project file from the current files project.
814 // This is required to allow selecting a primary file in a different directory. Otherwise, we search the current database directory.
815 Ref<ProjectFile> primaryProjectFile = nullptr;
816 auto currentProjectFile = GetFile()->GetProjectFile();
817 if (currentProjectFile)
818 primaryProjectFile = currentProjectFile->GetProject()->GetFileByPathOnDisk(*primaryFilePath);
819
820 if (!IsSameFolderForFile(primaryProjectFile, currentProjectFile))
821 {
822 // TODO: Remove this restriction using stored cache UUID's and a fast project file search.
823 m_logger->LogWarn("Because the primary file is in a different project folder you will need to select it on every open, consider moving the database file into the same folder.");
824 }
825
826 // OK, we have the primary shared cache file, now let's add the entries.
827 auto sharedCacheBuilder = SharedCacheBuilder(this);
828 sharedCacheBuilder.SetPrimaryFileName(m_primaryFileName);
829
830 // Add the primary file. If we fail log alert that the primary cache file is invalid.
831 // We process the primary cache entry first as it might be consulted in the processing of later entries.
832 if (!sharedCacheBuilder.AddFile(*primaryFilePath, m_primaryFileName, CacheEntryType::Primary))
833 {
834 m_logger->LogAlertF("Failed to add primary cache file: '{}'", m_primaryFileName);
835 return false;
836 }
837
838 {
839 // After this we should have all the mappings available as well.
840 auto startTime = std::chrono::high_resolution_clock::now();
841 sharedCacheBuilder.AddDirectory(primaryFileDir);
842 if (primaryProjectFile)
843 sharedCacheBuilder.AddProjectFolder(primaryProjectFile->GetFolder());
844 auto totalEntries = sharedCacheBuilder.GetCache().GetEntries().size();
845 auto endTime = std::chrono::high_resolution_clock::now();
846 std::chrono::duration<double> elapsed = endTime - startTime;
847 m_logger->LogInfo("Processing %zu entries took %.3f seconds", totalEntries, elapsed.count());
848
849 // If we can't store all of our files for this cache in the accessor cache we might run into issues, warn the user.
850 if (totalEntries > FileAccessorCache::Global().GetCacheSize())
851 m_logger->LogWarn("Cache contains more entries than the allowed number of opened file handles, this may impact reliability.");
852
853 // Verify that we are not missing any entries that were stored in the metadata.
854 // If we are that means we should alert the user that a previously associated cache entry is missing.
855 std::set<std::string> missingCacheEntries = m_secondaryFileNames;
856 uint64_t expectedFileCount = 1;
857 for (const auto& entry : sharedCacheBuilder.GetCache().GetEntries())
858 {
859 missingCacheEntries.erase(entry.GetFileName());
860 LogSecondaryFileName(entry.GetFileName());

Callers

nothing calls this directly

Calls 15

IsSameFolderForFileFunction · 0.85
SharedCacheBuilderClass · 0.85
LogErrorMethod · 0.80
GetProjectFileMethod · 0.80
GetFileByPathOnDiskMethod · 0.80
LogWarnMethod · 0.80
AddFileMethod · 0.80
LogAlertFMethod · 0.80
AddDirectoryMethod · 0.80
AddProjectFolderMethod · 0.80
GetEntriesMethod · 0.80
LogInfoMethod · 0.80

Tested by

no test coverage detected