| 255 | } |
| 256 | |
| 257 | bool PlatformFileSystem::saveContent(PathId fileId, const char *content, |
| 258 | std::streamsize length, bool useTemp) { |
| 259 | if (!fileId) return false; |
| 260 | |
| 261 | const std::filesystem::path filepath = toPath(fileId); |
| 262 | if (filepath.empty()) return false; |
| 263 | |
| 264 | bool result = false; |
| 265 | |
| 266 | std::filesystem::path filepath2Write = filepath; |
| 267 | if (useTemp) filepath2Write += ".tmp"; |
| 268 | |
| 269 | std::ostream &strm = |
| 270 | openOutput(filepath2Write, std::ios_base::out | std::ios_base::binary); |
| 271 | if (strm.good()) { |
| 272 | if (length > 0) { |
| 273 | strm.write(content, length); |
| 274 | } |
| 275 | result = strm.good(); |
| 276 | } |
| 277 | close(strm); |
| 278 | |
| 279 | if (useTemp) { |
| 280 | std::error_code ec; |
| 281 | if (result) { |
| 282 | std::filesystem::rename(filepath2Write, filepath, ec); |
| 283 | result = !ec; |
| 284 | } else { |
| 285 | std::filesystem::remove(filepath2Write, ec); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | return result; |
| 290 | } |
| 291 | |
| 292 | bool PlatformFileSystem::addMapping(std::string_view what, |
| 293 | std::string_view with) { |