Skip to content

Commit da7005f

Browse files
Resolve symlink recursively
1 parent c771e58 commit da7005f

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

Src/runcpp2/DependenciesHelper.cpp

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include "runcpp2/PlatformUtil.hpp"
44
#include "ssLogger/ssLog.hpp"
55

6+
#include <unordered_set>
7+
68
namespace
79
{
810
bool PopulateLocalDependencies( const std::vector<runcpp2::Data::DependencyInfo*>& dependencies,
@@ -253,6 +255,15 @@ namespace
253255

254256
return true;
255257
}
258+
259+
ghc::filesystem::path ResolveSymlink(const ghc::filesystem::path& path, std::error_code& ec)
260+
{
261+
ghc::filesystem::path resolvedPath = ghc::filesystem::canonical(path, ec);
262+
if(ec)
263+
return path; // Return original path if canonical fails
264+
265+
return resolvedPath;
266+
}
256267
}
257268

258269
bool runcpp2::GetDependenciesPaths( const std::vector<Data::DependencyInfo*>& availableDependencies,
@@ -475,6 +486,9 @@ bool runcpp2::GatherDependenciesBinaries( const std::vector<Data::DependencyIn
475486
std::vector<std::string>& outBinariesPaths)
476487
{
477488
std::vector<std::string> platformNames = GetPlatformNames();
489+
std::unordered_set<std::string> binariesPathsSet;
490+
for(int i = 0; i < outBinariesPaths.size(); ++i)
491+
binariesPathsSet.insert(outBinariesPaths[i]);
478492

479493
int minimumDependenciesCopiesCount = 0;
480494
for(int i = 0; i < availableDependencies.size(); ++i)
@@ -527,7 +541,9 @@ bool runcpp2::GatherDependenciesBinaries( const std::vector<Data::DependencyIn
527541
std::error_code e;
528542
if(ghc::filesystem::exists(srcPath, e))
529543
{
530-
outBinariesPaths.push_back(runcpp2::ProcessPath(srcPath));
544+
const std::string processedSrcPath = runcpp2::ProcessPath(srcPath);
545+
outBinariesPaths.push_back(processedSrcPath);
546+
binariesPathsSet.insert(processedSrcPath);
531547
++nonLinkFilesCount;
532548
ssLOG_INFO("Added binary path: " << srcPath.string());
533549
}
@@ -660,8 +676,25 @@ bool runcpp2::GatherDependenciesBinaries( const std::vector<Data::DependencyIn
660676
if(!extensionMatched)
661677
continue;
662678

663-
ssLOG_INFO("Linking " << it.path().string());
664-
outBinariesPaths.push_back(runcpp2::ProcessPath(it.path().string()));
679+
//Handle symlink
680+
ghc::filesystem::path finalPath = it.path();
681+
{
682+
std::error_code symlink_ec;
683+
finalPath = ResolveSymlink(finalPath, symlink_ec);
684+
if(symlink_ec)
685+
{
686+
ssLOG_ERROR("Failed to resolve symlink: " << symlink_ec.message());
687+
return false;
688+
}
689+
}
690+
691+
const std::string processedFinalPath = runcpp2::ProcessPath(finalPath.string());
692+
if(binariesPathsSet.count(processedFinalPath) == 0)
693+
{
694+
ssLOG_INFO("Linking " << finalPath.string());
695+
outBinariesPaths.push_back(processedFinalPath);
696+
binariesPathsSet.insert(processedFinalPath);
697+
}
665698
}
666699
}
667700
}

0 commit comments

Comments
 (0)