#include <test/FilesystemUtils.h>
#include <test/libsolidity/util/SoltestErrors.h>
using namespace std;
using namespace solidity;
using namespace solidity::test;
void solidity::test::createFilesWithParentDirs(set<boost::filesystem::path> const& _paths, string const& _content)
{
for (boost::filesystem::path const& path: _paths)
{
if (!path.parent_path().empty())
boost::filesystem::create_directories(path.parent_path());
ofstream newFile(path.string(), std::ofstream::binary);
newFile << _content;
if (newFile.fail() || !boost::filesystem::exists(path))
BOOST_THROW_EXCEPTION(runtime_error("Failed to create an empty file: \"" + path.string() + "\"."));
}
}
void solidity::test::createFileWithContent(boost::filesystem::path const& _path, string const& _content)
{
if (boost::filesystem::is_regular_file(_path))
BOOST_THROW_EXCEPTION(runtime_error("File already exists: \"" + _path.string() + "\".")); \
ofstream newFile(_path.string(), std::ofstream::binary);
if (newFile.fail() || !boost::filesystem::is_regular_file(_path))
BOOST_THROW_EXCEPTION(runtime_error("Failed to create a file: \"" + _path.string() + "\".")); \
newFile << _content;
}
bool solidity::test::createSymlinkIfSupportedByFilesystem(
boost::filesystem::path _targetPath,
boost::filesystem::path const& _linkName,
bool _directorySymlink
)
{
boost::system::error_code symlinkCreationError;
_targetPath.make_preferred();
if (_directorySymlink)
boost::filesystem::create_directory_symlink(_targetPath, _linkName, symlinkCreationError);
else
boost::filesystem::create_symlink(_targetPath, _linkName, symlinkCreationError);
if (!symlinkCreationError)
return true;
else if (
symlinkCreationError == boost::system::errc::not_supported ||
symlinkCreationError == boost::system::errc::operation_not_supported
)
return false;
else
BOOST_THROW_EXCEPTION(runtime_error(
"Failed to create a symbolic link: \"" + _linkName.string() + "\""
" -> " + _targetPath.string() + "\"."
" " + symlinkCreationError.message() + "."
));
}