[llvm] r184423 - Add r184420 back, but also handle long file names.

Rafael Espindola rafael.espindola at gmail.com
Thu Jun 20 06:41:52 PDT 2013


Author: rafael
Date: Thu Jun 20 08:41:51 2013
New Revision: 184423

URL: http://llvm.org/viewvc/llvm-project?rev=184423&view=rev
Log:
Add r184420 back, but also handle long file names.

Original message:

Don't include directory names in archives.

This matches the behavior of both gnu and os x versions of ar.

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

Modified: llvm/trunk/test/Archive/directory.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Archive/directory.ll?rev=184423&r1=184422&r2=184423&view=diff
==============================================================================
--- llvm/trunk/test/Archive/directory.ll (original)
+++ llvm/trunk/test/Archive/directory.ll Thu Jun 20 08:41:51 2013
@@ -1,2 +1,10 @@
 ;RUN: not llvm-ar r %T/test.a . 2>&1 | FileCheck %s
 ;CHECK: . Is a directory
+
+;RUN: rm -f %T/test.a
+;RUN: touch %T/a-very-long-file-name
+;RUN: llvm-ar r %T/test.a %s %T/a-very-long-file-name
+;RUN: llvm-ar t %T/test.a | FileCheck -check-prefix=MEMBERS %s
+;MEMBERS-NOT: /
+;MEMBERS: a-very-long-file-name
+;MEMBERS: directory.ll

Modified: llvm/trunk/tools/llvm-ar/Archive.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/Archive.cpp?rev=184423&r1=184422&r2=184423&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/Archive.cpp (original)
+++ llvm/trunk/tools/llvm-ar/Archive.cpp Thu Jun 20 08:41:51 2013
@@ -97,15 +97,8 @@ bool ArchiveMember::replaceWith(StringRe
   else
     flags &= ~StringTableFlag;
 
-  // If it has a slash then it has a path
-  bool hasSlash = path.find('/') != std::string::npos;
-  if (hasSlash)
-    flags |= HasPathFlag;
-  else
-    flags &= ~HasPathFlag;
-
   // If it has a slash or its over 15 chars then its a long filename format
-  if (hasSlash || path.length() > 15)
+  if (path.length() > 15)
     flags |= HasLongFilenameFlag;
   else
     flags &= ~HasLongFilenameFlag;

Modified: llvm/trunk/tools/llvm-ar/Archive.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/Archive.h?rev=184423&r1=184422&r2=184423&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/Archive.h (original)
+++ llvm/trunk/tools/llvm-ar/Archive.h Thu Jun 20 08:41:51 2013
@@ -52,9 +52,8 @@ class ArchiveMember : public ilist_node<
       SVR4SymbolTableFlag = 1,     ///< Member is a SVR4 symbol table
       BSD4SymbolTableFlag = 2,     ///< Member is a BSD4 symbol table
       BitcodeFlag         = 4,     ///< Member is bitcode
-      HasPathFlag         = 8,     ///< Member has a full or partial path
-      HasLongFilenameFlag = 16,    ///< Member uses the long filename syntax
-      StringTableFlag     = 32     ///< Member is an ar(1) format string table
+      HasLongFilenameFlag = 8,     ///< Member uses the long filename syntax
+      StringTableFlag     = 16     ///< Member is an ar(1) format string table
     };
 
   /// @}
@@ -125,10 +124,6 @@ class ArchiveMember : public ilist_node<
     /// @brief Determine if this member is a bitcode file.
     bool isBitcode() const { return flags&BitcodeFlag; }
 
-    /// @returns true iff the file name contains a path (directory) component.
-    /// @brief Determine if the member has a path
-    bool hasPath() const { return flags&HasPathFlag; }
-
     /// Long filenames are an artifact of the ar(1) file format which allows
     /// up to sixteen characters in its header and doesn't allow a path
     /// separator character (/). To avoid this, a "long format" member name is

Modified: llvm/trunk/tools/llvm-ar/ArchiveWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/ArchiveWriter.cpp?rev=184423&r1=184422&r2=184423&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/ArchiveWriter.cpp (original)
+++ llvm/trunk/tools/llvm-ar/ArchiveWriter.cpp Thu Jun 20 08:41:51 2013
@@ -98,13 +98,7 @@ Archive::fillHeader(const ArchiveMember
   sprintf(buffer,"%-12u", unsigned(secondsSinceEpoch));
   memcpy(hdr.date,buffer,12);
 
-  // Get rid of trailing blanks in the name
-  std::string mbrPath = mbr.getPath().str();
-  size_t mbrLen = mbrPath.length();
-  while (mbrLen > 0 && mbrPath[mbrLen-1] == ' ') {
-    mbrPath.erase(mbrLen-1,1);
-    mbrLen--;
-  }
+  std::string mbrPath = sys::path::filename(mbr.getPath());
 
   // Set the name field in one of its various flavors.
   bool writeLongName = false;
@@ -165,8 +159,8 @@ bool Archive::addFileBefore(StringRef fi
   ArchiveMember* mbr = new ArchiveMember(this);
 
   mbr->data = 0;
-  mbr->path = filePath.str();
-  sys::PathWithStatus PWS(mbr->path);
+  mbr->path = filePath;
+  sys::PathWithStatus PWS(filePath);
   const sys::FileStatus *FSInfo = PWS.getFileStatus(false, ErrMsg);
   if (!FSInfo) {
     delete mbr;
@@ -179,10 +173,7 @@ bool Archive::addFileBefore(StringRef fi
   mbr->Size = FSInfo->getSize();
 
   unsigned flags = 0;
-  bool hasSlash = filePath.str().find('/') != std::string::npos;
-  if (hasSlash)
-    flags |= ArchiveMember::HasPathFlag;
-  if (hasSlash || filePath.str().length() > 15)
+  if (sys::path::filename(filePath).size() > 15)
     flags |= ArchiveMember::HasLongFilenameFlag;
 
   sys::fs::file_magic type;
@@ -240,8 +231,8 @@ Archive::writeMember(
 
   // Write the long filename if its long
   if (writeLongName) {
-    ARFile.write(member.getPath().str().data(),
-                 member.getPath().str().length());
+    StringRef Name = sys::path::filename(member.getPath());
+    ARFile.write(Name.data(), Name.size());
   }
 
   // Write the (possibly compressed) member's content to the file.

Modified: llvm/trunk/tools/llvm-ar/llvm-ar.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/llvm-ar.cpp?rev=184423&r1=184422&r2=184423&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)
+++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Thu Jun 20 08:41:51 2013
@@ -399,14 +399,6 @@ doExtract(std::string* ErrMsg) {
     if (Paths.empty() ||
         (std::find(Paths.begin(), Paths.end(), I->getPath()) != Paths.end())) {
 
-      // Make sure the intervening directories are created
-      if (I->hasPath()) {
-        sys::Path dirs(I->getPath());
-        dirs.eraseComponent();
-        if (dirs.createDirectoryOnDisk(/*create_parents=*/true, ErrMsg))
-          return true;
-      }
-
       // Open up a file stream for writing
       std::ios::openmode io_mode = std::ios::out | std::ios::trunc |
                                    std::ios::binary;





More information about the llvm-commits mailing list