adamdebreceni commented on code in PR #2088:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2088#discussion_r2732119159
##########
libminifi/src/c2/C2Agent.cpp:
##########
@@ -1140,24 +1158,31 @@ void C2Agent::handleAssetUpdate(const
C2ContentResponse& resp) {
return;
}
- C2Payload file_response = protocol_->fetch(url);
-
- if (file_response.getStatus().getState() !=
state::UpdateState::READ_COMPLETE) {
- send_error("Failed to fetch asset from '" + url + "'");
- return;
- }
-
- auto raw_data = std::move(file_response).moveRawData();
// ensure directory exists for file
if (utils::file::create_dir(file_path.parent_path()) != 0) {
send_error("Failed to create directory '" +
file_path.parent_path().string() + "'");
return;
}
- {
- std::ofstream file{file_path, std::ofstream::binary};
- file.write(reinterpret_cast<const char*>(raw_data.data()),
gsl::narrow<std::streamsize>(raw_data.size()));
+ std::filesystem::path tmp_file{file_path.string() + ".part"};
+
+ std::ofstream file{tmp_file, std::ofstream::binary};
+ if (!file) {
+ send_error("Failed to open asset file to write '" + tmp_file.string() +
"'");
+ return;
}
+ bool success = protocol_->fetch(url, [&] (std::span<const char> chunk) {
+ file.write(chunk.data(), gsl::narrow<std::streamsize>(chunk.size()));
+ return file.good();
+ });
+ file.close();
+ if (!file || !success) {
+ std::filesystem::remove(tmp_file);
+ send_error("Failed to fetch asset from '" + url + "'");
+ return;
+ }
+
+ std::filesystem::rename(tmp_file, file_path);
Review Comment:
done
##########
core-framework/include/http/HTTPStream.h:
##########
@@ -127,11 +127,11 @@ class HttpStream : public io::BaseStreamImpl {
do {
logger_->log_trace("Waiting for more data");
} while (http_client_future_.wait_for(std::chrono::seconds(0)) !=
std::future_status::ready
- && http_client_->getReadCallback()
- && http_client_->getReadCallback()->getSize() == 0);
+ &&
dynamic_cast<utils::ByteOutputCallback*>(http_client_->getReadCallback())
+ &&
dynamic_cast<utils::ByteOutputCallback*>(http_client_->getReadCallback())->getSize()
== 0);
- return http_client_->getReadCallback()
- && http_client_->getReadCallback()->getSize() > 0;
+ return
dynamic_cast<utils::ByteOutputCallback*>(http_client_->getReadCallback())
+ &&
dynamic_cast<utils::ByteOutputCallback*>(http_client_->getReadCallback())->getSize()
> 0;
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]