You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2020/06/12 15:42:20 UTC

[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #808: MINIFICPP-1234 - Enable all archive tests on Windows.

szaszm commented on a change in pull request #808:
URL: https://github.com/apache/nifi-minifi-cpp/pull/808#discussion_r439495642



##########
File path: libminifi/test/archive-tests/ManipulateArchiveTests.cpp
##########
@@ -90,9 +89,7 @@ bool run_archive_test(OrderedTestArchive input_archive, OrderedTestArchive outpu
     plan->runNextProcessor();  // ManipulateArchive
     plan->runNextProcessor();  // PutFile 2 (manipulated)
 
-    std::stringstream ss2;
-    ss2 << dir2 << "/" << TEST_ARCHIVE_NAME;
-    std::string output_path = ss2.str();
+    std::string output_path =utils::file::FileUtils::concat_path(dir2, TEST_ARCHIVE_NAME);

Review comment:
       linter error: missing space after `=`
   
   ```
   /Users/travis/build/apache/nifi-minifi-cpp/libminifi/test//archive-tests/ManipulateArchiveTests.cpp:92:  Missing spaces around =  [whitespace/operators] [4]
   ```

##########
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;

Review comment:
       :+1: 

##########
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:
       To me this function looks like it could nicely delegate.
   ```
     std::string unique_file(bool keep = false) {
   #ifdef BOOST_VERSION
       return boost::filesystem::unique_path().native();
   #else  // BOOST_VERSION
       return unique_file(std::string{}, keep);
   #endif  // BOOST_VERSION
     }
   ```




----------------------------------------------------------------
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:
users@infra.apache.org