From c02eacf4c4e1c7ab2a855fd79ee4184c4d77084e Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 14 Nov 2017 01:21:15 +0000 Subject: [PATCH] Use TempFile in llvm-ar. NFC. llvm-svn: 318127 --- llvm/lib/Object/ArchiveWriter.cpp | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/llvm/lib/Object/ArchiveWriter.cpp b/llvm/lib/Object/ArchiveWriter.cpp index 63f5082c29d9..8448b617b78b 100644 --- a/llvm/lib/Object/ArchiveWriter.cpp +++ b/llvm/lib/Object/ArchiveWriter.cpp @@ -488,14 +488,12 @@ Error llvm::writeArchive(StringRef ArcName, Kind = object::Archive::K_GNU64; } - SmallString<128> TmpArchive; - int TmpArchiveFD; - if (auto EC = sys::fs::createUniqueFile(ArcName + ".temp-archive-%%%%%%%.a", - TmpArchiveFD, TmpArchive)) - return errorCodeToError(EC); + Expected Temp = + sys::fs::TempFile::create(ArcName + ".temp-archive-%%%%%%%.a"); + if (!Temp) + return Temp.takeError(); - ToolOutputFile Output(TmpArchive, TmpArchiveFD); - raw_fd_ostream &Out = Output.os(); + raw_fd_ostream Out(Temp->FD, false); if (Thin) Out << "!\n"; else @@ -507,8 +505,7 @@ Error llvm::writeArchive(StringRef ArcName, for (const MemberData &M : Data) Out << M.Header << M.Data << M.Padding; - Output.keep(); - Out.close(); + Out.flush(); // At this point, we no longer need whatever backing memory // was used to generate the NewMembers. On Windows, this buffer @@ -522,6 +519,5 @@ Error llvm::writeArchive(StringRef ArcName, // closed before we attempt to rename. OldArchiveBuf.reset(); - sys::fs::rename(TmpArchive, ArcName); - return Error::success(); + return Temp->keep(ArcName); }