Don't include directory names in archives.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 20 Jun 2013 13:16:44 +0000 (13:16 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 20 Jun 2013 13:16:44 +0000 (13:16 +0000)
This matches the behavior of both gnu and os x versions of ar.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184420 91177308-0d34-0410-b5e6-96231b3b80d8

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

index f17ac5d36bdfa7772d092721d88f5b53c1986ee0..e10c3b43b82aedd9732735e4ffa4d5041cc10fee 100644 (file)
@@ -1,2 +1,8 @@
 ;RUN: not llvm-ar r %T/test.a . 2>&1 | FileCheck %s
 ;CHECK: . Is a directory
+
+;RUN: rm -f %T/test.a
+;RUN: llvm-ar r %T/test.a %s
+;RUN: llvm-ar t %T/test.a | FileCheck -check-prefix=MEMBERS %s
+;MEMBERS-NOT: /
+;MEMBERS: directory.ll
index cac65cf7706897eac835f07f9cef425a5d216ce4..520e410e1aca60fd5bad86cb637c0e08ee259d9f 100644 (file)
@@ -97,15 +97,8 @@ bool ArchiveMember::replaceWith(StringRef newFile, std::string* ErrMsg) {
   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;
index 79d95873fdef07c739702cb935906761d3423ee5..37489992cfaa244510ed4bf79dfa2c267b93ebba 100644 (file)
@@ -52,9 +52,8 @@ class ArchiveMember : public ilist_node<ArchiveMember> {
       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<ArchiveMember> {
     /// @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
index 5563b564b3909eb5d03da6a83651ab6068d54467..332d55f0a445daa007b72d591db868fab9ab25d5 100644 (file)
@@ -98,13 +98,7 @@ Archive::fillHeader(const ArchiveMember &mbr, ArchiveMemberHeader& hdr,
   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 filePath, iterator where,
   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 filePath, iterator where,
   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;
index 36bec4206d3b94be1655d3ee3d6f897bdd4ddd08..941b6310804d3376c40765433f47a8ff18c41e1f 100644 (file)
@@ -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;