| 148 | } |
| 149 | |
| 150 | frontend::ReadCallback::Result FileRepository::readFile(std::string const& _kind, std::string const& _sourceUnitName) |
| 151 | { |
| 152 | solAssert( |
| 153 | _kind == ReadCallback::kindString(ReadCallback::Kind::ReadFile), |
| 154 | "ReadFile callback used as callback kind " + _kind |
| 155 | ); |
| 156 | |
| 157 | try |
| 158 | { |
| 159 | // File was read already. Use local store. |
| 160 | if (m_sourceCodes.count(_sourceUnitName)) |
| 161 | return ReadCallback::Result{true, m_sourceCodes.at(_sourceUnitName)}; |
| 162 | |
| 163 | std::string const strippedSourceUnitName = stripFileUriSchemePrefix(_sourceUnitName); |
| 164 | Result<boost::filesystem::path> const resolvedPath = tryResolvePath(strippedSourceUnitName); |
| 165 | if (!resolvedPath.message().empty()) |
| 166 | return ReadCallback::Result{false, resolvedPath.message()}; |
| 167 | |
| 168 | auto contents = readFileAsString(resolvedPath.get()); |
| 169 | solAssert(m_sourceCodes.count(_sourceUnitName) == 0, ""); |
| 170 | m_sourceCodes[_sourceUnitName] = contents; |
| 171 | return ReadCallback::Result{true, std::move(contents)}; |
| 172 | } |
| 173 | catch (...) |
| 174 | { |
| 175 | return ReadCallback::Result{false, "Exception in read callback: " + boost::current_exception_diagnostic_information()}; |
| 176 | } |
| 177 | } |
| 178 |
nothing calls this directly
no test coverage detected