[llvm] r184599 - Convert some uses of PathV1.h in ArchiveWriter.cpp.

Rafael Espindola rafael.espindola at gmail.com
Fri Jun 21 15:11:36 PDT 2013


Author: rafael
Date: Fri Jun 21 17:11:36 2013
New Revision: 184599

URL: http://llvm.org/viewvc/llvm-project?rev=184599&view=rev
Log:
Convert some uses of PathV1.h in ArchiveWriter.cpp.

Modified:
    llvm/trunk/tools/llvm-ar/Archive.h
    llvm/trunk/tools/llvm-ar/ArchiveWriter.cpp

Modified: llvm/trunk/tools/llvm-ar/Archive.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/Archive.h?rev=184599&r1=184598&r2=184599&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/Archive.h (original)
+++ llvm/trunk/tools/llvm-ar/Archive.h Fri Jun 21 17:11:36 2013
@@ -20,6 +20,7 @@
 #include "llvm/ADT/ilist.h"
 #include "llvm/ADT/ilist_node.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/TimeValue.h"
 #include <map>
 #include <set>
@@ -375,7 +376,7 @@ class Archive {
     /// returns true if writing member failed, \p error set to error message.
     bool writeMember(
       const ArchiveMember& member, ///< The member to be written
-      std::ofstream& ARFile,       ///< The file to write member onto
+      raw_fd_ostream& ARFile,      ///< The file to write member onto
       bool TruncateNames,          ///< Should names be truncated to 11 chars?
       std::string* ErrMessage      ///< If non-null, place were error msg is set
     );

Modified: llvm/trunk/tools/llvm-ar/ArchiveWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/ArchiveWriter.cpp?rev=184599&r1=184598&r2=184599&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/ArchiveWriter.cpp (original)
+++ llvm/trunk/tools/llvm-ar/ArchiveWriter.cpp Fri Jun 21 17:11:36 2013
@@ -160,17 +160,22 @@ bool Archive::addFileBefore(StringRef fi
 
   mbr->data = 0;
   mbr->path = filePath;
-  sys::PathWithStatus PWS(filePath);
-  const sys::FileStatus *FSInfo = PWS.getFileStatus(false, ErrMsg);
-  if (!FSInfo) {
+  sys::fs::file_status Status;
+  error_code EC = sys::fs::status(filePath, Status);
+  if (EC) {
+    delete mbr;
+    return true;
+  }
+  mbr->User = Status.getUser();
+  mbr->Group = Status.getGroup();
+  mbr->Mode = Status.permissions();
+  mbr->ModTime = Status.getLastModificationTime();
+  // FIXME: On posix this is a second stat.
+  EC =  sys::fs::file_size(filePath, mbr->Size);
+  if (EC) {
     delete mbr;
     return true;
   }
-  mbr->User = FSInfo->getUser();
-  mbr->Group = FSInfo->getGroup();
-  mbr->Mode = FSInfo->getMode();
-  mbr->ModTime = FSInfo->getTimestamp();
-  mbr->Size = FSInfo->getSize();
 
   unsigned flags = 0;
   if (sys::path::filename(filePath).size() > 15)
@@ -195,12 +200,12 @@ bool Archive::addFileBefore(StringRef fi
 bool
 Archive::writeMember(
   const ArchiveMember& member,
-  std::ofstream& ARFile,
+  raw_fd_ostream& ARFile,
   bool TruncateNames,
   std::string* ErrMsg
 ) {
 
-  unsigned filepos = ARFile.tellp();
+  uint64_t filepos = ARFile.tell();
   filepos -= 8;
 
   // Get the data and its size either from the
@@ -239,7 +244,7 @@ Archive::writeMember(
   ARFile.write(data,fSize);
 
   // Make sure the member is an even length
-  if ((ARFile.tellp() & 1) == 1)
+  if ((ARFile.tell() & 1) == 1)
     ARFile << ARFILE_PAD;
 
   // Close the mapped file if it was opened
@@ -261,25 +266,18 @@ bool Archive::writeToDisk(bool TruncateN
   }
 
   // Create a temporary file to store the archive in
-  sys::Path TmpArchive(archPath);
-  if (TmpArchive.createTemporaryFileOnDisk(ErrMsg))
+  int TmpArchiveFD;
+  SmallString<128> TmpArchive;
+  error_code EC = sys::fs::unique_file("temp-archive-%%%%%%%.a", TmpArchiveFD,
+                                       TmpArchive);
+  if (EC)
     return true;
 
   // Make sure the temporary gets removed if we crash
-  sys::RemoveFileOnSignal(TmpArchive.str());
+  sys::RemoveFileOnSignal(TmpArchive);
 
   // Create archive file for output.
-  std::ios::openmode io_mode = std::ios::out | std::ios::trunc |
-                               std::ios::binary;
-  std::ofstream ArchiveFile(TmpArchive.c_str(), io_mode);
-
-  // Check for errors opening or creating archive file.
-  if (!ArchiveFile.is_open() || ArchiveFile.bad()) {
-    TmpArchive.eraseFromDisk();
-    if (ErrMsg)
-      *ErrMsg = "Error opening archive file: " + archPath;
-    return true;
-  }
+  raw_fd_ostream ArchiveFile(TmpArchiveFD, true);
 
   // Write magic string to archive.
   ArchiveFile << ARFILE_MAGIC;
@@ -288,7 +286,7 @@ bool Archive::writeToDisk(bool TruncateN
   // builds the symbol table, symTab.
   for (MembersList::iterator I = begin(), E = end(); I != E; ++I) {
     if (writeMember(*I, ArchiveFile, TruncateNames, ErrMsg)) {
-      TmpArchive.eraseFromDisk();
+      sys::fs::remove(Twine(TmpArchive));
       ArchiveFile.close();
       return true;
     }
@@ -302,8 +300,10 @@ bool Archive::writeToDisk(bool TruncateN
   // this because we cannot replace an open file on Windows.
   cleanUpMemory();
 
-  if (TmpArchive.renamePathOnDisk(sys::Path(archPath), ErrMsg))
+  if (sys::fs::rename(Twine(TmpArchive), archPath)) {
+    *ErrMsg = EC.message();
     return true;
+  }
 
   // Set correct read and write permissions after temporary file is moved
   // to final destination path.





More information about the llvm-commits mailing list