| 67 | } |
| 68 | |
| 69 | void ContentSession::commit() { |
| 70 | for (const auto& resource : managedResources_) { |
| 71 | auto outStream = repository_->write(*resource.first); |
| 72 | if (outStream == nullptr) { |
| 73 | throw Exception(REPOSITORY_EXCEPTION, "Couldn't open the underlying resource for write: " + resource.first->getContentFullPath()); |
| 74 | } |
| 75 | const int size = gsl::narrow<int>(resource.second->size()); |
| 76 | const int bytes_written = outStream->write(const_cast<uint8_t*>(resource.second->getBuffer()), size); |
| 77 | if (bytes_written != size) { |
| 78 | throw Exception(REPOSITORY_EXCEPTION, "Failed to write new resource: " + resource.first->getContentFullPath()); |
| 79 | } |
| 80 | } |
| 81 | for (const auto& resource : extendedResources_) { |
| 82 | auto outStream = repository_->write(*resource.first, true); |
| 83 | if (outStream == nullptr) { |
| 84 | throw Exception(REPOSITORY_EXCEPTION, "Couldn't open the underlying resource for append: " + resource.first->getContentFullPath()); |
| 85 | } |
| 86 | const int size = gsl::narrow<int>(resource.second->size()); |
| 87 | const int bytes_written = outStream->write(const_cast<uint8_t*>(resource.second->getBuffer()), size); |
| 88 | if (bytes_written != size) { |
| 89 | throw Exception(REPOSITORY_EXCEPTION, "Failed to append to resource: " + resource.first->getContentFullPath()); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | managedResources_.clear(); |
| 94 | extendedResources_.clear(); |
| 95 | } |
| 96 | |
| 97 | void ContentSession::rollback() { |
| 98 | managedResources_.clear(); |