mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #5259 from ethereum/cleanup8
Cleanup in some base utils
This commit is contained in:
commit
99dc869eb9
@ -80,45 +80,6 @@ string dev::readStandardInput()
|
||||
return ret;
|
||||
}
|
||||
|
||||
void dev::writeFile(std::string const& _file, bytesConstRef _data, bool _writeDeleteRename)
|
||||
{
|
||||
namespace fs = boost::filesystem;
|
||||
if (_writeDeleteRename)
|
||||
{
|
||||
fs::path tempPath = fs::unique_path(_file + "-%%%%%%");
|
||||
writeFile(tempPath.string(), _data, false);
|
||||
// will delete _file if it exists
|
||||
fs::rename(tempPath, _file);
|
||||
}
|
||||
else
|
||||
{
|
||||
// create directory if not existent
|
||||
fs::path p(_file);
|
||||
if (!p.parent_path().empty() && !fs::exists(p.parent_path()))
|
||||
{
|
||||
fs::create_directories(p.parent_path());
|
||||
try
|
||||
{
|
||||
fs::permissions(p.parent_path(), fs::owner_all);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
ofstream s(_file, ios::trunc | ios::binary);
|
||||
s.write(reinterpret_cast<char const*>(_data.data()), _data.size());
|
||||
assertThrow(s, FileError, "Could not write to file: " + _file);
|
||||
try
|
||||
{
|
||||
fs::permissions(_file, fs::owner_read|fs::owner_write);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
class DisableConsoleBuffering
|
||||
{
|
||||
|
@ -41,14 +41,6 @@ std::string readStandardInput();
|
||||
/// Retrieve and returns a character from standard input (without waiting for EOL).
|
||||
int readStandardInputChar();
|
||||
|
||||
/// Write the given binary data into the given file, replacing the file if it pre-exists.
|
||||
/// Throws exception on error.
|
||||
/// @param _writeDeleteRename useful not to lose any data: If set, first writes to another file in
|
||||
/// the same directory and then moves that file.
|
||||
void writeFile(std::string const& _file, bytesConstRef _data, bool _writeDeleteRename = false);
|
||||
/// Write the given binary data into the given file, replacing the file if it pre-exists.
|
||||
inline void writeFile(std::string const& _file, bytes const& _data, bool _writeDeleteRename = false) { writeFile(_file, bytesConstRef(&_data), _writeDeleteRename); }
|
||||
inline void writeFile(std::string const& _file, std::string const& _data, bool _writeDeleteRename = false) { writeFile(_file, bytesConstRef(_data), _writeDeleteRename); }
|
||||
/// Converts arbitrary value to string representation using std::stringstream.
|
||||
template <class _T>
|
||||
std::string toString(_T const& _t)
|
||||
|
@ -1118,7 +1118,15 @@ void CommandLineInterface::writeLinkedFiles()
|
||||
if (src.first == g_stdinFileName)
|
||||
cout << src.second << endl;
|
||||
else
|
||||
writeFile(src.first, src.second);
|
||||
{
|
||||
ofstream outFile(src.first);
|
||||
outFile << src.second;
|
||||
if (!outFile)
|
||||
{
|
||||
cerr << "Could not write to file " << src.first << ". Aborting." << endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string CommandLineInterface::libraryPlaceholderHint(string const& _libraryName)
|
||||
|
Loading…
Reference in New Issue
Block a user