diff --git a/src/AppInstallerSharedLib/Filesystem.cpp b/src/AppInstallerSharedLib/Filesystem.cpp index 2e0e283359..08b6f21315 100644 --- a/src/AppInstallerSharedLib/Filesystem.cpp +++ b/src/AppInstallerSharedLib/Filesystem.cpp @@ -465,7 +465,17 @@ namespace AppInstaller::Filesystem { if (error.code().value() == ERROR_PRIVILEGE_NOT_HELD) { - return false; + // If symlink creation fails due to insufficient privileges, + // fall back to creating a hard link instead. + try + { + std::filesystem::create_hard_link(target, link); + return true; + } + catch (...) + { + return false; + } } else { diff --git a/src/AppInstallerSharedLib/Public/winget/Filesystem.h b/src/AppInstallerSharedLib/Public/winget/Filesystem.h index 1a7df6aa28..ba4b5cf7bc 100644 --- a/src/AppInstallerSharedLib/Public/winget/Filesystem.h +++ b/src/AppInstallerSharedLib/Public/winget/Filesystem.h @@ -38,7 +38,6 @@ namespace AppInstaller::Filesystem // Checks if the path is a symlink and exists. bool SymlinkExists(const std::filesystem::path& symlinkPath); - bool CreateSymlink(const std::filesystem::path& path, const std::filesystem::path& target); // Get expanded file system path. std::filesystem::path GetExpandedPath(const std::string& path);