Ensure that native path separators are always used in symlink targets on Windows

This commit is contained in:
Kamil Śliwak 2021-07-28 02:36:30 +02:00
parent a67828b9ba
commit 226f040e25
3 changed files with 6 additions and 7 deletions

View File

@ -53,13 +53,17 @@ void solidity::test::createFileWithContent(boost::filesystem::path const& _path,
} }
bool solidity::test::createSymlinkIfSupportedByFilesystem( bool solidity::test::createSymlinkIfSupportedByFilesystem(
boost::filesystem::path const& _targetPath, boost::filesystem::path _targetPath,
boost::filesystem::path const& _linkName, boost::filesystem::path const& _linkName,
bool _directorySymlink bool _directorySymlink
) )
{ {
boost::system::error_code symlinkCreationError; boost::system::error_code symlinkCreationError;
// NOTE: On Windows / works as a separator in a symlink target only if the target is absolute.
// Convert path separators to native ones to avoid this problem.
_targetPath.make_preferred();
if (_directorySymlink) if (_directorySymlink)
boost::filesystem::create_directory_symlink(_targetPath, _linkName, symlinkCreationError); boost::filesystem::create_directory_symlink(_targetPath, _linkName, symlinkCreationError);
else else

View File

@ -46,7 +46,7 @@ void createFileWithContent(boost::filesystem::path const& _path, std::string con
/// support symlinks. /// support symlinks.
/// Throws an exception of the operation fails for a different reason. /// Throws an exception of the operation fails for a different reason.
bool createSymlinkIfSupportedByFilesystem( bool createSymlinkIfSupportedByFilesystem(
boost::filesystem::path const& _targetPath, boost::filesystem::path _targetPath,
boost::filesystem::path const& _linkName, boost::filesystem::path const& _linkName,
bool _directorySymlink bool _directorySymlink
); );

View File

@ -786,12 +786,7 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_symlinks)
TemporaryWorkingDirectory tempWorkDir(tempDir.path() / "r"); TemporaryWorkingDirectory tempWorkDir(tempDir.path() / "r");
if ( if (
#if !defined(_WIN32)
!createSymlinkIfSupportedByFilesystem("../x/y", tempDir.path() / "r/sym", true) || !createSymlinkIfSupportedByFilesystem("../x/y", tempDir.path() / "r/sym", true) ||
#else
// NOTE: On Windows / works as a separator in a symlink target only if the target is absolute
!createSymlinkIfSupportedByFilesystem("..\\x\\y", tempDir.path() / "r/sym", true) ||
#endif
!createSymlinkIfSupportedByFilesystem("contract.sol", tempDir.path() / "x/y/z/contract_symlink.sol", false) !createSymlinkIfSupportedByFilesystem("contract.sol", tempDir.path() / "x/y/z/contract_symlink.sol", false)
) )
return; return;