|
| 1 | +/* |
| 2 | + This file is part of solidity. |
| 3 | +
|
| 4 | + solidity is free software: you can redistribute it and/or modify |
| 5 | + it under the terms of the GNU General Public License as published by |
| 6 | + the Free Software Foundation, either version 3 of the License, or |
| 7 | + (at your option) any later version. |
| 8 | +
|
| 9 | + solidity is distributed in the hope that it will be useful, |
| 10 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + GNU General Public License for more details. |
| 13 | +
|
| 14 | + You should have received a copy of the GNU General Public License |
| 15 | + along with solidity. If not, see <http://www.gnu.org/licenses/>. |
| 16 | +*/ |
| 17 | +// SPDX-License-Identifier: GPL-3.0 |
| 18 | + |
| 19 | +#include <test/FilesystemUtils.h> |
| 20 | + |
| 21 | +#include <test/libsolidity/util/SoltestErrors.h> |
| 22 | + |
| 23 | +using namespace std; |
| 24 | +using namespace solidity; |
| 25 | +using namespace solidity::test; |
| 26 | + |
| 27 | +void solidity::test::createFileWithContent(boost::filesystem::path const& _path, string const& content) |
| 28 | +{ |
| 29 | + if (boost::filesystem::is_regular_file(_path)) |
| 30 | + BOOST_THROW_EXCEPTION(runtime_error("File already exists: \"" + _path.string() + "\".")); \ |
| 31 | + |
| 32 | + // Use binary mode to avoid line ending conversion on Windows. |
| 33 | + ofstream newFile(_path.string(), std::ofstream::binary); |
| 34 | + if (newFile.fail() || !boost::filesystem::is_regular_file(_path)) |
| 35 | + BOOST_THROW_EXCEPTION(runtime_error("Failed to create a file: \"" + _path.string() + "\".")); \ |
| 36 | + |
| 37 | + newFile << content; |
| 38 | +} |
| 39 | + |
| 40 | +bool solidity::test::createSymlinkIfSupportedByFilesystem( |
| 41 | + boost::filesystem::path const& _targetPath, |
| 42 | + boost::filesystem::path const& _linkName |
| 43 | +) |
| 44 | +{ |
| 45 | + boost::system::error_code symlinkCreationError; |
| 46 | + boost::filesystem::create_symlink(_targetPath, _linkName, symlinkCreationError); |
| 47 | + |
| 48 | + if (!symlinkCreationError) |
| 49 | + return true; |
| 50 | + else if ( |
| 51 | + symlinkCreationError == boost::system::errc::not_supported || |
| 52 | + symlinkCreationError == boost::system::errc::operation_not_supported |
| 53 | + ) |
| 54 | + return false; |
| 55 | + else |
| 56 | + BOOST_THROW_EXCEPTION(runtime_error( |
| 57 | + "Failed to create a symbolic link: \"" + _linkName.string() + "\"" |
| 58 | + " -> " + _targetPath.string() + "\"." |
| 59 | + )); |
| 60 | +} |
0 commit comments