Index: include/llvm/Support/TarWriter.h =================================================================== --- include/llvm/Support/TarWriter.h +++ include/llvm/Support/TarWriter.h @@ -13,6 +13,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Support/Error.h" #include "llvm/Support/raw_ostream.h" +#include namespace llvm { class TarWriter { @@ -20,12 +21,13 @@ static Expected> create(StringRef OutputPath, StringRef BaseDir); - void append(StringRef Path, StringRef Data); + bool append(StringRef Path, StringRef Data); private: TarWriter(int FD, StringRef BaseDir); raw_fd_ostream OS; std::string BaseDir; + std::set Files; }; } Index: lib/Support/TarWriter.cpp =================================================================== --- lib/Support/TarWriter.cpp +++ lib/Support/TarWriter.cpp @@ -169,10 +169,15 @@ : OS(FD, /*shouldClose=*/true, /*unbuffered=*/false), BaseDir(BaseDir) {} // Append a given file to an archive. -void TarWriter::append(StringRef Path, StringRef Data) { +bool TarWriter::append(StringRef Path, StringRef Data) { // Write Path and Data. std::string Fullpath = BaseDir + "/" + sys::path::convert_to_slash(Path); + bool Exist; + std::tie(std::ignore, Exist) = Files.insert(Fullpath); + if (Exist) + return false; + StringRef Prefix; StringRef Name; if (splitUstar(Fullpath, Prefix, Name)) { @@ -192,4 +197,6 @@ OS << std::string(BlockSize * 2, '\0'); OS.seek(Pos); OS.flush(); + + return true; }