Skip to content

Commit ecdb87a

Browse files
committed
[SharedCache] Allow project databases to be stored in a separate folder
However the primary file will need to be selected each time you open, for that to be resolved we need to use project file UUID's or the cache entry UUID's themselves to traverse all project files
1 parent 09a617a commit ecdb87a

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

view/sharedcache/core/SharedCacheView.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,19 @@ bool SharedCacheView::InitController()
811811
}
812812
std::string primaryFileDir = std::filesystem::path(*primaryFilePath).parent_path().string();
813813

814+
// Get the primary project file from the current files project.
815+
// This is required to allow selecting a primary file in a different directory. Otherwise, we search the current database directory.
816+
Ref<ProjectFile> primaryProjectFile = nullptr;
817+
auto currentProjectFile = GetFile()->GetProjectFile();
818+
if (currentProjectFile)
819+
primaryProjectFile = currentProjectFile->GetProject()->GetFileByPathOnDisk(*primaryFilePath);
820+
821+
if (!IsSameFolderForFile(primaryProjectFile, currentProjectFile))
822+
{
823+
// TODO: Remove this restriction using stored cache UUID's and a fast project file search.
824+
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.");
825+
}
826+
814827
// OK, we have the primary shared cache file, now let's add the entries.
815828
auto sharedCacheBuilder = SharedCacheBuilder(this);
816829
sharedCacheBuilder.SetPrimaryFileName(m_primaryFileName);
@@ -827,8 +840,8 @@ bool SharedCacheView::InitController()
827840
// After this we should have all the mappings available as well.
828841
auto startTime = std::chrono::high_resolution_clock::now();
829842
sharedCacheBuilder.AddDirectory(primaryFileDir);
830-
if (auto projectFile = GetFile()->GetProjectFile())
831-
sharedCacheBuilder.AddProjectFolder(projectFile->GetFolder());
843+
if (primaryProjectFile)
844+
sharedCacheBuilder.AddProjectFolder(primaryProjectFile->GetFolder());
832845
auto totalEntries = sharedCacheBuilder.GetCache().GetEntries().size();
833846
auto endTime = std::chrono::high_resolution_clock::now();
834847
std::chrono::duration<double> elapsed = endTime - startTime;

view/sharedcache/core/Utility.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,15 @@ std::string BaseFileName(const std::string& path)
137137
return path;
138138
}
139139

140+
bool IsSameFolderForFile(Ref<ProjectFile> a, Ref<ProjectFile> b)
141+
{
142+
if (!a && !b)
143+
return true;
144+
if (a && b)
145+
return IsSameFolder(a->GetFolder(), b->GetFolder());
146+
return false;
147+
}
148+
140149
bool IsSameFolder(Ref<ProjectFolder> a, Ref<ProjectFolder> b)
141150
{
142151
if (!a && !b)

view/sharedcache/core/Utility.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ void ApplySymbol(BinaryNinja::Ref<BinaryNinja::BinaryView> view, BinaryNinja::Re
4040
// /blah/foo/bar/libObjCThing.dylib -> libObjCThing.dylib
4141
std::string BaseFileName(const std::string& path);
4242

43+
bool IsSameFolderForFile(BinaryNinja::Ref<BinaryNinja::ProjectFile> a, BinaryNinja::Ref<BinaryNinja::ProjectFile> b);
4344
bool IsSameFolder(BinaryNinja::Ref<BinaryNinja::ProjectFolder> a, BinaryNinja::Ref<BinaryNinja::ProjectFolder> b);
4445

4546
// Represents a range of addresses [start, end).

0 commit comments

Comments
 (0)