adamdebreceni commented on a change in pull request #808:
URL: https://github.com/apache/nifi-minifi-cpp/pull/808#discussion_r439969614
##########
File path: libminifi/include/utils/file/FileManager.h
##########
@@ -61,46 +62,25 @@ class FileManager {
}
}
std::string unique_file(const std::string &location, bool keep = false) {
+ const std::string& dir = !IsNullOrEmpty(location) ? location :
utils::file::FileUtils::get_temp_directory();
-
- if (!IsNullOrEmpty(location)) {
- std::string file_name = location + FILE_SEPARATOR +
non_repeating_string_generator_.generate();
- while (!verify_not_exist(file_name)) {
- file_name = location + FILE_SEPARATOR +
non_repeating_string_generator_.generate();
- }
- if (!keep)
- unique_files_.push_back(file_name);
- return file_name;
- } else {
- std::string tmpDir = "/tmp";
- #ifdef WIN32
- TCHAR lpTempPathBuffer[MAX_PATH];
- GetTempPath(MAX_PATH, lpTempPathBuffer);
- tmpDir = lpTempPathBuffer;
- #endif
- std::string file_name = tmpDir + FILE_SEPARATOR +
non_repeating_string_generator_.generate();
- while (!verify_not_exist(file_name)) {
- file_name = tmpDir + FILE_SEPARATOR +
non_repeating_string_generator_.generate();
- }
- if (!keep)
- unique_files_.push_back(file_name);
- return file_name;
+ std::string file_name = utils::file::FileUtils::concat_path(dir,
non_repeating_string_generator_.generate());
+ while (!verify_not_exist(file_name)) {
+ file_name = utils::file::FileUtils::concat_path(dir,
non_repeating_string_generator_.generate());
}
+ if (!keep)
+ unique_files_.push_back(file_name);
+ return file_name;
}
std::string unique_file(bool keep = false) {
#ifdef BOOST_VERSION
return boost::filesystem::unique_path().native();
#else
- std::string tmpDir = "/tmp";
- #ifdef WIN32
- TCHAR lpTempPathBuffer[MAX_PATH];
- GetTempPath(MAX_PATH, lpTempPathBuffer);
- tmpDir = lpTempPathBuffer;
- #endif
- std::string file_name = tmpDir + FILE_SEPARATOR +
non_repeating_string_generator_.generate();
+ std::string tmpDir = utils::file::FileUtils::get_temp_directory();
+ std::string file_name = utils::file::FileUtils::concat_path(tmpDir,
non_repeating_string_generator_.generate());
while (!verify_not_exist(file_name)) {
- file_name = tmpDir + FILE_SEPARATOR +
non_repeating_string_generator_.generate();
+ file_name = utils::file::FileUtils::concat_path(tmpDir,
non_repeating_string_generator_.generate());
}
if (!keep)
unique_files_.push_back(file_name);
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.
For queries about this service, please contact Infrastructure at:
[email protected]