Skip to content

Commit 226f040

Browse files
committed
Ensure that native path separators are always used in symlink targets on Windows
1 parent a67828b commit 226f040

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

test/FilesystemUtils.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,17 @@ void solidity::test::createFileWithContent(boost::filesystem::path const& _path,
5353
}
5454

5555
bool solidity::test::createSymlinkIfSupportedByFilesystem(
56-
boost::filesystem::path const& _targetPath,
56+
boost::filesystem::path _targetPath,
5757
boost::filesystem::path const& _linkName,
5858
bool _directorySymlink
5959
)
6060
{
6161
boost::system::error_code symlinkCreationError;
6262

63+
// NOTE: On Windows / works as a separator in a symlink target only if the target is absolute.
64+
// Convert path separators to native ones to avoid this problem.
65+
_targetPath.make_preferred();
66+
6367
if (_directorySymlink)
6468
boost::filesystem::create_directory_symlink(_targetPath, _linkName, symlinkCreationError);
6569
else

test/FilesystemUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void createFileWithContent(boost::filesystem::path const& _path, std::string con
4646
/// support symlinks.
4747
/// Throws an exception of the operation fails for a different reason.
4848
bool createSymlinkIfSupportedByFilesystem(
49-
boost::filesystem::path const& _targetPath,
49+
boost::filesystem::path _targetPath,
5050
boost::filesystem::path const& _linkName,
5151
bool _directorySymlink
5252
);

test/solc/CommandLineInterface.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -786,12 +786,7 @@ BOOST_AUTO_TEST_CASE(cli_paths_to_source_unit_names_symlinks)
786786
TemporaryWorkingDirectory tempWorkDir(tempDir.path() / "r");
787787

788788
if (
789-
#if !defined(_WIN32)
790789
!createSymlinkIfSupportedByFilesystem("../x/y", tempDir.path() / "r/sym", true) ||
791-
#else
792-
// NOTE: On Windows / works as a separator in a symlink target only if the target is absolute
793-
!createSymlinkIfSupportedByFilesystem("..\\x\\y", tempDir.path() / "r/sym", true) ||
794-
#endif
795790
!createSymlinkIfSupportedByFilesystem("contract.sol", tempDir.path() / "x/y/z/contract_symlink.sol", false)
796791
)
797792
return;

0 commit comments

Comments
 (0)