[PATCH] D57927: [llvm-ar] Implement the P modifier.

Jordan Rupprecht via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 7 15:00:58 PST 2019


rupprecht added a comment.

In D57927#1389723 <https://reviews.llvm.org/D57927#1389723>, @ruiu wrote:

> I played with ar and found that the following behavior is pretty odd.
>
> 1. Create an archive $ mkdir x $ echo 123 > x/foo.txt $ ar rcS archive.a x/foo.txt
> 2. Directory name is not stored to archive.a $ cat archive.a !<arch> foo.txt/        0           0     0     644     4         ` 123
> 3. But you can extract foo.txt with any directory name $ ar x archive.a bar/foo.txt $ cat foo.txt 123
>
>   If I understand correctly, `ar` by default ignores directory names in many situations like the above, and "P" flag is to make it to not ignore directory names in a pathname. It looks like the default behavior is broken. Is that important for compatibility? I wonder if there's a chance to make "P" the default behavior.


Yes, the more I dug into pathnames, the more confusing it got... just to clarify, directory names are never stored in the non-thin archive format; the P option is only for whether full path names are used for comparisons (e.g. reading/extracting a single member from an archive, deleting a single member from an archive, etc.)

Your example is odd, but I don't think it would be invoked this way. Although making P the default would make your example make sense, the counterexample would be confusing in a more normal case:

  $ mkdir x
  $ echo 123 > x/foo.txt
  $ ar rcSP archive.a x/foo.txt
  
  # Directory name still not stored even though P is present
  $ cat archive.a
  !<arch>
  foo.txt/        0           0     0     644     4         `
  123
  
  # The file we just added is there, right?
  $ ar tP archive.a x/foo.txt
  no entry x/foo.txt in archive
  
  # Nope, we have to chop off the directory ourselves to find it.
  $ ar tP archive.a foo.txt
  foo.txt


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D57927/new/

https://reviews.llvm.org/D57927





More information about the llvm-commits mailing list