3
0
Prechádzať zdrojové kódy

Fixed file name collisions when executing in parallel by using a hash function

Stefan Schmidt 6 rokov pred
rodič
commit
bb63f7b667
1 zmenil súbory, kde vykonal 6 pridanie a 2 odobranie
  1. 6 2
      code_boost/src/cxx/pcap_processor.cpp

+ 6 - 2
code_boost/src/cxx/pcap_processor.cpp

@@ -49,9 +49,13 @@ std::string pcap_processor::merge_pcaps(const std::string pcap_path) {
     strftime(buff, sizeof(buff), "%Y%m%d-%H%M%S", now);
     std::string tstmp(buff);
 
-    // Replace filename with 'timestamp_filename'
+    // Calculate hash of the temporary pcap name
+    std::hash<std::string> hash_fn;
+    std::string hashstr = std::to_string(hash_fn(pcap_path));
+
+    // Replace filename with 'filename_timestamp_hash'
     std::string new_filepath = filePath;
-    const std::string &newExt = "_" + tstmp + ".pcap";
+    const std::string &newExt = "_" + tstmp + "_" + hashstr + ".pcap";
     std::string::size_type h = new_filepath.rfind('.', new_filepath.length());
 
     if ((filePath.length() + newExt.length()) < 250) {