aboutsummaryrefslogtreecommitdiff
path: root/CPP/7zip/Archive/Tar
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CPP/7zip/Archive/Tar/StdAfx.h7
-rw-r--r--CPP/7zip/Archive/Tar/TarHandler.cpp97
-rw-r--r--CPP/7zip/Archive/Tar/TarHandler.h34
-rw-r--r--CPP/7zip/Archive/Tar/TarHandlerOut.cpp38
-rw-r--r--CPP/7zip/Archive/Tar/TarHeader.cpp2
-rw-r--r--CPP/7zip/Archive/Tar/TarHeader.h6
-rw-r--r--CPP/7zip/Archive/Tar/TarIn.cpp94
-rw-r--r--CPP/7zip/Archive/Tar/TarIn.h4
-rw-r--r--CPP/7zip/Archive/Tar/TarItem.h12
-rw-r--r--CPP/7zip/Archive/Tar/TarOut.cpp48
-rw-r--r--CPP/7zip/Archive/Tar/TarOut.h4
-rw-r--r--CPP/7zip/Archive/Tar/TarRegister.cpp2
-rw-r--r--CPP/7zip/Archive/Tar/TarUpdate.cpp92
-rw-r--r--CPP/7zip/Archive/Tar/TarUpdate.h4
14 files changed, 223 insertions, 221 deletions
diff --git a/CPP/7zip/Archive/Tar/StdAfx.h b/CPP/7zip/Archive/Tar/StdAfx.h
index 2854ff3..035267c 100644
--- a/CPP/7zip/Archive/Tar/StdAfx.h
+++ b/CPP/7zip/Archive/Tar/StdAfx.h
@@ -1,8 +1,11 @@
1// StdAfx.h 1// StdAfx.h
2 2
3#ifndef __STDAFX_H 3#ifndef ZIP7_INC_STDAFX_H
4#define __STDAFX_H 4#define ZIP7_INC_STDAFX_H
5 5
6#if defined(_MSC_VER) && _MSC_VER >= 1800
7#pragma warning(disable : 4464) // relative include path contains '..'
8#endif
6#include "../../../Common/Common.h" 9#include "../../../Common/Common.h"
7 10
8#endif 11#endif
diff --git a/CPP/7zip/Archive/Tar/TarHandler.cpp b/CPP/7zip/Archive/Tar/TarHandler.cpp
index bd04bd7..d7fe175 100644
--- a/CPP/7zip/Archive/Tar/TarHandler.cpp
+++ b/CPP/7zip/Archive/Tar/TarHandler.cpp
@@ -67,7 +67,7 @@ static const char *k_Characts_Prefix = "PREFIX";
67IMP_IInArchive_Props 67IMP_IInArchive_Props
68IMP_IInArchive_ArcProps 68IMP_IInArchive_ArcProps
69 69
70STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) 70Z7_COM7F_IMF(CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value))
71{ 71{
72 NCOM::CPropVariant prop; 72 NCOM::CPropVariant prop;
73 switch (propID) 73 switch (propID)
@@ -83,9 +83,9 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
83 { 83 {
84 case k_ErrorType_UnexpectedEnd: flags = kpv_ErrorFlags_UnexpectedEnd; break; 84 case k_ErrorType_UnexpectedEnd: flags = kpv_ErrorFlags_UnexpectedEnd; break;
85 case k_ErrorType_Corrupted: flags = kpv_ErrorFlags_HeadersError; break; 85 case k_ErrorType_Corrupted: flags = kpv_ErrorFlags_HeadersError; break;
86 // case k_ErrorType_OK: break; 86 case k_ErrorType_OK: break;
87 // case k_ErrorType_Warning: break; 87 // case k_ErrorType_Warning: break;
88 default: break; 88 // default: break;
89 } 89 }
90 if (flags != 0) 90 if (flags != 0)
91 prop = flags; 91 prop = flags;
@@ -206,10 +206,9 @@ AString CEncodingCharacts::GetCharactsString() const
206 206
207HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback) 207HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
208{ 208{
209 UInt64 endPos = 0; 209 UInt64 endPos;
210 { 210 {
211 RINOK(stream->Seek(0, STREAM_SEEK_END, &endPos)); 211 RINOK(InStream_AtBegin_GetSize(stream, endPos))
212 RINOK(stream->Seek(0, STREAM_SEEK_SET, NULL));
213 } 212 }
214 213
215 _arc._phySize_Defined = true; 214 _arc._phySize_Defined = true;
@@ -224,7 +223,7 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
224 for (;;) 223 for (;;)
225 { 224 {
226 _arc.NumFiles = _items.Size(); 225 _arc.NumFiles = _items.Size();
227 RINOK(_arc.ReadItem(item)); 226 RINOK(_arc.ReadItem(item))
228 if (!_arc.filled) 227 if (!_arc.filled)
229 break; 228 break;
230 229
@@ -245,7 +244,7 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
245 244
246 _items.Add(item); 245 _items.Add(item);
247 246
248 RINOK(stream->Seek((Int64)item.Get_PackSize_Aligned(), STREAM_SEEK_CUR, &_arc._phySize)); 247 RINOK(stream->Seek((Int64)item.Get_PackSize_Aligned(), STREAM_SEEK_CUR, &_arc._phySize))
249 if (_arc._phySize > endPos) 248 if (_arc._phySize > endPos)
250 { 249 {
251 _arc._error = k_ErrorType_UnexpectedEnd; 250 _arc._error = k_ErrorType_UnexpectedEnd;
@@ -290,10 +289,11 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
290 _isArc = false; 289 _isArc = false;
291 return S_FALSE; 290 return S_FALSE;
292 } 291 }
293 CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;
294 if (!callback) 292 if (!callback)
295 return S_FALSE; 293 return S_FALSE;
296 callback->QueryInterface(IID_IArchiveOpenVolumeCallback, (void **)&openVolumeCallback); 294 Z7_DECL_CMyComPtr_QI_FROM(
295 IArchiveOpenVolumeCallback,
296 openVolumeCallback, callback)
297 if (!openVolumeCallback) 297 if (!openVolumeCallback)
298 return S_FALSE; 298 return S_FALSE;
299 NCOM::CPropVariant prop; 299 NCOM::CPropVariant prop;
@@ -310,20 +310,20 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
310 return S_OK; 310 return S_OK;
311} 311}
312 312
313STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallback *openArchiveCallback) 313Z7_COM7F_IMF(CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallback *openArchiveCallback))
314{ 314{
315 COM_TRY_BEGIN 315 COM_TRY_BEGIN
316 // for (int i = 0; i < 10; i++) // for debug 316 // for (int i = 0; i < 10; i++) // for debug
317 { 317 {
318 Close(); 318 Close();
319 RINOK(Open2(stream, openArchiveCallback)); 319 RINOK(Open2(stream, openArchiveCallback))
320 _stream = stream; 320 _stream = stream;
321 } 321 }
322 return S_OK; 322 return S_OK;
323 COM_TRY_END 323 COM_TRY_END
324} 324}
325 325
326STDMETHODIMP CHandler::OpenSeq(ISequentialInStream *stream) 326Z7_COM7F_IMF(CHandler::OpenSeq(ISequentialInStream *stream))
327{ 327{
328 Close(); 328 Close();
329 _seqStream = stream; 329 _seqStream = stream;
@@ -331,7 +331,7 @@ STDMETHODIMP CHandler::OpenSeq(ISequentialInStream *stream)
331 return S_OK; 331 return S_OK;
332} 332}
333 333
334STDMETHODIMP CHandler::Close() 334Z7_COM7F_IMF(CHandler::Close())
335{ 335{
336 _isArc = false; 336 _isArc = false;
337 337
@@ -346,7 +346,7 @@ STDMETHODIMP CHandler::Close()
346 return S_OK; 346 return S_OK;
347} 347}
348 348
349STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems) 349Z7_COM7F_IMF(CHandler::GetNumberOfItems(UInt32 *numItems))
350{ 350{
351 *numItems = (_stream ? _items.Size() : (UInt32)(Int32)-1); 351 *numItems = (_stream ? _items.Size() : (UInt32)(Int32)-1);
352 return S_OK; 352 return S_OK;
@@ -367,7 +367,7 @@ HRESULT CHandler::SkipTo(UInt32 index)
367 if (_latestIsRead) 367 if (_latestIsRead)
368 { 368 {
369 const UInt64 packSize = _latestItem.Get_PackSize_Aligned(); 369 const UInt64 packSize = _latestItem.Get_PackSize_Aligned();
370 RINOK(copyCoderSpec->Code(_seqStream, NULL, &packSize, &packSize, NULL)); 370 RINOK(copyCoder->Code(_seqStream, NULL, &packSize, &packSize, NULL))
371 _arc._phySize += copyCoderSpec->TotalSize; 371 _arc._phySize += copyCoderSpec->TotalSize;
372 if (copyCoderSpec->TotalSize != packSize) 372 if (copyCoderSpec->TotalSize != packSize)
373 { 373 {
@@ -381,7 +381,7 @@ HRESULT CHandler::SkipTo(UInt32 index)
381 { 381 {
382 _arc.SeqStream = _seqStream; 382 _arc.SeqStream = _seqStream;
383 _arc.InStream = NULL; 383 _arc.InStream = NULL;
384 RINOK(_arc.ReadItem(_latestItem)); 384 RINOK(_arc.ReadItem(_latestItem))
385 if (!_arc.filled) 385 if (!_arc.filled)
386 { 386 {
387 _arc._phySize_Defined = true; 387 _arc._phySize_Defined = true;
@@ -407,6 +407,7 @@ void CHandler::TarStringToUnicode(const AString &s, NWindows::NCOM::CPropVariant
407} 407}
408 408
409 409
410// CPaxTime is defined (NumDigits >= 0)
410static void PaxTimeToProp(const CPaxTime &pt, NWindows::NCOM::CPropVariant &prop) 411static void PaxTimeToProp(const CPaxTime &pt, NWindows::NCOM::CPropVariant &prop)
411{ 412{
412 UInt64 v; 413 UInt64 v;
@@ -418,7 +419,7 @@ static void PaxTimeToProp(const CPaxTime &pt, NWindows::NCOM::CPropVariant &prop
418 ft.dwLowDateTime = (DWORD)v; 419 ft.dwLowDateTime = (DWORD)v;
419 ft.dwHighDateTime = (DWORD)(v >> 32); 420 ft.dwHighDateTime = (DWORD)(v >> 32);
420 prop.SetAsTimeFrom_FT_Prec_Ns100(ft, 421 prop.SetAsTimeFrom_FT_Prec_Ns100(ft,
421 k_PropVar_TimePrec_Base + pt.NumDigits, pt.Ns % 100); 422 k_PropVar_TimePrec_Base + (unsigned)pt.NumDigits, pt.Ns % 100);
422} 423}
423 424
424 425
@@ -469,7 +470,7 @@ static void AddSpecBools(AString &s, const char *name, bool b1, bool b2)
469} 470}
470 471
471 472
472STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value) 473Z7_COM7F_IMF(CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value))
473{ 474{
474 COM_TRY_BEGIN 475 COM_TRY_BEGIN
475 NCOM::CPropVariant prop; 476 NCOM::CPropVariant prop;
@@ -483,7 +484,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
483 return E_INVALIDARG; 484 return E_INVALIDARG;
484 else 485 else
485 { 486 {
486 RINOK(SkipTo(index)); 487 RINOK(SkipTo(index))
487 item = &_latestItem; 488 item = &_latestItem;
488 } 489 }
489 } 490 }
@@ -665,8 +666,8 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
665} 666}
666 667
667 668
668HRESULT CHandler::Extract(const UInt32 *indices, UInt32 numItems, 669Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
669 Int32 testMode, IArchiveExtractCallback *extractCallback) 670 Int32 testMode, IArchiveExtractCallback *extractCallback))
670{ 671{
671 COM_TRY_BEGIN 672 COM_TRY_BEGIN
672 ISequentialInStream *stream = _seqStream; 673 ISequentialInStream *stream = _seqStream;
@@ -703,7 +704,7 @@ HRESULT CHandler::Extract(const UInt32 *indices, UInt32 numItems,
703 { 704 {
704 lps->InSize = totalPackSize; 705 lps->InSize = totalPackSize;
705 lps->OutSize = totalSize; 706 lps->OutSize = totalSize;
706 RINOK(lps->SetCur()); 707 RINOK(lps->SetCur())
707 CMyComPtr<ISequentialOutStream> realOutStream; 708 CMyComPtr<ISequentialOutStream> realOutStream;
708 Int32 askMode = testMode ? 709 Int32 askMode = testMode ?
709 NExtract::NAskMode::kTest : 710 NExtract::NAskMode::kTest :
@@ -715,20 +716,20 @@ HRESULT CHandler::Extract(const UInt32 *indices, UInt32 numItems,
715 HRESULT res = SkipTo(index); 716 HRESULT res = SkipTo(index);
716 if (res == E_INVALIDARG) 717 if (res == E_INVALIDARG)
717 break; 718 break;
718 RINOK(res); 719 RINOK(res)
719 item = &_latestItem; 720 item = &_latestItem;
720 } 721 }
721 else 722 else
722 item = &_items[index]; 723 item = &_items[index];
723 724
724 RINOK(extractCallback->GetStream(index, &realOutStream, askMode)); 725 RINOK(extractCallback->GetStream(index, &realOutStream, askMode))
725 const UInt64 unpackSize = item->Get_UnpackSize(); 726 const UInt64 unpackSize = item->Get_UnpackSize();
726 totalSize += unpackSize; 727 totalSize += unpackSize;
727 totalPackSize += item->Get_PackSize_Aligned(); 728 totalPackSize += item->Get_PackSize_Aligned();
728 if (item->IsDir()) 729 if (item->IsDir())
729 { 730 {
730 RINOK(extractCallback->PrepareOperation(askMode)); 731 RINOK(extractCallback->PrepareOperation(askMode))
731 RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK)); 732 RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK))
732 continue; 733 continue;
733 } 734 }
734 bool skipMode = false; 735 bool skipMode = false;
@@ -741,8 +742,8 @@ HRESULT CHandler::Extract(const UInt32 *indices, UInt32 numItems,
741 if (item->IsHardLink() || 742 if (item->IsHardLink() ||
742 item->IsSymLink()) 743 item->IsSymLink())
743 { 744 {
744 RINOK(extractCallback->PrepareOperation(askMode)); 745 RINOK(extractCallback->PrepareOperation(askMode))
745 RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK)); 746 RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK))
746 } 747 }
747 */ 748 */
748 continue; 749 continue;
@@ -750,7 +751,7 @@ HRESULT CHandler::Extract(const UInt32 *indices, UInt32 numItems,
750 skipMode = true; 751 skipMode = true;
751 askMode = NExtract::NAskMode::kSkip; 752 askMode = NExtract::NAskMode::kSkip;
752 } 753 }
753 RINOK(extractCallback->PrepareOperation(askMode)); 754 RINOK(extractCallback->PrepareOperation(askMode))
754 755
755 outStreamSpec->SetStream(realOutStream); 756 outStreamSpec->SetStream(realOutStream);
756 realOutStream.Release(); 757 realOutStream.Release();
@@ -770,16 +771,16 @@ HRESULT CHandler::Extract(const UInt32 *indices, UInt32 numItems,
770 { 771 {
771 if (item->Is_SymLink()) 772 if (item->Is_SymLink())
772 { 773 {
773 RINOK(WriteStream(outStreamSpec, (const char *)item->LinkName, item->LinkName.Len())); 774 RINOK(WriteStream(outStreamSpec, (const char *)item->LinkName, item->LinkName.Len()))
774 } 775 }
775 else 776 else
776 { 777 {
777 if (!seqMode) 778 if (!seqMode)
778 { 779 {
779 RINOK(_stream->Seek((Int64)item->Get_DataPos(), STREAM_SEEK_SET, NULL)); 780 RINOK(InStream_SeekSet(_stream, item->Get_DataPos()))
780 } 781 }
781 streamSpec->Init(item->Get_PackSize_Aligned()); 782 streamSpec->Init(item->Get_PackSize_Aligned());
782 RINOK(copyCoder->Code(inStream2, outStream, NULL, NULL, progress)); 783 RINOK(copyCoder->Code(inStream2, outStream, NULL, NULL, progress))
783 } 784 }
784 if (outStreamSpec->GetRem() != 0) 785 if (outStreamSpec->GetRem() != 0)
785 opRes = NExtract::NOperationResult::kDataError; 786 opRes = NExtract::NOperationResult::kDataError;
@@ -790,16 +791,16 @@ HRESULT CHandler::Extract(const UInt32 *indices, UInt32 numItems,
790 _curIndex++; 791 _curIndex++;
791 } 792 }
792 outStreamSpec->ReleaseStream(); 793 outStreamSpec->ReleaseStream();
793 RINOK(extractCallback->SetOperationResult(opRes)); 794 RINOK(extractCallback->SetOperationResult(opRes))
794 } 795 }
795 return S_OK; 796 return S_OK;
796 COM_TRY_END 797 COM_TRY_END
797} 798}
798 799
799class CSparseStream: 800
800 public IInStream, 801Z7_CLASS_IMP_IInStream(
801 public CMyUnknownImp 802 CSparseStream
802{ 803)
803 UInt64 _phyPos; 804 UInt64 _phyPos;
804 UInt64 _virtPos; 805 UInt64 _virtPos;
805 bool _needStartSeek; 806 bool _needStartSeek;
@@ -810,10 +811,6 @@ public:
810 unsigned ItemIndex; 811 unsigned ItemIndex;
811 CRecordVector<UInt64> PhyOffsets; 812 CRecordVector<UInt64> PhyOffsets;
812 813
813 MY_UNKNOWN_IMP2(ISequentialInStream, IInStream)
814 STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
815 STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
816
817 void Init() 814 void Init()
818 { 815 {
819 _virtPos = 0; 816 _virtPos = 0;
@@ -823,7 +820,7 @@ public:
823}; 820};
824 821
825 822
826STDMETHODIMP CSparseStream::Read(void *data, UInt32 size, UInt32 *processedSize) 823Z7_COM7F_IMF(CSparseStream::Read(void *data, UInt32 size, UInt32 *processedSize))
827{ 824{
828 if (processedSize) 825 if (processedSize)
829 *processedSize = 0; 826 *processedSize = 0;
@@ -867,7 +864,7 @@ STDMETHODIMP CSparseStream::Read(void *data, UInt32 size, UInt32 *processedSize)
867 UInt64 phyPos = PhyOffsets[left] + relat; 864 UInt64 phyPos = PhyOffsets[left] + relat;
868 if (_needStartSeek || _phyPos != phyPos) 865 if (_needStartSeek || _phyPos != phyPos)
869 { 866 {
870 RINOK(Handler->_stream->Seek((Int64)(item.Get_DataPos() + phyPos), STREAM_SEEK_SET, NULL)); 867 RINOK(InStream_SeekSet(Handler->_stream, (item.Get_DataPos() + phyPos)))
871 _needStartSeek = false; 868 _needStartSeek = false;
872 _phyPos = phyPos; 869 _phyPos = phyPos;
873 } 870 }
@@ -894,7 +891,7 @@ STDMETHODIMP CSparseStream::Read(void *data, UInt32 size, UInt32 *processedSize)
894 return res; 891 return res;
895} 892}
896 893
897STDMETHODIMP CSparseStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) 894Z7_COM7F_IMF(CSparseStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition))
898{ 895{
899 switch (seekOrigin) 896 switch (seekOrigin)
900 { 897 {
@@ -911,7 +908,7 @@ STDMETHODIMP CSparseStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPos
911 return S_OK; 908 return S_OK;
912} 909}
913 910
914STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream) 911Z7_COM7F_IMF(CHandler::GetStream(UInt32 index, ISequentialInStream **stream))
915{ 912{
916 COM_TRY_BEGIN 913 COM_TRY_BEGIN
917 914
@@ -961,7 +958,7 @@ void CHandler::Init()
961} 958}
962 959
963 960
964STDMETHODIMP CHandler::SetProperties(const wchar_t * const *names, const PROPVARIANT *values, UInt32 numProps) 961Z7_COM7F_IMF(CHandler::SetProperties(const wchar_t * const *names, const PROPVARIANT *values, UInt32 numProps))
965{ 962{
966 Init(); 963 Init();
967 964
@@ -978,12 +975,12 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t * const *names, const PROPVAR
978 { 975 {
979 // some clients write 'x' property. So we support it 976 // some clients write 'x' property. So we support it
980 UInt32 level = 0; 977 UInt32 level = 0;
981 RINOK(ParsePropToUInt32(name.Ptr(1), prop, level)); 978 RINOK(ParsePropToUInt32(name.Ptr(1), prop, level))
982 } 979 }
983 else if (name.IsEqualTo("cp")) 980 else if (name.IsEqualTo("cp"))
984 { 981 {
985 UInt32 cp = CP_OEMCP; 982 UInt32 cp = CP_OEMCP;
986 RINOK(ParsePropToUInt32(L"", prop, cp)); 983 RINOK(ParsePropToUInt32(L"", prop, cp))
987 _forceCodePage = true; 984 _forceCodePage = true;
988 _curCodePage = _specifiedCodePage = cp; 985 _curCodePage = _specifiedCodePage = cp;
989 } 986 }
@@ -1036,7 +1033,7 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t * const *names, const PROPVAR
1036 } 1033 }
1037 */ 1034 */
1038 bool processed = false; 1035 bool processed = false;
1039 RINOK(_handlerTimeOptions.Parse(name, prop, processed)); 1036 RINOK(_handlerTimeOptions.Parse(name, prop, processed))
1040 if (processed) 1037 if (processed)
1041 continue; 1038 continue;
1042 return E_INVALIDARG; 1039 return E_INVALIDARG;
diff --git a/CPP/7zip/Archive/Tar/TarHandler.h b/CPP/7zip/Archive/Tar/TarHandler.h
index 44a9980..451c2fd 100644
--- a/CPP/7zip/Archive/Tar/TarHandler.h
+++ b/CPP/7zip/Archive/Tar/TarHandler.h
@@ -1,12 +1,10 @@
1// TarHandler.h 1// TarHandler.h
2 2
3#ifndef __TAR_HANDLER_H 3#ifndef ZIP7_INC_TAR_HANDLER_H
4#define __TAR_HANDLER_H 4#define ZIP7_INC_TAR_HANDLER_H
5 5
6#include "../../../Common/MyCom.h" 6#include "../../../Common/MyCom.h"
7 7
8#include "../../../Windows/PropVariant.h"
9
10#include "../../Compress/CopyCoder.h" 8#include "../../Compress/CopyCoder.h"
11 9
12#include "../Common/HandlerOut.h" 10#include "../Common/HandlerOut.h"
@@ -16,14 +14,12 @@
16namespace NArchive { 14namespace NArchive {
17namespace NTar { 15namespace NTar {
18 16
19class CHandler: 17Z7_CLASS_IMP_CHandler_IInArchive_4(
20 public IInArchive, 18 IArchiveOpenSeq
21 public IArchiveOpenSeq, 19 , IInArchiveGetStream
22 public IInArchiveGetStream, 20 , ISetProperties
23 public ISetProperties, 21 , IOutArchive
24 public IOutArchive, 22)
25 public CMyUnknownImp
26{
27public: 23public:
28 CObjectVector<CItemEx> _items; 24 CObjectVector<CItemEx> _items;
29 CMyComPtr<IInStream> _stream; 25 CMyComPtr<IInStream> _stream;
@@ -53,20 +49,6 @@ private:
53 HRESULT SkipTo(UInt32 index); 49 HRESULT SkipTo(UInt32 index);
54 void TarStringToUnicode(const AString &s, NWindows::NCOM::CPropVariant &prop, bool toOs = false) const; 50 void TarStringToUnicode(const AString &s, NWindows::NCOM::CPropVariant &prop, bool toOs = false) const;
55public: 51public:
56 MY_UNKNOWN_IMP5(
57 IInArchive,
58 IArchiveOpenSeq,
59 IInArchiveGetStream,
60 ISetProperties,
61 IOutArchive
62 )
63
64 INTERFACE_IInArchive(;)
65 INTERFACE_IOutArchive(;)
66 STDMETHOD(OpenSeq)(ISequentialInStream *stream);
67 STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
68 STDMETHOD(SetProperties)(const wchar_t * const *names, const PROPVARIANT *values, UInt32 numProps);
69
70 void Init(); 52 void Init();
71 CHandler(); 53 CHandler();
72}; 54};
diff --git a/CPP/7zip/Archive/Tar/TarHandlerOut.cpp b/CPP/7zip/Archive/Tar/TarHandlerOut.cpp
index 53255e4..c93a86e 100644
--- a/CPP/7zip/Archive/Tar/TarHandlerOut.cpp
+++ b/CPP/7zip/Archive/Tar/TarHandlerOut.cpp
@@ -20,7 +20,7 @@ using namespace NWindows;
20namespace NArchive { 20namespace NArchive {
21namespace NTar { 21namespace NTar {
22 22
23STDMETHODIMP CHandler::GetFileTimeType(UInt32 *type) 23Z7_COM7F_IMF(CHandler::GetFileTimeType(UInt32 *type))
24{ 24{
25 UInt32 t = NFileTimeType::kUnix; 25 UInt32 t = NFileTimeType::kUnix;
26 const UInt32 prec = _handlerTimeOptions.Prec; 26 const UInt32 prec = _handlerTimeOptions.Prec;
@@ -55,7 +55,7 @@ HRESULT GetPropString(IArchiveUpdateCallback *callback, UInt32 index, PROPID pro
55 UINT codePage, unsigned utfFlags, bool convertSlash) 55 UINT codePage, unsigned utfFlags, bool convertSlash)
56{ 56{
57 NCOM::CPropVariant prop; 57 NCOM::CPropVariant prop;
58 RINOK(callback->GetProperty(index, propId, &prop)); 58 RINOK(callback->GetProperty(index, propId, &prop))
59 59
60 if (prop.vt == VT_BSTR) 60 if (prop.vt == VT_BSTR)
61 { 61 {
@@ -94,7 +94,7 @@ static HRESULT GetTime(UInt32 i, UInt32 pid, IArchiveUpdateCallback *callback,
94{ 94{
95 pt.Clear(); 95 pt.Clear();
96 NCOM::CPropVariant prop; 96 NCOM::CPropVariant prop;
97 RINOK(callback->GetProperty(i, pid, &prop)); 97 RINOK(callback->GetProperty(i, pid, &prop))
98 return Prop_To_PaxTime(prop, pt); 98 return Prop_To_PaxTime(prop, pt);
99} 99}
100 100
@@ -125,7 +125,7 @@ static HRESULT GetDevice(IArchiveUpdateCallback *callback, UInt32 i,
125{ 125{
126 defined = false; 126 defined = false;
127 NWindows::NCOM::CPropVariant prop; 127 NWindows::NCOM::CPropVariant prop;
128 RINOK(callback->GetProperty(i, pid, &prop)); 128 RINOK(callback->GetProperty(i, pid, &prop))
129 if (prop.vt == VT_EMPTY) 129 if (prop.vt == VT_EMPTY)
130 return S_OK; 130 return S_OK;
131 if (prop.vt == VT_UI4) 131 if (prop.vt == VT_UI4)
@@ -147,7 +147,7 @@ static HRESULT GetUser(IArchiveUpdateCallback *callback, UInt32 i,
147 bool isSet = false; 147 bool isSet = false;
148 { 148 {
149 NWindows::NCOM::CPropVariant prop; 149 NWindows::NCOM::CPropVariant prop;
150 RINOK(callback->GetProperty(i, pidId, &prop)); 150 RINOK(callback->GetProperty(i, pidId, &prop))
151 if (prop.vt == VT_UI4) 151 if (prop.vt == VT_UI4)
152 { 152 {
153 isSet = true; 153 isSet = true;
@@ -160,7 +160,7 @@ static HRESULT GetUser(IArchiveUpdateCallback *callback, UInt32 i,
160 } 160 }
161 { 161 {
162 NWindows::NCOM::CPropVariant prop; 162 NWindows::NCOM::CPropVariant prop;
163 RINOK(callback->GetProperty(i, pidName, &prop)); 163 RINOK(callback->GetProperty(i, pidName, &prop))
164 if (prop.vt == VT_BSTR) 164 if (prop.vt == VT_BSTR)
165 { 165 {
166 const UString s = prop.bstrVal; 166 const UString s = prop.bstrVal;
@@ -181,8 +181,8 @@ static HRESULT GetUser(IArchiveUpdateCallback *callback, UInt32 i,
181 181
182 182
183 183
184STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems, 184Z7_COM7F_IMF(CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,
185 IArchiveUpdateCallback *callback) 185 IArchiveUpdateCallback *callback))
186{ 186{
187 COM_TRY_BEGIN 187 COM_TRY_BEGIN
188 188
@@ -196,8 +196,8 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
196 /* 196 /*
197 // for debug only: 197 // for debug only:
198 unsigned utfFlags = 0; 198 unsigned utfFlags = 0;
199 utfFlags |= UTF_FLAG__TO_UTF8__EXTRACT_BMP_ESCAPE; 199 utfFlags |= Z7_UTF_FLAG_TO_UTF8_EXTRACT_BMP_ESCAPE;
200 utfFlags |= UTF_FLAG__TO_UTF8__SURROGATE_ERROR; 200 utfFlags |= Z7_UTF_FLAG_TO_UTF8_SURROGATE_ERROR;
201 */ 201 */
202 202
203 for (UInt32 i = 0; i < numItems; i++) 203 for (UInt32 i = 0; i < numItems; i++)
@@ -210,7 +210,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
210 if (!callback) 210 if (!callback)
211 return E_FAIL; 211 return E_FAIL;
212 212
213 RINOK(callback->GetUpdateItemInfo(i, &newData, &newProps, &indexInArc)); 213 RINOK(callback->GetUpdateItemInfo(i, &newData, &newProps, &indexInArc))
214 214
215 ui.NewProps = IntToBool(newProps); 215 ui.NewProps = IntToBool(newProps);
216 ui.NewData = IntToBool(newData); 216 ui.NewData = IntToBool(newData);
@@ -221,7 +221,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
221 { 221 {
222 { 222 {
223 NCOM::CPropVariant prop; 223 NCOM::CPropVariant prop;
224 RINOK(callback->GetProperty(i, kpidIsDir, &prop)); 224 RINOK(callback->GetProperty(i, kpidIsDir, &prop))
225 if (prop.vt == VT_EMPTY) 225 if (prop.vt == VT_EMPTY)
226 ui.IsDir = false; 226 ui.IsDir = false;
227 else if (prop.vt != VT_BOOL) 227 else if (prop.vt != VT_BOOL)
@@ -232,7 +232,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
232 232
233 { 233 {
234 NCOM::CPropVariant prop; 234 NCOM::CPropVariant prop;
235 RINOK(callback->GetProperty(i, kpidPosixAttrib, &prop)); 235 RINOK(callback->GetProperty(i, kpidPosixAttrib, &prop))
236 if (prop.vt == VT_EMPTY) 236 if (prop.vt == VT_EMPTY)
237 ui.Mode = 237 ui.Mode =
238 MY_LIN_S_IRWXO 238 MY_LIN_S_IRWXO
@@ -255,25 +255,25 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
255 if (_handlerTimeOptions.Write_CTime.Val) 255 if (_handlerTimeOptions.Write_CTime.Val)
256 RINOK(GetTime(i, kpidCTime, callback, ui.PaxTimes.CTime)) 256 RINOK(GetTime(i, kpidCTime, callback, ui.PaxTimes.CTime))
257 257
258 RINOK(GetPropString(callback, i, kpidPath, ui.Name, codePage, utfFlags, true)); 258 RINOK(GetPropString(callback, i, kpidPath, ui.Name, codePage, utfFlags, true))
259 if (ui.IsDir && !ui.Name.IsEmpty() && ui.Name.Back() != '/') 259 if (ui.IsDir && !ui.Name.IsEmpty() && ui.Name.Back() != '/')
260 ui.Name += '/'; 260 ui.Name += '/';
261 // ui.Name += '/'; // for debug 261 // ui.Name += '/'; // for debug
262 262
263 if (_posixMode) 263 if (_posixMode)
264 { 264 {
265 RINOK(GetDevice(callback, i, kpidDeviceMajor, ui.DeviceMajor, ui.DeviceMajor_Defined)); 265 RINOK(GetDevice(callback, i, kpidDeviceMajor, ui.DeviceMajor, ui.DeviceMajor_Defined))
266 RINOK(GetDevice(callback, i, kpidDeviceMinor, ui.DeviceMinor, ui.DeviceMinor_Defined)); 266 RINOK(GetDevice(callback, i, kpidDeviceMinor, ui.DeviceMinor, ui.DeviceMinor_Defined))
267 } 267 }
268 268
269 RINOK(GetUser(callback, i, kpidUser, kpidUserId, ui.User, ui.UID, codePage, utfFlags)); 269 RINOK(GetUser(callback, i, kpidUser, kpidUserId, ui.User, ui.UID, codePage, utfFlags))
270 RINOK(GetUser(callback, i, kpidGroup, kpidGroupId, ui.Group, ui.GID, codePage, utfFlags)); 270 RINOK(GetUser(callback, i, kpidGroup, kpidGroupId, ui.Group, ui.GID, codePage, utfFlags))
271 } 271 }
272 272
273 if (IntToBool(newData)) 273 if (IntToBool(newData))
274 { 274 {
275 NCOM::CPropVariant prop; 275 NCOM::CPropVariant prop;
276 RINOK(callback->GetProperty(i, kpidSize, &prop)); 276 RINOK(callback->GetProperty(i, kpidSize, &prop))
277 if (prop.vt != VT_UI8) 277 if (prop.vt != VT_UI8)
278 return E_INVALIDARG; 278 return E_INVALIDARG;
279 ui.Size = prop.uhVal.QuadPart; 279 ui.Size = prop.uhVal.QuadPart;
diff --git a/CPP/7zip/Archive/Tar/TarHeader.cpp b/CPP/7zip/Archive/Tar/TarHeader.cpp
index f1efddb..deae357 100644
--- a/CPP/7zip/Archive/Tar/TarHeader.cpp
+++ b/CPP/7zip/Archive/Tar/TarHeader.cpp
@@ -20,7 +20,7 @@ namespace NFileHeader {
20 // 7-Zip used kUsTar_00 before 21.07: 20 // 7-Zip used kUsTar_00 before 21.07:
21 const char k_Posix_ustar_00[8] = { 'u', 's', 't', 'a', 'r', 0, '0', '0' } ; 21 const char k_Posix_ustar_00[8] = { 'u', 's', 't', 'a', 'r', 0, '0', '0' } ;
22 // GNU TAR uses such header: 22 // GNU TAR uses such header:
23 const char k_GNU_ustar__[8] = { 'u', 's', 't', 'a', 'r', ' ', ' ', 0 } ; 23 const char k_GNU_ustar[8] = { 'u', 's', 't', 'a', 'r', ' ', ' ', 0 } ;
24 } 24 }
25 25
26/* 26/*
diff --git a/CPP/7zip/Archive/Tar/TarHeader.h b/CPP/7zip/Archive/Tar/TarHeader.h
index 1af3093..aeccd28 100644
--- a/CPP/7zip/Archive/Tar/TarHeader.h
+++ b/CPP/7zip/Archive/Tar/TarHeader.h
@@ -1,7 +1,7 @@
1// Archive/TarHeader.h 1// Archive/TarHeader.h
2 2
3#ifndef __ARCHIVE_TAR_HEADER_H 3#ifndef ZIP7_INC_ARCHIVE_TAR_HEADER_H
4#define __ARCHIVE_TAR_HEADER_H 4#define ZIP7_INC_ARCHIVE_TAR_HEADER_H
5 5
6#include "../../../Common/MyTypes.h" 6#include "../../../Common/MyTypes.h"
7 7
@@ -81,7 +81,7 @@ namespace NFileHeader
81 // extern const char * const kGNUTar; // = "GNUtar "; // 7 chars and a null 81 // extern const char * const kGNUTar; // = "GNUtar "; // 7 chars and a null
82 // extern const char * const kEmpty; // = "\0\0\0\0\0\0\0\0" 82 // extern const char * const kEmpty; // = "\0\0\0\0\0\0\0\0"
83 extern const char k_Posix_ustar_00[8]; 83 extern const char k_Posix_ustar_00[8];
84 extern const char k_GNU_ustar__[8]; 84 extern const char k_GNU_ustar[8];
85 } 85 }
86} 86}
87 87
diff --git a/CPP/7zip/Archive/Tar/TarIn.cpp b/CPP/7zip/Archive/Tar/TarIn.cpp
index 4fd8c5b..90b6f84 100644
--- a/CPP/7zip/Archive/Tar/TarIn.cpp
+++ b/CPP/7zip/Archive/Tar/TarIn.cpp
@@ -14,8 +14,8 @@
14 14
15#define NUM_UNROLL_BYTES (8 * 4) 15#define NUM_UNROLL_BYTES (8 * 4)
16 16
17MY_NO_INLINE static bool IsBufNonZero(const void *data, size_t size); 17Z7_NO_INLINE static bool IsBufNonZero(const void *data, size_t size);
18MY_NO_INLINE static bool IsBufNonZero(const void *data, size_t size) 18Z7_NO_INLINE static bool IsBufNonZero(const void *data, size_t size)
19{ 19{
20 const Byte *p = (const Byte *)data; 20 const Byte *p = (const Byte *)data;
21 21
@@ -159,7 +159,7 @@ API_FUNC_IsArc IsArc_Tar(const Byte *p2, size_t size)
159 159
160 UInt32 mode; 160 UInt32 mode;
161 // we allow empty Mode value for LongName prefix items 161 // we allow empty Mode value for LongName prefix items
162 CHECK(OctalToNumber32(p, mode, true)); p += 8; 162 CHECK(OctalToNumber32(p, mode, true)) p += 8;
163 163
164 // if (!OctalToNumber32(p, item.UID)) item.UID = 0; 164 // if (!OctalToNumber32(p, item.UID)) item.UID = 0;
165 p += 8; 165 p += 8;
@@ -170,9 +170,9 @@ API_FUNC_IsArc IsArc_Tar(const Byte *p2, size_t size)
170 Int64 time; 170 Int64 time;
171 UInt32 checkSum; 171 UInt32 checkSum;
172 bool isBin; 172 bool isBin;
173 CHECK(ParseSize(p, packSize, isBin)); p += 12; 173 CHECK(ParseSize(p, packSize, isBin)) p += 12;
174 CHECK(ParseInt64_MTime(p, time, isBin)); p += 12; 174 CHECK(ParseInt64_MTime(p, time, isBin)) p += 12;
175 CHECK(OctalToNumber32(p, checkSum)); 175 CHECK(OctalToNumber32(p, checkSum))
176 return k_IsArc_Res_YES; 176 return k_IsArc_Res_YES;
177} 177}
178 178
@@ -188,7 +188,7 @@ HRESULT CArchive::GetNextItemReal(CItemEx &item)
188 for (;;) 188 for (;;)
189 { 189 {
190 size_t processedSize = NFileHeader::kRecordSize; 190 size_t processedSize = NFileHeader::kRecordSize;
191 RINOK(ReadStream(SeqStream, buf, &processedSize)); 191 RINOK(ReadStream(SeqStream, buf, &processedSize))
192 if (processedSize == 0) 192 if (processedSize == 0)
193 { 193 {
194 if (!thereAreEmptyRecords) 194 if (!thereAreEmptyRecords)
@@ -220,7 +220,7 @@ HRESULT CArchive::GetNextItemReal(CItemEx &item)
220 thereAreEmptyRecords = true; 220 thereAreEmptyRecords = true;
221 if (OpenCallback) 221 if (OpenCallback)
222 { 222 {
223 RINOK(Progress(item, 0)); 223 RINOK(Progress(item, 0))
224 } 224 }
225 } 225 }
226 if (thereAreEmptyRecords) 226 if (thereAreEmptyRecords)
@@ -243,19 +243,19 @@ HRESULT CArchive::GetNextItemReal(CItemEx &item)
243 */ 243 */
244 244
245 // we allow empty Mode value for LongName prefix items 245 // we allow empty Mode value for LongName prefix items
246 RIF(OctalToNumber32(p, item.Mode, true)); p += 8; 246 RIF(OctalToNumber32(p, item.Mode, true)) p += 8;
247 247
248 if (!OctalToNumber32(p, item.UID)) { item.UID = 0; } p += 8; 248 if (!OctalToNumber32(p, item.UID)) { item.UID = 0; } p += 8;
249 if (!OctalToNumber32(p, item.GID)) { item.GID = 0; } p += 8; 249 if (!OctalToNumber32(p, item.GID)) { item.GID = 0; } p += 8;
250 250
251 RIF(ParseSize(p, item.PackSize, item.PackSize_IsBin)); 251 RIF(ParseSize(p, item.PackSize, item.PackSize_IsBin))
252 item.Size = item.PackSize; 252 item.Size = item.PackSize;
253 item.Size_IsBin = item.PackSize_IsBin; 253 item.Size_IsBin = item.PackSize_IsBin;
254 p += 12; 254 p += 12;
255 RIF(ParseInt64_MTime(p, item.MTime, item.MTime_IsBin)); p += 12; 255 RIF(ParseInt64_MTime(p, item.MTime, item.MTime_IsBin)) p += 12;
256 256
257 UInt32 checkSum; 257 UInt32 checkSum;
258 RIF(OctalToNumber32(p, checkSum)); 258 RIF(OctalToNumber32(p, checkSum))
259 memset(p, ' ', 8); p += 8; 259 memset(p, ' ', 8); p += 8;
260 260
261 item.LinkFlag = *p++; 261 item.LinkFlag = *p++;
@@ -273,8 +273,8 @@ HRESULT CArchive::GetNextItemReal(CItemEx &item)
273 ReadString(p, NFileHeader::kUserNameSize, item.User); p += NFileHeader::kUserNameSize; 273 ReadString(p, NFileHeader::kUserNameSize, item.User); p += NFileHeader::kUserNameSize;
274 ReadString(p, NFileHeader::kGroupNameSize, item.Group); p += NFileHeader::kGroupNameSize; 274 ReadString(p, NFileHeader::kGroupNameSize, item.Group); p += NFileHeader::kGroupNameSize;
275 275
276 item.DeviceMajor_Defined = (p[0] != 0); if (item.DeviceMajor_Defined) { RIF(OctalToNumber32(p, item.DeviceMajor)); } p += 8; 276 item.DeviceMajor_Defined = (p[0] != 0); if (item.DeviceMajor_Defined) { RIF(OctalToNumber32(p, item.DeviceMajor)) } p += 8;
277 item.DeviceMinor_Defined = (p[0] != 0); if (item.DeviceMinor_Defined) { RIF(OctalToNumber32(p, item.DeviceMinor)); } p += 8; 277 item.DeviceMinor_Defined = (p[0] != 0); if (item.DeviceMinor_Defined) { RIF(OctalToNumber32(p, item.DeviceMinor)) } p += 8;
278 278
279 if (p[0] != 0 279 if (p[0] != 0
280 && item.IsMagic_ustar_5chars() 280 && item.IsMagic_ustar_5chars()
@@ -338,7 +338,7 @@ HRESULT CArchive::GetNextItemReal(CItemEx &item)
338 Byte isExtended = (Byte)buf[482]; 338 Byte isExtended = (Byte)buf[482];
339 if (isExtended != 0 && isExtended != 1) 339 if (isExtended != 0 && isExtended != 1)
340 return S_OK; 340 return S_OK;
341 RIF(ParseSize(buf + 483, item.Size, item.Size_IsBin)); 341 RIF(ParseSize(buf + 483, item.Size, item.Size_IsBin))
342 UInt64 min = 0; 342 UInt64 min = 0;
343 for (unsigned i = 0; i < 4; i++) 343 for (unsigned i = 0; i < 4; i++)
344 { 344 {
@@ -350,8 +350,8 @@ HRESULT CArchive::GetNextItemReal(CItemEx &item)
350 break; 350 break;
351 } 351 }
352 CSparseBlock sb; 352 CSparseBlock sb;
353 RIF(ParseSize(p, sb.Offset)); 353 RIF(ParseSize(p, sb.Offset))
354 RIF(ParseSize(p + 12, sb.Size)); 354 RIF(ParseSize(p + 12, sb.Size))
355 item.SparseBlocks.Add(sb); 355 item.SparseBlocks.Add(sb);
356 if (sb.Offset < min || sb.Offset > item.Size) 356 if (sb.Offset < min || sb.Offset > item.Size)
357 return S_OK; 357 return S_OK;
@@ -367,7 +367,7 @@ HRESULT CArchive::GetNextItemReal(CItemEx &item)
367 while (isExtended != 0) 367 while (isExtended != 0)
368 { 368 {
369 size_t processedSize = NFileHeader::kRecordSize; 369 size_t processedSize = NFileHeader::kRecordSize;
370 RINOK(ReadStream(SeqStream, buf, &processedSize)); 370 RINOK(ReadStream(SeqStream, buf, &processedSize))
371 if (processedSize != NFileHeader::kRecordSize) 371 if (processedSize != NFileHeader::kRecordSize)
372 { 372 {
373 error = k_ErrorType_UnexpectedEnd; 373 error = k_ErrorType_UnexpectedEnd;
@@ -378,7 +378,7 @@ HRESULT CArchive::GetNextItemReal(CItemEx &item)
378 378
379 if (OpenCallback) 379 if (OpenCallback)
380 { 380 {
381 RINOK(Progress(item, 0)); 381 RINOK(Progress(item, 0))
382 } 382 }
383 383
384 isExtended = (Byte)buf[21 * 24]; 384 isExtended = (Byte)buf[21 * 24];
@@ -394,8 +394,8 @@ HRESULT CArchive::GetNextItemReal(CItemEx &item)
394 break; 394 break;
395 } 395 }
396 CSparseBlock sb; 396 CSparseBlock sb;
397 RIF(ParseSize(p, sb.Offset)); 397 RIF(ParseSize(p, sb.Offset))
398 RIF(ParseSize(p + 12, sb.Size)); 398 RIF(ParseSize(p + 12, sb.Size))
399 item.SparseBlocks.Add(sb); 399 item.SparseBlocks.Add(sb);
400 if (sb.Offset < min || sb.Offset > item.Size) 400 if (sb.Offset < min || sb.Offset > item.Size)
401 return S_OK; 401 return S_OK;
@@ -459,7 +459,7 @@ HRESULT CArchive::ReadDataToBuffer(const CItemEx &item,
459 error = k_ErrorType_UnexpectedEnd; 459 error = k_ErrorType_UnexpectedEnd;
460 return res; 460 return res;
461 } 461 }
462 RINOK(res); 462 RINOK(res)
463 463
464 packSize -= size; 464 packSize -= size;
465 465
@@ -492,7 +492,7 @@ HRESULT CArchive::ReadDataToBuffer(const CItemEx &item,
492 492
493 if (InStream) 493 if (InStream)
494 { 494 {
495 RINOK(InStream->Seek((Int64)packSize, STREAM_SEEK_CUR, NULL)); 495 RINOK(InStream->Seek((Int64)packSize, STREAM_SEEK_CUR, NULL))
496 return S_OK; 496 return S_OK;
497 } 497 }
498 const unsigned kBufSize = 1 << 15; 498 const unsigned kBufSize = 1 << 15;
@@ -502,7 +502,7 @@ HRESULT CArchive::ReadDataToBuffer(const CItemEx &item,
502 { 502 {
503 if (OpenCallback) 503 if (OpenCallback)
504 { 504 {
505 RINOK(Progress(item, pos)); 505 RINOK(Progress(item, pos))
506 } 506 }
507 507
508 unsigned size = kBufSize; 508 unsigned size = kBufSize;
@@ -590,8 +590,8 @@ static bool ParsePaxTime(const AString &src, CPaxTime &pt, bool &doubleTagError)
590 if (sec >= ((UInt64)1 << 63)) 590 if (sec >= ((UInt64)1 << 63))
591 return false; 591 return false;
592 if (isNegative) 592 if (isNegative)
593 sec = -(Int64)sec; 593 sec = (UInt64)-(Int64)sec;
594 pt.Sec = sec; 594 pt.Sec = (Int64)sec;
595 } 595 }
596 if (*end == 0) 596 if (*end == 0)
597 { 597 {
@@ -617,10 +617,10 @@ static bool ParsePaxTime(const AString &src, CPaxTime &pt, bool &doubleTagError)
617 if (i < kNsDigits) 617 if (i < kNsDigits)
618 { 618 {
619 ns *= 10; 619 ns *= 10;
620 ns += c - '0'; 620 ns += (unsigned)(c - '0');
621 } 621 }
622 } 622 }
623 pt.NumDigits = (i < kNsDigits ? i : kNsDigits); 623 pt.NumDigits = (int)(i < kNsDigits ? i : kNsDigits);
624 while (i < kNsDigits) 624 while (i < kNsDigits)
625 { 625 {
626 ns *= 10; 626 ns *= 10;
@@ -690,7 +690,7 @@ bool CPaxInfo::ParsePax(const CTempBuffer &tb, bool isFile)
690 return false; 690 return false;
691 691
692 name.SetFrom(s + offset, i - offset); 692 name.SetFrom(s + offset, i - offset);
693 val.SetFrom(s + i + 1, size - 1 - (i + 1)); 693 val.SetFrom(s + i + 1, (unsigned)(size - 1 - (i + 1)));
694 694
695 bool parsed = false; 695 bool parsed = false;
696 if (isFile) 696 if (isFile)
@@ -822,29 +822,34 @@ HRESULT CArchive::ReadItem2(CItemEx &item)
822 PaxBuf.Init(); 822 PaxBuf.Init();
823 PaxBuf_global.Init(); 823 PaxBuf_global.Init();
824 824
825 for (unsigned recordIndex = 0;; recordIndex++) 825 UInt64 numExtraRecords = 0;
826
827 for (;;)
826 { 828 {
827 if (OpenCallback) 829 if (OpenCallback)
828 { 830 {
829 RINOK(Progress(item, 0)); 831 RINOK(Progress(item, 0))
830 } 832 }
831 833
832 RINOK(GetNextItemReal(item)); 834 RINOK(GetNextItemReal(item))
833 835
834 // NumRecords++; 836 // NumRecords++;
835 837
836 if (!filled) 838 if (!filled)
837 { 839 {
838 if (error == k_ErrorType_OK) 840 if (error == k_ErrorType_OK)
839 if (item.LongName_WasUsed || 841 if (numExtraRecords != 0
840 item.LongLink_WasUsed || 842 || item.LongName_WasUsed
841 item.Num_Pax_Records != 0) 843 || item.LongLink_WasUsed
844 || item.Num_Pax_Records != 0)
842 error = k_ErrorType_Corrupted; 845 error = k_ErrorType_Corrupted;
846 return S_OK;
843 } 847 }
844
845 if (error != k_ErrorType_OK) 848 if (error != k_ErrorType_OK)
846 return S_OK; 849 return S_OK;
847 850
851 numExtraRecords++;
852
848 const char lf = item.LinkFlag; 853 const char lf = item.LinkFlag;
849 if (lf == NFileHeader::NLinkFlag::kGnu_LongName || 854 if (lf == NFileHeader::NLinkFlag::kGnu_LongName ||
850 lf == NFileHeader::NLinkFlag::kGnu_LongLink) 855 lf == NFileHeader::NLinkFlag::kGnu_LongLink)
@@ -874,7 +879,7 @@ HRESULT CArchive::ReadItem2(CItemEx &item)
874 */ 879 */
875 880
876 const unsigned kLongNameSizeMax = (unsigned)1 << 14; 881 const unsigned kLongNameSizeMax = (unsigned)1 << 14;
877 RINOK(ReadDataToBuffer(item, *tb, kLongNameSizeMax)); 882 RINOK(ReadDataToBuffer(item, *tb, kLongNameSizeMax))
878 if (error != k_ErrorType_OK) 883 if (error != k_ErrorType_OK)
879 return S_OK; 884 return S_OK;
880 885
@@ -921,7 +926,7 @@ HRESULT CArchive::ReadItem2(CItemEx &item)
921 926
922 CTempBuffer *tb = (lf == NFileHeader::NLinkFlag::kGlobal ? &PaxBuf_global : &PaxBuf); 927 CTempBuffer *tb = (lf == NFileHeader::NLinkFlag::kGlobal ? &PaxBuf_global : &PaxBuf);
923 928
924 RINOK(ReadDataToBuffer(item, *tb, kParsingPaxSizeMax)); 929 RINOK(ReadDataToBuffer(item, *tb, kParsingPaxSizeMax))
925 if (error != k_ErrorType_OK) 930 if (error != k_ErrorType_OK)
926 return S_OK; 931 return S_OK;
927 932
@@ -951,12 +956,19 @@ HRESULT CArchive::ReadItem2(CItemEx &item)
951 } 956 }
952 else 957 else
953 _is_PaxGlobal_Error = true; 958 _is_PaxGlobal_Error = true;
954 if (isStartHeader) 959
960 if (isStartHeader
961 && item.Num_Pax_Records == 1
962 && numExtraRecords == 1)
955 { 963 {
956 // we skip global pax header info after parsing 964 // we skip global pax header info after parsing
957 item.HeaderPos += item.HeaderSize; 965 item.HeaderPos += item.HeaderSize;
958 item.HeaderSize = 0; 966 item.HeaderSize = 0;
967 item.Num_Pax_Records = 0;
968 numExtraRecords = 0;
959 } 969 }
970 else
971 _is_PaxGlobal_Error = true;
960 } 972 }
961 continue; 973 continue;
962 } 974 }
@@ -1071,7 +1083,7 @@ HRESULT CArchive::ReadItem(CItemEx &item)
1071 if (error != k_ErrorType_OK) 1083 if (error != k_ErrorType_OK)
1072 _error = error; 1084 _error = error;
1073 1085
1074 RINOK(res); 1086 RINOK(res)
1075 1087
1076 if (filled) 1088 if (filled)
1077 { 1089 {
diff --git a/CPP/7zip/Archive/Tar/TarIn.h b/CPP/7zip/Archive/Tar/TarIn.h
index e99599a..8c69057 100644
--- a/CPP/7zip/Archive/Tar/TarIn.h
+++ b/CPP/7zip/Archive/Tar/TarIn.h
@@ -1,7 +1,7 @@
1// TarIn.h 1// TarIn.h
2 2
3#ifndef __ARCHIVE_TAR_IN_H 3#ifndef ZIP7_INC_ARCHIVE_TAR_IN_H
4#define __ARCHIVE_TAR_IN_H 4#define ZIP7_INC_ARCHIVE_TAR_IN_H
5 5
6#include "../IArchive.h" 6#include "../IArchive.h"
7 7
diff --git a/CPP/7zip/Archive/Tar/TarItem.h b/CPP/7zip/Archive/Tar/TarItem.h
index 738618f..2e12c9d 100644
--- a/CPP/7zip/Archive/Tar/TarItem.h
+++ b/CPP/7zip/Archive/Tar/TarItem.h
@@ -1,7 +1,7 @@
1// TarItem.h 1// TarItem.h
2 2
3#ifndef __ARCHIVE_TAR_ITEM_H 3#ifndef ZIP7_INC_ARCHIVE_TAR_ITEM_H
4#define __ARCHIVE_TAR_ITEM_H 4#define ZIP7_INC_ARCHIVE_TAR_ITEM_H
5 5
6#include "../../../Common/MyLinux.h" 6#include "../../../Common/MyLinux.h"
7#include "../../../Common/UTFConvert.h" 7#include "../../../Common/UTFConvert.h"
@@ -143,7 +143,7 @@ struct CItem
143 { 143 {
144 memcpy(Magic, posixMode ? 144 memcpy(Magic, posixMode ?
145 NFileHeader::NMagic::k_Posix_ustar_00 : 145 NFileHeader::NMagic::k_Posix_ustar_00 :
146 NFileHeader::NMagic::k_GNU_ustar__, 146 NFileHeader::NMagic::k_GNU_ustar,
147 8); 147 8);
148 } 148 }
149 149
@@ -172,7 +172,7 @@ struct CItem
172 172
173 void Set_LinkFlag_for_File(UInt32 mode) 173 void Set_LinkFlag_for_File(UInt32 mode)
174 { 174 {
175 Byte lf = NFileHeader::NLinkFlag::kNormal; 175 char lf = NFileHeader::NLinkFlag::kNormal;
176 if (MY_LIN_S_ISCHR(mode)) lf = NFileHeader::NLinkFlag::kCharacter; 176 if (MY_LIN_S_ISCHR(mode)) lf = NFileHeader::NLinkFlag::kCharacter;
177 else if (MY_LIN_S_ISBLK(mode)) lf = NFileHeader::NLinkFlag::kBlock; 177 else if (MY_LIN_S_ISBLK(mode)) lf = NFileHeader::NLinkFlag::kBlock;
178 else if (MY_LIN_S_ISFIFO(mode)) lf = NFileHeader::NLinkFlag::kFIFO; 178 else if (MY_LIN_S_ISFIFO(mode)) lf = NFileHeader::NLinkFlag::kFIFO;
@@ -225,7 +225,7 @@ struct CItem
225 bool IsMagic_ustar_5chars() const 225 bool IsMagic_ustar_5chars() const
226 { 226 {
227 for (unsigned i = 0; i < 5; i++) 227 for (unsigned i = 0; i < 5; i++)
228 if (Magic[i] != NFileHeader::NMagic::k_GNU_ustar__[i]) 228 if (Magic[i] != NFileHeader::NMagic::k_GNU_ustar[i])
229 return false; 229 return false;
230 return true; 230 return true;
231 } 231 }
@@ -241,7 +241,7 @@ struct CItem
241 bool IsMagic_GNU() const 241 bool IsMagic_GNU() const
242 { 242 {
243 for (unsigned i = 0; i < 8; i++) 243 for (unsigned i = 0; i < 8; i++)
244 if (Magic[i] != NFileHeader::NMagic::k_GNU_ustar__[i]) 244 if (Magic[i] != NFileHeader::NMagic::k_GNU_ustar[i])
245 return false; 245 return false;
246 return true; 246 return true;
247 } 247 }
diff --git a/CPP/7zip/Archive/Tar/TarOut.cpp b/CPP/7zip/Archive/Tar/TarOut.cpp
index f73c625..26d0855 100644
--- a/CPP/7zip/Archive/Tar/TarOut.cpp
+++ b/CPP/7zip/Archive/Tar/TarOut.cpp
@@ -60,7 +60,7 @@ static void WriteOctal_12(char *s, UInt64 val)
60 } 60 }
61} 61}
62 62
63static void WriteOctal_12_Signed(char *s, Int64 val) 63static void WriteOctal_12_Signed(char *s, const Int64 val)
64{ 64{
65 if (val >= 0) 65 if (val >= 0)
66 { 66 {
@@ -68,10 +68,10 @@ static void WriteOctal_12_Signed(char *s, Int64 val)
68 return; 68 return;
69 } 69 }
70 s[0] = s[1] = s[2] = s[3] = (char)(Byte)0xFF; 70 s[0] = s[1] = s[2] = s[3] = (char)(Byte)0xFF;
71 WriteBin_64bit(s + 4, val); 71 WriteBin_64bit(s + 4, (UInt64)val);
72} 72}
73 73
74static void CopyString(char *dest, const AString &src, unsigned maxSize) 74static void CopyString(char *dest, const AString &src, const unsigned maxSize)
75{ 75{
76 unsigned len = src.Len(); 76 unsigned len = src.Len();
77 if (len == 0) 77 if (len == 0)
@@ -119,11 +119,11 @@ HRESULT COutArchive::WriteHeaderReal(const CItem &item, bool isPax
119 119
120 COPY_STRING_CHECK (cur, 120 COPY_STRING_CHECK (cur,
121 (!isPax && !Glob_Name.IsEmpty()) ? Glob_Name : item.Name, 121 (!isPax && !Glob_Name.IsEmpty()) ? Glob_Name : item.Name,
122 kNameSize); 122 kNameSize)
123 123
124 WRITE_OCTAL_8_CHECK (cur, item.Mode); cur += 8; // & k_7_oct_digits_Val_Max 124 WRITE_OCTAL_8_CHECK (cur, item.Mode) cur += 8; // & k_7_oct_digits_Val_Max
125 WRITE_OCTAL_8_CHECK (cur, item.UID); cur += 8; 125 WRITE_OCTAL_8_CHECK (cur, item.UID) cur += 8;
126 WRITE_OCTAL_8_CHECK (cur, item.GID); cur += 8; 126 WRITE_OCTAL_8_CHECK (cur, item.GID) cur += 8;
127 127
128 WriteOctal_12 (cur, /* zero_PackSize ? 0 : */ item.PackSize); cur += 12; 128 WriteOctal_12 (cur, /* zero_PackSize ? 0 : */ item.PackSize); cur += 12;
129 WriteOctal_12_Signed (cur, /* zero_MTime ? 0 : */ item.MTime); cur += 12; 129 WriteOctal_12_Signed (cur, /* zero_MTime ? 0 : */ item.MTime); cur += 12;
@@ -135,13 +135,13 @@ HRESULT COutArchive::WriteHeaderReal(const CItem &item, bool isPax
135 135
136 *cur++ = item.LinkFlag; 136 *cur++ = item.LinkFlag;
137 137
138 COPY_STRING_CHECK (cur, item.LinkName, kNameSize); 138 COPY_STRING_CHECK (cur, item.LinkName, kNameSize)
139 139
140 memcpy(cur, item.Magic, 8); 140 memcpy(cur, item.Magic, 8);
141 cur += 8; 141 cur += 8;
142 142
143 COPY_STRING_CHECK (cur, item.User, kUserNameSize); 143 COPY_STRING_CHECK (cur, item.User, kUserNameSize)
144 COPY_STRING_CHECK (cur, item.Group, kGroupNameSize); 144 COPY_STRING_CHECK (cur, item.Group, kGroupNameSize)
145 145
146 const bool needDevice = (IsPosixMode && !isPax); 146 const bool needDevice = (IsPosixMode && !isPax);
147 147
@@ -159,7 +159,7 @@ HRESULT COutArchive::WriteHeaderReal(const CItem &item, bool isPax
159 159
160 if (!isPax && !Prefix.IsEmpty()) 160 if (!isPax && !Prefix.IsEmpty())
161 { 161 {
162 COPY_STRING_CHECK (cur, Prefix, kPrefixSize); 162 COPY_STRING_CHECK (cur, Prefix, kPrefixSize)
163 } 163 }
164 164
165 if (item.Is_Sparse()) 165 if (item.Is_Sparse())
@@ -194,7 +194,7 @@ HRESULT COutArchive::WriteHeaderReal(const CItem &item, bool isPax
194 record[148 + 7] = ' '; // we need it, if we use binary init 194 record[148 + 7] = ' '; // we need it, if we use binary init
195 } 195 }
196 196
197 RINOK(Write_Data(record, kRecordSize)); 197 RINOK(Write_Data(record, kRecordSize))
198 198
199 if (item.Is_Sparse()) 199 if (item.Is_Sparse())
200 { 200 {
@@ -209,7 +209,7 @@ HRESULT COutArchive::WriteHeaderReal(const CItem &item, bool isPax
209 WriteOctal_12(p + 12, sb.Size); 209 WriteOctal_12(p + 12, sb.Size);
210 } 210 }
211 record[21 * 24] = (char)(i < item.SparseBlocks.Size() ? 1 : 0); 211 record[21 * 24] = (char)(i < item.SparseBlocks.Size() ? 1 : 0);
212 RINOK(Write_Data(record, kRecordSize)); 212 RINOK(Write_Data(record, kRecordSize))
213 } 213 }
214 } 214 }
215 215
@@ -237,11 +237,11 @@ static void AddPaxLine(AString &s, const char *name, const AString &val)
237 s.Add_LF(); 237 s.Add_LF();
238} 238}
239 239
240 240// pt is defined : (pt.NumDigits >= 0)
241static void AddPaxTime(AString &s, const char *name, const CPaxTime &pt, 241static void AddPaxTime(AString &s, const char *name, const CPaxTime &pt,
242 const CTimeOptions &options) 242 const CTimeOptions &options)
243{ 243{
244 unsigned numDigits = pt.NumDigits; 244 unsigned numDigits = (unsigned)pt.NumDigits;
245 if (numDigits > options.NumDigitsMax) 245 if (numDigits > options.NumDigitsMax)
246 numDigits = options.NumDigitsMax; 246 numDigits = options.NumDigitsMax;
247 247
@@ -265,14 +265,14 @@ static void AddPaxTime(AString &s, const char *name, const CPaxTime &pt,
265 if (pt.Sec < 0) 265 if (pt.Sec < 0)
266 { 266 {
267 sec = -sec; 267 sec = -sec;
268 v += '-'; 268 v.Add_Minus();
269 if (ns != 0) 269 if (ns != 0)
270 { 270 {
271 ns = 1000*1000*1000 - ns; 271 ns = 1000*1000*1000 - ns;
272 sec--; 272 sec--;
273 } 273 }
274 } 274 }
275 v.Add_UInt64(sec); 275 v.Add_UInt64((UInt64)sec);
276 } 276 }
277 277
278 if (needNs) 278 if (needNs)
@@ -291,7 +291,7 @@ static void AddPaxTime(AString &s, const char *name, const CPaxTime &pt,
291 291
292 if (!d.IsEmpty()) 292 if (!d.IsEmpty())
293 { 293 {
294 v += '.'; 294 v.Add_Dot();
295 v += d; 295 v += d;
296 // v += "1234567009999"; // for debug 296 // v += "1234567009999"; // for debug
297 // for (int y = 0; y < 1000; y++) v += '8'; // for debug 297 // for (int y = 0; y < 1000; y++) v += '8'; // for debug
@@ -467,8 +467,8 @@ HRESULT COutArchive::WriteHeader(const CItem &item)
467 // mi.LinkFlag = 'Z'; // for debug 467 // mi.LinkFlag = 'Z'; // for debug
468 mi.PackSize = paxSize; 468 mi.PackSize = paxSize;
469 // for (unsigned y = 0; y < 1; y++) { // for debug 469 // for (unsigned y = 0; y < 1; y++) { // for debug
470 RINOK(WriteHeaderReal(mi, true)); // isPax 470 RINOK(WriteHeaderReal(mi, true)) // isPax
471 RINOK(Write_Data_And_Residual(s, paxSize)); 471 RINOK(Write_Data_And_Residual(s, paxSize))
472 // } // for debug 472 // } // for debug
473 /* 473 /*
474 we can send (zero_MTime) for compatibility with gnu tar output. 474 we can send (zero_MTime) for compatibility with gnu tar output.
@@ -538,8 +538,8 @@ HRESULT COutArchive::WriteHeader(const CItem &item)
538 const unsigned nameStreamSize = name->Len() + 1; 538 const unsigned nameStreamSize = name->Len() + 1;
539 mi.PackSize = nameStreamSize; 539 mi.PackSize = nameStreamSize;
540 // for (unsigned y = 0; y < 3; y++) { // for debug 540 // for (unsigned y = 0; y < 3; y++) { // for debug
541 RINOK(WriteHeaderReal(mi)); 541 RINOK(WriteHeaderReal(mi))
542 RINOK(Write_Data_And_Residual(name->Ptr(), nameStreamSize)); 542 RINOK(Write_Data_And_Residual(name->Ptr(), nameStreamSize))
543 // } 543 // }
544 544
545 // for debug 545 // for debug
@@ -615,7 +615,7 @@ HRESULT COutArchive::Write_AfterDataResidual(UInt64 dataSize)
615 615
616HRESULT COutArchive::Write_Data_And_Residual(const void *data, unsigned size) 616HRESULT COutArchive::Write_Data_And_Residual(const void *data, unsigned size)
617{ 617{
618 RINOK(Write_Data(data, size)); 618 RINOK(Write_Data(data, size))
619 return Write_AfterDataResidual(size); 619 return Write_AfterDataResidual(size);
620} 620}
621 621
@@ -636,7 +636,7 @@ HRESULT COutArchive::WriteFinishHeader()
636 636
637 for (unsigned i = 0; i < kNumFinishRecords; i++) 637 for (unsigned i = 0; i < kNumFinishRecords; i++)
638 { 638 {
639 RINOK(Write_Data(record, kRecordSize)); 639 RINOK(Write_Data(record, kRecordSize))
640 } 640 }
641 return S_OK; 641 return S_OK;
642} 642}
diff --git a/CPP/7zip/Archive/Tar/TarOut.h b/CPP/7zip/Archive/Tar/TarOut.h
index 34af20a..7b99c26 100644
--- a/CPP/7zip/Archive/Tar/TarOut.h
+++ b/CPP/7zip/Archive/Tar/TarOut.h
@@ -1,7 +1,7 @@
1// Archive/TarOut.h 1// Archive/TarOut.h
2 2
3#ifndef __ARCHIVE_TAR_OUT_H 3#ifndef ZIP7_INC_ARCHIVE_TAR_OUT_H
4#define __ARCHIVE_TAR_OUT_H 4#define ZIP7_INC_ARCHIVE_TAR_OUT_H
5 5
6#include "../../../Common/MyCom.h" 6#include "../../../Common/MyCom.h"
7 7
diff --git a/CPP/7zip/Archive/Tar/TarRegister.cpp b/CPP/7zip/Archive/Tar/TarRegister.cpp
index a78c376..709c191 100644
--- a/CPP/7zip/Archive/Tar/TarRegister.cpp
+++ b/CPP/7zip/Archive/Tar/TarRegister.cpp
@@ -12,7 +12,7 @@ namespace NTar {
12static const Byte k_Signature[] = { 'u', 's', 't', 'a', 'r' }; 12static const Byte k_Signature[] = { 'u', 's', 't', 'a', 'r' };
13 13
14REGISTER_ARC_IO( 14REGISTER_ARC_IO(
15 "tar", "tar ova", 0, 0xEE, 15 "tar", "tar ova", NULL, 0xEE,
16 k_Signature, 16 k_Signature,
17 NFileHeader::kUstarMagic_Offset, 17 NFileHeader::kUstarMagic_Offset,
18 NArcInfoFlags::kStartOpen 18 NArcInfoFlags::kStartOpen
diff --git a/CPP/7zip/Archive/Tar/TarUpdate.cpp b/CPP/7zip/Archive/Tar/TarUpdate.cpp
index caa0a82..0b348e9 100644
--- a/CPP/7zip/Archive/Tar/TarUpdate.cpp
+++ b/CPP/7zip/Archive/Tar/TarUpdate.cpp
@@ -8,6 +8,7 @@
8 8
9#include "../../Common/LimitedStreams.h" 9#include "../../Common/LimitedStreams.h"
10#include "../../Common/ProgressUtils.h" 10#include "../../Common/ProgressUtils.h"
11#include "../../Common/StreamUtils.h"
11 12
12#include "../../Compress/CopyCoder.h" 13#include "../../Compress/CopyCoder.h"
13 14
@@ -44,7 +45,7 @@ HRESULT Prop_To_PaxTime(const NWindows::NCOM::CPropVariant &prop, CPaxTime &pt)
44 const unsigned prec = prop.wReserved1; 45 const unsigned prec = prop.wReserved1;
45 if (prec >= k_PropVar_TimePrec_Base) 46 if (prec >= k_PropVar_TimePrec_Base)
46 { 47 {
47 pt.NumDigits = prec - k_PropVar_TimePrec_Base; 48 pt.NumDigits = (int)(prec - k_PropVar_TimePrec_Base);
48 if (prop.wReserved2 < 100) 49 if (prop.wReserved2 < 100)
49 ns += prop.wReserved2; 50 ns += prop.wReserved2;
50 } 51 }
@@ -58,7 +59,7 @@ static HRESULT GetTime(IStreamGetProp *getProp, UInt32 pid, CPaxTime &pt)
58{ 59{
59 pt.Clear(); 60 pt.Clear();
60 NWindows::NCOM::CPropVariant prop; 61 NWindows::NCOM::CPropVariant prop;
61 RINOK(getProp->GetProperty(pid, &prop)); 62 RINOK(getProp->GetProperty(pid, &prop))
62 return Prop_To_PaxTime(prop, pt); 63 return Prop_To_PaxTime(prop, pt);
63} 64}
64 65
@@ -73,7 +74,7 @@ static HRESULT GetUser(IStreamGetProp *getProp,
73 bool isSet = false; 74 bool isSet = false;
74 { 75 {
75 NWindows::NCOM::CPropVariant prop; 76 NWindows::NCOM::CPropVariant prop;
76 RINOK(getProp->GetProperty(pidId, &prop)); 77 RINOK(getProp->GetProperty(pidId, &prop))
77 if (prop.vt == VT_UI4) 78 if (prop.vt == VT_UI4)
78 { 79 {
79 isSet = true; 80 isSet = true;
@@ -85,7 +86,7 @@ static HRESULT GetUser(IStreamGetProp *getProp,
85 } 86 }
86 { 87 {
87 NWindows::NCOM::CPropVariant prop; 88 NWindows::NCOM::CPropVariant prop;
88 RINOK(getProp->GetProperty(pidName, &prop)); 89 RINOK(getProp->GetProperty(pidName, &prop))
89 if (prop.vt == VT_BSTR) 90 if (prop.vt == VT_BSTR)
90 { 91 {
91 const UString s = prop.bstrVal; 92 const UString s = prop.bstrVal;
@@ -133,7 +134,7 @@ static HRESULT GetDevice(IStreamGetProp *getProp,
133{ 134{
134 defined = false; 135 defined = false;
135 NWindows::NCOM::CPropVariant prop; 136 NWindows::NCOM::CPropVariant prop;
136 RINOK(getProp->GetProperty(pid, &prop)); 137 RINOK(getProp->GetProperty(pid, &prop))
137 if (prop.vt == VT_EMPTY) 138 if (prop.vt == VT_EMPTY)
138 return S_OK; 139 return S_OK;
139 if (prop.vt == VT_UI4) 140 if (prop.vt == VT_UI4)
@@ -158,8 +159,10 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
158 outArchive.IsPosixMode = options.PosixMode; 159 outArchive.IsPosixMode = options.PosixMode;
159 outArchive.TimeOptions = options.TimeOptions; 160 outArchive.TimeOptions = options.TimeOptions;
160 161
161 CMyComPtr<IOutStream> outSeekStream; 162 Z7_DECL_CMyComPtr_QI_FROM(IOutStream, outSeekStream, outStream)
162 outStream->QueryInterface(IID_IOutStream, (void **)&outSeekStream); 163 Z7_DECL_CMyComPtr_QI_FROM(IStreamSetRestriction, setRestriction, outStream)
164 Z7_DECL_CMyComPtr_QI_FROM(IArchiveUpdateCallbackFile, opCallback, outStream)
165
163 if (outSeekStream) 166 if (outSeekStream)
164 { 167 {
165 /* 168 /*
@@ -169,12 +172,10 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
169 RINOK(outStream->Write(buf, sizeof(buf), NULL)); 172 RINOK(outStream->Write(buf, sizeof(buf), NULL));
170 */ 173 */
171 // we need real outArchive.Pos, if outSeekStream->SetSize() will be used. 174 // we need real outArchive.Pos, if outSeekStream->SetSize() will be used.
172 RINOK(outSeekStream->Seek(0, STREAM_SEEK_CUR, &outArchive.Pos)); 175 RINOK(outSeekStream->Seek(0, STREAM_SEEK_CUR, &outArchive.Pos))
173 } 176 }
174 177 if (setRestriction)
175 178 RINOK(setRestriction->SetRestriction(0, 0))
176 CMyComPtr<IArchiveUpdateCallbackFile> opCallback;
177 updateCallback->QueryInterface(IID_IArchiveUpdateCallbackFile, (void **)&opCallback);
178 179
179 UInt64 complexity = 0; 180 UInt64 complexity = 0;
180 181
@@ -188,7 +189,7 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
188 complexity += inputItems[(unsigned)ui.IndexInArc].Get_FullSize_Aligned(); 189 complexity += inputItems[(unsigned)ui.IndexInArc].Get_FullSize_Aligned();
189 } 190 }
190 191
191 RINOK(updateCallback->SetTotal(complexity)); 192 RINOK(updateCallback->SetTotal(complexity))
192 193
193 NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder; 194 NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;
194 CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec; 195 CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
@@ -198,7 +199,7 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
198 lps->Init(updateCallback, true); 199 lps->Init(updateCallback, true);
199 200
200 CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream; 201 CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
201 CMyComPtr<CLimitedSequentialInStream> inStreamLimited(streamSpec); 202 CMyComPtr<ISequentialInStream> inStreamLimited(streamSpec);
202 streamSpec->SetStream(inStream); 203 streamSpec->SetStream(inStream);
203 204
204 complexity = 0; 205 complexity = 0;
@@ -208,10 +209,14 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
208 for (i = 0;; i++) 209 for (i = 0;; i++)
209 { 210 {
210 lps->InSize = lps->OutSize = complexity; 211 lps->InSize = lps->OutSize = complexity;
211 RINOK(lps->SetCur()); 212 RINOK(lps->SetCur())
212 213
213 if (i == updateItems.Size()) 214 if (i == updateItems.Size())
215 {
216 if (outSeekStream && setRestriction)
217 RINOK(setRestriction->SetRestriction(0, 0))
214 return outArchive.WriteFinishHeader(); 218 return outArchive.WriteFinishHeader();
219 }
215 220
216 const CUpdateItem &ui = updateItems[i]; 221 const CUpdateItem &ui = updateItems[i];
217 CItem item; 222 CItem item;
@@ -253,7 +258,7 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
253 if (ui.NewData || ui.NewProps) 258 if (ui.NewData || ui.NewProps)
254 { 259 {
255 RINOK(GetPropString(updateCallback, ui.IndexInClient, kpidSymLink, symLink, 260 RINOK(GetPropString(updateCallback, ui.IndexInClient, kpidSymLink, symLink,
256 options.CodePage, options.UtfFlags, true)); 261 options.CodePage, options.UtfFlags, true))
257 if (!symLink.IsEmpty()) 262 if (!symLink.IsEmpty())
258 { 263 {
259 item.LinkFlag = NFileHeader::NLinkFlag::kSymLink; 264 item.LinkFlag = NFileHeader::NLinkFlag::kSymLink;
@@ -286,7 +291,7 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
286 needWrite = false; 291 needWrite = false;
287 else 292 else
288 { 293 {
289 RINOK(res); 294 RINOK(res)
290 295
291 if (!fileInStream) 296 if (!fileInStream)
292 { 297 {
@@ -295,9 +300,7 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
295 } 300 }
296 else 301 else
297 { 302 {
298 CMyComPtr<IStreamGetProps> getProps; 303 Z7_DECL_CMyComPtr_QI_FROM(IStreamGetProp, getProp, fileInStream)
299 CMyComPtr<IStreamGetProp> getProp;
300 fileInStream->QueryInterface(IID_IStreamGetProp, (void **)&getProp);
301 if (getProp) 304 if (getProp)
302 { 305 {
303 if (options.Write_MTime.Val) RINOK(GetTime(getProp, kpidMTime, item.PaxTimes.MTime)) 306 if (options.Write_MTime.Val) RINOK(GetTime(getProp, kpidMTime, item.PaxTimes.MTime))
@@ -312,23 +315,23 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
312 */ 315 */
313 bool defined = false; 316 bool defined = false;
314 UInt32 val = 0; 317 UInt32 val = 0;
315 RINOK(GetDevice(getProp, kpidDeviceMajor, val, defined)); 318 RINOK(GetDevice(getProp, kpidDeviceMajor, val, defined))
316 if (defined) 319 if (defined)
317 { 320 {
318 item.DeviceMajor = val; 321 item.DeviceMajor = val;
319 item.DeviceMajor_Defined = true; 322 item.DeviceMajor_Defined = true;
320 item.DeviceMinor = 0; 323 item.DeviceMinor = 0;
321 item.DeviceMinor_Defined = false; 324 item.DeviceMinor_Defined = false;
322 RINOK(GetDevice(getProp, kpidDeviceMinor, item.DeviceMinor, item.DeviceMinor_Defined)); 325 RINOK(GetDevice(getProp, kpidDeviceMinor, item.DeviceMinor, item.DeviceMinor_Defined))
323 } 326 }
324 } 327 }
325 328
326 RINOK(GetUser(getProp, kpidUser, kpidUserId, item.User, item.UID, options.CodePage, options.UtfFlags)); 329 RINOK(GetUser(getProp, kpidUser, kpidUserId, item.User, item.UID, options.CodePage, options.UtfFlags))
327 RINOK(GetUser(getProp, kpidGroup, kpidGroupId, item.Group, item.GID, options.CodePage, options.UtfFlags)); 330 RINOK(GetUser(getProp, kpidGroup, kpidGroupId, item.Group, item.GID, options.CodePage, options.UtfFlags))
328 331
329 { 332 {
330 NWindows::NCOM::CPropVariant prop; 333 NWindows::NCOM::CPropVariant prop;
331 RINOK(getProp->GetProperty(kpidPosixAttrib, &prop)); 334 RINOK(getProp->GetProperty(kpidPosixAttrib, &prop))
332 if (prop.vt == VT_EMPTY) 335 if (prop.vt == VT_EMPTY)
333 item.Mode = 336 item.Mode =
334 MY_LIN_S_IRWXO 337 MY_LIN_S_IRWXO
@@ -346,7 +349,7 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
346 349
347 { 350 {
348 NWindows::NCOM::CPropVariant prop; 351 NWindows::NCOM::CPropVariant prop;
349 RINOK(getProp->GetProperty(kpidSize, &prop)); 352 RINOK(getProp->GetProperty(kpidSize, &prop))
350 if (prop.vt != VT_UI8) 353 if (prop.vt != VT_UI8)
351 return E_INVALIDARG; 354 return E_INVALIDARG;
352 const UInt64 size = prop.uhVal.QuadPart; 355 const UInt64 size = prop.uhVal.QuadPart;
@@ -361,7 +364,7 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
361 } 364 }
362 else 365 else
363 { 366 {
364 fileInStream->QueryInterface(IID_IStreamGetProps, (void **)&getProps); 367 Z7_DECL_CMyComPtr_QI_FROM(IStreamGetProps, getProps, fileInStream)
365 if (getProps) 368 if (getProps)
366 { 369 {
367 FILETIME mTime, aTime, cTime; 370 FILETIME mTime, aTime, cTime;
@@ -386,7 +389,7 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
386 // we must request kpidHardLink after updateCallback->GetStream() 389 // we must request kpidHardLink after updateCallback->GetStream()
387 AString hardLink; 390 AString hardLink;
388 RINOK(GetPropString(updateCallback, ui.IndexInClient, kpidHardLink, hardLink, 391 RINOK(GetPropString(updateCallback, ui.IndexInClient, kpidHardLink, hardLink,
389 options.CodePage, options.UtfFlags, true)); 392 options.CodePage, options.UtfFlags, true))
390 if (!hardLink.IsEmpty()) 393 if (!hardLink.IsEmpty())
391 { 394 {
392 item.LinkFlag = NFileHeader::NLinkFlag::kHardLink; 395 item.LinkFlag = NFileHeader::NLinkFlag::kHardLink;
@@ -408,7 +411,11 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
408 { 411 {
409 const UInt64 headerPos = outArchive.Pos; 412 const UInt64 headerPos = outArchive.Pos;
410 // item.PackSize = ((UInt64)1 << 33); // for debug 413 // item.PackSize = ((UInt64)1 << 33); // for debug
411 RINOK(outArchive.WriteHeader(item)); 414
415 if (outSeekStream && setRestriction)
416 RINOK(setRestriction->SetRestriction(outArchive.Pos, (UInt64)(Int64)-1))
417
418 RINOK(outArchive.WriteHeader(item))
412 if (fileInStream) 419 if (fileInStream)
413 { 420 {
414 for (unsigned numPasses = 0;; numPasses++) 421 for (unsigned numPasses = 0;; numPasses++)
@@ -424,9 +431,9 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
424 } 431 }
425 432
426 const UInt64 dataPos = outArchive.Pos; 433 const UInt64 dataPos = outArchive.Pos;
427 RINOK(copyCoder->Code(fileInStream, outStream, NULL, NULL, progress)); 434 RINOK(copyCoder->Code(fileInStream, outStream, NULL, NULL, progress))
428 outArchive.Pos += copyCoderSpec->TotalSize; 435 outArchive.Pos += copyCoderSpec->TotalSize;
429 RINOK(outArchive.Write_AfterDataResidual(copyCoderSpec->TotalSize)); 436 RINOK(outArchive.Write_AfterDataResidual(copyCoderSpec->TotalSize))
430 437
431 // if (numPasses >= 10) // for debug 438 // if (numPasses >= 10) // for debug
432 if (copyCoderSpec->TotalSize == item.PackSize) 439 if (copyCoderSpec->TotalSize == item.PackSize)
@@ -442,11 +449,11 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
442 if (!outSeekStream) 449 if (!outSeekStream)
443 return E_FAIL; 450 return E_FAIL;
444 const UInt64 nextPos = outArchive.Pos; 451 const UInt64 nextPos = outArchive.Pos;
445 RINOK(outSeekStream->Seek(-(Int64)(nextPos - headerPos), STREAM_SEEK_CUR, NULL)); 452 RINOK(outSeekStream->Seek(-(Int64)(nextPos - headerPos), STREAM_SEEK_CUR, NULL))
446 outArchive.Pos = headerPos; 453 outArchive.Pos = headerPos;
447 item.PackSize = copyCoderSpec->TotalSize; 454 item.PackSize = copyCoderSpec->TotalSize;
448 455
449 RINOK(outArchive.WriteHeader(item)); 456 RINOK(outArchive.WriteHeader(item))
450 457
451 // if (numPasses >= 10) // for debug 458 // if (numPasses >= 10) // for debug
452 if (outArchive.Pos == dataPos) 459 if (outArchive.Pos == dataPos)
@@ -454,7 +461,7 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
454 const UInt64 alignedSize = nextPos - dataPos; 461 const UInt64 alignedSize = nextPos - dataPos;
455 if (alignedSize != 0) 462 if (alignedSize != 0)
456 { 463 {
457 RINOK(outSeekStream->Seek(alignedSize, STREAM_SEEK_CUR, NULL)); 464 RINOK(outSeekStream->Seek((Int64)alignedSize, STREAM_SEEK_CUR, NULL))
458 outArchive.Pos += alignedSize; 465 outArchive.Pos += alignedSize;
459 } 466 }
460 break; 467 break;
@@ -462,12 +469,11 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
462 469
463 // size of header was changed. 470 // size of header was changed.
464 // we remove data after header and try new attempt, if required 471 // we remove data after header and try new attempt, if required
465 CMyComPtr<IInStream> fileSeekStream; 472 Z7_DECL_CMyComPtr_QI_FROM(IInStream, fileSeekStream, fileInStream)
466 fileInStream->QueryInterface(IID_IInStream, (void **)&fileSeekStream);
467 if (!fileSeekStream) 473 if (!fileSeekStream)
468 return E_FAIL; 474 return E_FAIL;
469 RINOK(fileSeekStream->Seek(0, STREAM_SEEK_SET, NULL)); 475 RINOK(InStream_SeekToBegin(fileSeekStream))
470 RINOK(outSeekStream->SetSize(outArchive.Pos)); 476 RINOK(outSeekStream->SetSize(outArchive.Pos))
471 if (item.PackSize == 0) 477 if (item.PackSize == 0)
472 break; 478 break;
473 } 479 }
@@ -476,7 +482,7 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
476 482
477 complexity += item.PackSize; 483 complexity += item.PackSize;
478 fileInStream.Release(); 484 fileInStream.Release();
479 RINOK(updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK)); 485 RINOK(updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK))
480 } 486 }
481 else 487 else
482 { 488 {
@@ -518,7 +524,7 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
518 item.UID = existItem.UID; 524 item.UID = existItem.UID;
519 item.GID = existItem.GID; 525 item.GID = existItem.GID;
520 526
521 RINOK(outArchive.WriteHeader(item)); 527 RINOK(outArchive.WriteHeader(item))
522 size = existItem.Get_PackSize_Aligned(); 528 size = existItem.Get_PackSize_Aligned();
523 pos = existItem.Get_DataPos(); 529 pos = existItem.Get_DataPos();
524 } 530 }
@@ -530,10 +536,12 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
530 536
531 if (size != 0) 537 if (size != 0)
532 { 538 {
533 RINOK(inStream->Seek((Int64)pos, STREAM_SEEK_SET, NULL)); 539 RINOK(InStream_SeekSet(inStream, pos))
534 streamSpec->Init(size); 540 streamSpec->Init(size);
541 if (outSeekStream && setRestriction)
542 RINOK(setRestriction->SetRestriction(0, 0))
535 // 22.00 : we copy Residual data from old archive to new archive instead of zeroing 543 // 22.00 : we copy Residual data from old archive to new archive instead of zeroing
536 RINOK(copyCoder->Code(inStreamLimited, outStream, NULL, NULL, progress)); 544 RINOK(copyCoder->Code(inStreamLimited, outStream, NULL, NULL, progress))
537 if (copyCoderSpec->TotalSize != size) 545 if (copyCoderSpec->TotalSize != size)
538 return E_FAIL; 546 return E_FAIL;
539 outArchive.Pos += size; 547 outArchive.Pos += size;
diff --git a/CPP/7zip/Archive/Tar/TarUpdate.h b/CPP/7zip/Archive/Tar/TarUpdate.h
index ca0976d..f6c2e77 100644
--- a/CPP/7zip/Archive/Tar/TarUpdate.h
+++ b/CPP/7zip/Archive/Tar/TarUpdate.h
@@ -1,7 +1,7 @@
1// TarUpdate.h 1// TarUpdate.h
2 2
3#ifndef __TAR_UPDATE_H 3#ifndef ZIP7_INC_TAR_UPDATE_H
4#define __TAR_UPDATE_H 4#define ZIP7_INC_TAR_UPDATE_H
5 5
6#include "../IArchive.h" 6#include "../IArchive.h"
7 7