Skip to content

Instantly share code, notes, and snippets.

/TarUpdate.diff Secret

Created September 20, 2011 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/57177e5f57d6859a3bea to your computer and use it in GitHub Desktop.
Save anonymous/57177e5f57d6859a3bea to your computer and use it in GitHub Desktop.
7zip tar pax header patch
*** old/TarUpdate.cpp
--- new/TarUpdate.cpp
***************
*** 13,25 ****
namespace NArchive {
namespace NTar {
HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
const CObjectVector<NArchive::NTar::CItemEx> &inputItems,
! const CObjectVector<CUpdateItem> &updateItems,
IArchiveUpdateCallback *updateCallback)
{
COutArchive outArchive;
outArchive.Create(outStream);
UInt64 complexity = 0;
--- 13,44 ----
namespace NArchive {
namespace NTar {
+ static int CompareTarUpdateItems(void *const *x, void *const *y, void *)
+ {
+ const CUpdateItem* p1 = *((const CUpdateItem**)x);
+ const CUpdateItem* p2 = *((const CUpdateItem**)y);
+
+ if(!(p1->NewProps || p2->NewProps)) //Both are existing files
+ return MyCompare(p1->IndexInArchive, p2->IndexInArchive);
+
+ if(p1->NewProps!=p2->NewProps)
+ return p1->NewProps?1:-1; //We want the existing file on the top
+
+ return 0;
+ }
+
HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
const CObjectVector<NArchive::NTar::CItemEx> &inputItems,
! const CObjectVector<CUpdateItem> &updateItemsUnsorted,
IArchiveUpdateCallback *updateCallback)
{
COutArchive outArchive;
outArchive.Create(outStream);
+
+ //Sort the update items to make sure that the existing files
+ //are handled first. This preserves the ordering of pax headers.
+ CObjectVector<CUpdateItem> updateItems(updateItemsUnsorted);
+ updateItems.Sort(CompareTarUpdateItems, (void*)NULL);
UInt64 complexity = 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment