[PATCH] D40606: [Support/TarWriter] - Don't allow TarWriter to add the same file more than once.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 30 09:44:50 PST 2017


grimar updated this revision to Diff 124958.
grimar added a comment.

- Use llvm::StringSet instead of std::set<std::string>.


https://reviews.llvm.org/D40606

Files:
  include/llvm/Support/TarWriter.h
  lib/Support/TarWriter.cpp


Index: lib/Support/TarWriter.cpp
===================================================================
--- lib/Support/TarWriter.cpp
+++ lib/Support/TarWriter.cpp
@@ -173,6 +173,10 @@
   // Write Path and Data.
   std::string Fullpath = BaseDir + "/" + sys::path::convert_to_slash(Path);
 
+  // We do not want to include the same file more than once.
+  if (!Files.insert(Fullpath).second)
+    return;
+
   StringRef Prefix;
   StringRef Name;
   if (splitUstar(Fullpath, Prefix, Name)) {
Index: include/llvm/Support/TarWriter.h
===================================================================
--- include/llvm/Support/TarWriter.h
+++ include/llvm/Support/TarWriter.h
@@ -11,6 +11,7 @@
 #define LLVM_SUPPORT_TAR_WRITER_H
 
 #include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -26,6 +27,7 @@
   TarWriter(int FD, StringRef BaseDir);
   raw_fd_ostream OS;
   std::string BaseDir;
+  StringSet<> Files;
 };
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40606.124958.patch
Type: text/x-patch
Size: 1002 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171130/8a63a127/attachment.bin>


More information about the llvm-commits mailing list