| 105 | } |
| 106 | |
| 107 | void dev::writeFile(std::string const& _file, bytesConstRef _data, bool _writeDeleteRename) |
| 108 | { |
| 109 | namespace fs = boost::filesystem; |
| 110 | if (_writeDeleteRename) |
| 111 | { |
| 112 | fs::path tempPath = fs::unique_path(_file + "-%%%%%%"); |
| 113 | writeFile(tempPath.string(), _data, false); |
| 114 | // will delete _file if it exists |
| 115 | fs::rename(tempPath, _file); |
| 116 | } |
| 117 | else |
| 118 | { |
| 119 | // create directory if not existent |
| 120 | fs::path p(_file); |
| 121 | if (!fs::exists(p.parent_path())) |
| 122 | { |
| 123 | fs::create_directories(p.parent_path()); |
| 124 | DEV_IGNORE_EXCEPTIONS(fs::permissions(p.parent_path(), fs::owner_all)); |
| 125 | } |
| 126 | |
| 127 | ofstream s(_file, ios::trunc | ios::binary); |
| 128 | s.write(reinterpret_cast<char const*>(_data.data()), _data.size()); |
| 129 | if (!s) |
| 130 | BOOST_THROW_EXCEPTION(FileError() << errinfo_comment("Could not write to file: " + _file)); |
| 131 | DEV_IGNORE_EXCEPTIONS(fs::permissions(_file, fs::owner_read|fs::owner_write)); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | std::string dev::getPassword(std::string const& _prompt) |
| 136 | { |