This is an archive of the discontinued LLVM Phabricator instance.

[llvm-ar] Support N [count] modifier
ClosedPublic

Authored by rupprecht on Mar 18 2019, 11:59 AM.

Details

Summary

GNU ar supports the 'N' count modifier for the extract (x) and delete (d) operations. When an archive contains multiple members with the same name, this can be used to extract (or delete) them individually. For example:

$ llvm-ar t archive.a
foo
foo
$ llvm-ar x archive.a
-> Writes foo twice, overwriting it the second time :( :(
$ llvm-ar xN 1 archive.a foo && mv foo foo.1
$ llvm-ar xN 2 archive.a foo && mv foo foo.2
-> Write foo twice, renaming it in between invocations to preserve all versions

Event Timeline

rupprecht created this revision.Mar 18 2019, 11:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 18 2019, 11:59 AM
ruiu added a comment.Mar 18 2019, 1:15 PM

Wow, this option is too good... I'm using Unix more than 20 years now but didn't know this option existed. In rare occasions where I had to extract a file with a duplicate name, I opened an archive file using a binary editor and rename a file name before extracting.

llvm/tools/llvm-ar/llvm-ar.cpp
194

If this is 1-indexed, you could use 0 to indicate that the option was not given, which allows you to remove UseCountParam. (But this is perhaps more like a personal preference, so you can ignore this comment.)

rupprecht updated this revision to Diff 191162.Mar 18 2019, 1:32 PM
rupprecht marked an inline comment as done.
  • Remove UseCountParam, as CountParam != 0 implies the same thing
ruiu accepted this revision.Mar 18 2019, 1:37 PM

LGTM

This revision is now accepted and ready to land.Mar 18 2019, 1:37 PM
MaskRay accepted this revision.Mar 18 2019, 9:10 PM
This revision was automatically updated to reflect the committed changes.