@@ -488,14 +488,12 @@ Error llvm::writeArchive(StringRef ArcName,
488
488
Kind = object::Archive::K_GNU64;
489
489
}
490
490
491
- SmallString<128 > TmpArchive;
492
- int TmpArchiveFD;
493
- if (auto EC = sys::fs::createUniqueFile (ArcName + " .temp-archive-%%%%%%%.a" ,
494
- TmpArchiveFD, TmpArchive))
495
- return errorCodeToError (EC);
491
+ Expected<sys::fs::TempFile> Temp =
492
+ sys::fs::TempFile::create (ArcName + " .temp-archive-%%%%%%%.a" );
493
+ if (!Temp)
494
+ return Temp.takeError ();
496
495
497
- ToolOutputFile Output (TmpArchive, TmpArchiveFD);
498
- raw_fd_ostream &Out = Output.os ();
496
+ raw_fd_ostream Out (Temp->FD , false );
499
497
if (Thin)
500
498
Out << " !<thin>\n " ;
501
499
else
@@ -507,8 +505,7 @@ Error llvm::writeArchive(StringRef ArcName,
507
505
for (const MemberData &M : Data)
508
506
Out << M.Header << M.Data << M.Padding ;
509
507
510
- Output.keep ();
511
- Out.close ();
508
+ Out.flush ();
512
509
513
510
// At this point, we no longer need whatever backing memory
514
511
// was used to generate the NewMembers. On Windows, this buffer
@@ -522,6 +519,5 @@ Error llvm::writeArchive(StringRef ArcName,
522
519
// closed before we attempt to rename.
523
520
OldArchiveBuf.reset ();
524
521
525
- sys::fs::rename (TmpArchive, ArcName);
526
- return Error::success ();
522
+ return Temp->keep (ArcName);
527
523
}
0 commit comments