|
3 | 3 | #include "runcpp2/PlatformUtil.hpp" |
4 | 4 | #include "ssLogger/ssLog.hpp" |
5 | 5 |
|
| 6 | +#include <unordered_set> |
| 7 | + |
6 | 8 | namespace |
7 | 9 | { |
8 | 10 | bool PopulateLocalDependencies( const std::vector<runcpp2::Data::DependencyInfo*>& dependencies, |
@@ -253,6 +255,15 @@ namespace |
253 | 255 |
|
254 | 256 | return true; |
255 | 257 | } |
| 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 | + } |
256 | 267 | } |
257 | 268 |
|
258 | 269 | bool runcpp2::GetDependenciesPaths( const std::vector<Data::DependencyInfo*>& availableDependencies, |
@@ -475,6 +486,9 @@ bool runcpp2::GatherDependenciesBinaries( const std::vector<Data::DependencyIn |
475 | 486 | std::vector<std::string>& outBinariesPaths) |
476 | 487 | { |
477 | 488 | 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]); |
478 | 492 |
|
479 | 493 | int minimumDependenciesCopiesCount = 0; |
480 | 494 | for(int i = 0; i < availableDependencies.size(); ++i) |
@@ -527,7 +541,9 @@ bool runcpp2::GatherDependenciesBinaries( const std::vector<Data::DependencyIn |
527 | 541 | std::error_code e; |
528 | 542 | if(ghc::filesystem::exists(srcPath, e)) |
529 | 543 | { |
530 | | - outBinariesPaths.push_back(runcpp2::ProcessPath(srcPath)); |
| 544 | + const std::string processedSrcPath = runcpp2::ProcessPath(srcPath); |
| 545 | + outBinariesPaths.push_back(processedSrcPath); |
| 546 | + binariesPathsSet.insert(processedSrcPath); |
531 | 547 | ++nonLinkFilesCount; |
532 | 548 | ssLOG_INFO("Added binary path: " << srcPath.string()); |
533 | 549 | } |
@@ -660,8 +676,25 @@ bool runcpp2::GatherDependenciesBinaries( const std::vector<Data::DependencyIn |
660 | 676 | if(!extensionMatched) |
661 | 677 | continue; |
662 | 678 |
|
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 | + } |
665 | 698 | } |
666 | 699 | } |
667 | 700 | } |
|
0 commit comments