martinzink commented on code in PR #1424:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1424#discussion_r1044569637
##########
extensions/standard-processors/processors/GetFile.cpp:
##########
@@ -154,36 +154,32 @@ void GetFile::onTrigger(core::ProcessContext*
/*context*/, core::ProcessSession*
return;
}
- std::queue<std::string> list_of_file_names = pollListing(request_.batchSize);
+ std::queue<std::filesystem::path> list_of_file_names =
pollListing(request_.batchSize);
while (!list_of_file_names.empty()) {
- std::string file_name = list_of_file_names.front();
+ auto file_name = list_of_file_names.front();
list_of_file_names.pop();
getSingleFile(*session, file_name);
}
}
-void GetFile::getSingleFile(core::ProcessSession& session, const std::string&
file_name) const {
- logger_->log_info("GetFile process %s", file_name);
+void GetFile::getSingleFile(core::ProcessSession& session, const
std::filesystem::path& file_path) const {
+ logger_->log_info("GetFile process %s", file_path.string());
auto flow_file = session.create();
gsl_Expects(flow_file);
- std::string path;
- std::string name;
- std::tie(path, name) = utils::file::split_path(file_name);
- flow_file->setAttribute(core::SpecialFlowAttribute::FILENAME, name);
- flow_file->setAttribute(core::SpecialFlowAttribute::PATH, path);
- flow_file->addAttribute(core::SpecialFlowAttribute::ABSOLUTE_PATH,
file_name);
+ flow_file->setAttribute(core::SpecialFlowAttribute::FILENAME,
file_path.filename().string());
+ flow_file->setAttribute(core::SpecialFlowAttribute::PATH,
(file_path.parent_path() / "").string());
+ flow_file->addAttribute(core::SpecialFlowAttribute::ABSOLUTE_PATH,
file_path.string());
try {
- session.write(flow_file, utils::FileReaderCallback{file_name});
+ session.write(flow_file, utils::FileReaderCallback{file_path});
session.transfer(flow_file, Success);
if (!request_.keepSourceFile) {
- auto remove_status = remove(file_name.c_str());
- if (remove_status != 0) {
- logger_->log_error("GetFile could not delete file '%s', error %d: %s",
file_name, errno, strerror(errno));
+ if (!std::filesystem::remove(file_path)) {
+ logger_->log_error("GetFile could not delete file '%s', error %d: %s",
file_path.string(), errno, strerror(errno));
Review Comment:
Nope, that wasnt intentional, good thing you caught it. Fixed it in
https://github.com/apache/nifi-minifi-cpp/pull/1424/commits/6c775d116236c92105c7be38bb284f309c27887c#diff-3f192172f343b26308cbdbb6f28836bcd8ca11f0484d3aa95450dde45970fa1fR175-R177
##########
extensions/standard-processors/processors/TailFile.cpp:
##########
@@ -530,21 +530,20 @@ bool
TailFile::getStateFromStateManager(std::map<std::string, TailState> &new_ta
readOptionalInt64(state_map, "file." + std::to_string(i) +
".last_read_time")
}};
- std::string fileLocation;
- std::string fileName;
- if (utils::file::getFileNameAndPath(current, fileLocation, fileName)) {
- logger_->log_debug("Received path %s, file %s", fileLocation,
fileName);
- new_tail_states.emplace(current, TailState{fileLocation, fileName,
position, last_read_time, checksum});
+ std::filesystem::path file_path = current;
+ if (file_path.has_filename() && file_path.has_parent_path()) {
+ logger_->log_debug("Received path %s, file %s",
file_path.parent_path().string(), file_path.filename().string());
+ new_tail_states.emplace(current, TailState{file_path.parent_path(),
file_path.filename(), position, last_read_time, checksum});
} else {
- new_tail_states.emplace(current, TailState{fileLocation, current,
position, last_read_time, checksum});
+ new_tail_states.emplace(current, TailState{file_path.parent_path(),
current, position, last_read_time, checksum});
Review Comment:
fixed it in
https://github.com/apache/nifi-minifi-cpp/pull/1424/commits/6c775d116236c92105c7be38bb284f309c27887c#diff-16a8df4d25f85ca2144b3e61d418c99e06ffc578461f288db8d32cd02d45307dR550
--
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]