Skip to content

Commit 618ba2f

Browse files
committed
createSymlinkIfSupportedByFilesystem(): Add support for directory symlinks used on Windows
1 parent 1f95348 commit 618ba2f

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

test/FilesystemUtils.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void solidity::test::createFilesWithParentDirs(set<boost::filesystem::path> cons
3939
}
4040
}
4141

42-
void solidity::test::createFileWithContent(boost::filesystem::path const& _path, string const& content)
42+
void solidity::test::createFileWithContent(boost::filesystem::path const& _path, string const& _content)
4343
{
4444
if (boost::filesystem::is_regular_file(_path))
4545
BOOST_THROW_EXCEPTION(runtime_error("File already exists: \"" + _path.string() + "\".")); \
@@ -49,16 +49,21 @@ void solidity::test::createFileWithContent(boost::filesystem::path const& _path,
4949
if (newFile.fail() || !boost::filesystem::is_regular_file(_path))
5050
BOOST_THROW_EXCEPTION(runtime_error("Failed to create a file: \"" + _path.string() + "\".")); \
5151

52-
newFile << content;
52+
newFile << _content;
5353
}
5454

5555
bool solidity::test::createSymlinkIfSupportedByFilesystem(
5656
boost::filesystem::path const& _targetPath,
57-
boost::filesystem::path const& _linkName
57+
boost::filesystem::path const& _linkName,
58+
bool _directorySymlink
5859
)
5960
{
6061
boost::system::error_code symlinkCreationError;
61-
boost::filesystem::create_symlink(_targetPath, _linkName, symlinkCreationError);
62+
63+
if (_directorySymlink)
64+
boost::filesystem::create_directory_symlink(_targetPath, _linkName, symlinkCreationError);
65+
else
66+
boost::filesystem::create_symlink(_targetPath, _linkName, symlinkCreationError);
6267

6368
if (!symlinkCreationError)
6469
return true;

test/FilesystemUtils.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,20 @@ void createFilesWithParentDirs(std::set<boost::filesystem::path> const& _paths,
3535

3636
/// Creates a file with the exact content specified in the second argument.
3737
/// Throws an exception if the file already exists or if the parent directory of the file does not.
38-
void createFileWithContent(boost::filesystem::path const& _path, std::string const& content);
38+
void createFileWithContent(boost::filesystem::path const& _path, std::string const& _content);
3939

4040
/// Creates a symlink between two paths.
4141
/// The target does not have to exist.
42+
/// If @p directorySymlink is true, indicate to the operating system that this is a directory
43+
/// symlink. On some systems (e.g. Windows) it's possible to create a non-directory symlink pointing
44+
/// at a directory, which makes such a symlinks unusable.
4245
/// @returns true if the symlink has been successfully created, false if the filesystem does not
4346
/// support symlinks.
4447
/// Throws an exception of the operation fails for a different reason.
4548
bool createSymlinkIfSupportedByFilesystem(
4649
boost::filesystem::path const& _targetPath,
47-
boost::filesystem::path const& _linkName
50+
boost::filesystem::path const& _linkName,
51+
bool _directorySymlink
4852
);
4953

5054
}

test/libsolutil/CommonIO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ BOOST_AUTO_TEST_CASE(readFileAsString_symlink)
5858
TemporaryDirectory tempDir("common-io-test-");
5959
createFileWithContent(tempDir.path() / "test.txt", "ABC\ndef\n");
6060

61-
if (!createSymlinkIfSupportedByFilesystem("test.txt", tempDir.path() / "symlink.txt"))
61+
if (!createSymlinkIfSupportedByFilesystem("test.txt", tempDir.path() / "symlink.txt", false))
6262
return;
6363

6464
BOOST_TEST(readFileAsString(tempDir.path() / "symlink.txt") == "ABC\ndef\n");

0 commit comments

Comments
 (0)