This commit is contained in:
Igor Pavlov
2023-12-22 17:17:05 +00:00
committed by Kornel
parent ec44a8a070
commit a36c48cece
954 changed files with 42199 additions and 25482 deletions

View File

@@ -1,8 +1,11 @@
// StdAfx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#ifndef ZIP7_INC_STDAFX_H
#define ZIP7_INC_STDAFX_H
#if defined(_MSC_VER) && _MSC_VER >= 1800
#pragma warning(disable : 4464) // relative include path contains '..'
#endif
#include "../../../Common/Common.h"
#endif

View File

@@ -67,7 +67,7 @@ static const char *k_Characts_Prefix = "PREFIX";
IMP_IInArchive_Props
IMP_IInArchive_ArcProps
STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
Z7_COM7F_IMF(CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value))
{
NCOM::CPropVariant prop;
switch (propID)
@@ -83,9 +83,9 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)
{
case k_ErrorType_UnexpectedEnd: flags = kpv_ErrorFlags_UnexpectedEnd; break;
case k_ErrorType_Corrupted: flags = kpv_ErrorFlags_HeadersError; break;
// case k_ErrorType_OK: break;
case k_ErrorType_OK: break;
// case k_ErrorType_Warning: break;
default: break;
// default: break;
}
if (flags != 0)
prop = flags;
@@ -206,10 +206,9 @@ AString CEncodingCharacts::GetCharactsString() const
HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
{
UInt64 endPos = 0;
UInt64 endPos;
{
RINOK(stream->Seek(0, STREAM_SEEK_END, &endPos));
RINOK(stream->Seek(0, STREAM_SEEK_SET, NULL));
RINOK(InStream_AtBegin_GetSize(stream, endPos))
}
_arc._phySize_Defined = true;
@@ -224,7 +223,7 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
for (;;)
{
_arc.NumFiles = _items.Size();
RINOK(_arc.ReadItem(item));
RINOK(_arc.ReadItem(item))
if (!_arc.filled)
break;
@@ -245,7 +244,7 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
_items.Add(item);
RINOK(stream->Seek((Int64)item.Get_PackSize_Aligned(), STREAM_SEEK_CUR, &_arc._phySize));
RINOK(stream->Seek((Int64)item.Get_PackSize_Aligned(), STREAM_SEEK_CUR, &_arc._phySize))
if (_arc._phySize > endPos)
{
_arc._error = k_ErrorType_UnexpectedEnd;
@@ -290,10 +289,11 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
_isArc = false;
return S_FALSE;
}
CMyComPtr<IArchiveOpenVolumeCallback> openVolumeCallback;
if (!callback)
return S_FALSE;
callback->QueryInterface(IID_IArchiveOpenVolumeCallback, (void **)&openVolumeCallback);
Z7_DECL_CMyComPtr_QI_FROM(
IArchiveOpenVolumeCallback,
openVolumeCallback, callback)
if (!openVolumeCallback)
return S_FALSE;
NCOM::CPropVariant prop;
@@ -310,20 +310,20 @@ HRESULT CHandler::Open2(IInStream *stream, IArchiveOpenCallback *callback)
return S_OK;
}
STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallback *openArchiveCallback)
Z7_COM7F_IMF(CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallback *openArchiveCallback))
{
COM_TRY_BEGIN
// for (int i = 0; i < 10; i++) // for debug
{
Close();
RINOK(Open2(stream, openArchiveCallback));
RINOK(Open2(stream, openArchiveCallback))
_stream = stream;
}
return S_OK;
COM_TRY_END
}
STDMETHODIMP CHandler::OpenSeq(ISequentialInStream *stream)
Z7_COM7F_IMF(CHandler::OpenSeq(ISequentialInStream *stream))
{
Close();
_seqStream = stream;
@@ -331,7 +331,7 @@ STDMETHODIMP CHandler::OpenSeq(ISequentialInStream *stream)
return S_OK;
}
STDMETHODIMP CHandler::Close()
Z7_COM7F_IMF(CHandler::Close())
{
_isArc = false;
@@ -346,7 +346,7 @@ STDMETHODIMP CHandler::Close()
return S_OK;
}
STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems)
Z7_COM7F_IMF(CHandler::GetNumberOfItems(UInt32 *numItems))
{
*numItems = (_stream ? _items.Size() : (UInt32)(Int32)-1);
return S_OK;
@@ -367,7 +367,7 @@ HRESULT CHandler::SkipTo(UInt32 index)
if (_latestIsRead)
{
const UInt64 packSize = _latestItem.Get_PackSize_Aligned();
RINOK(copyCoderSpec->Code(_seqStream, NULL, &packSize, &packSize, NULL));
RINOK(copyCoder->Code(_seqStream, NULL, &packSize, &packSize, NULL))
_arc._phySize += copyCoderSpec->TotalSize;
if (copyCoderSpec->TotalSize != packSize)
{
@@ -381,7 +381,7 @@ HRESULT CHandler::SkipTo(UInt32 index)
{
_arc.SeqStream = _seqStream;
_arc.InStream = NULL;
RINOK(_arc.ReadItem(_latestItem));
RINOK(_arc.ReadItem(_latestItem))
if (!_arc.filled)
{
_arc._phySize_Defined = true;
@@ -407,6 +407,7 @@ void CHandler::TarStringToUnicode(const AString &s, NWindows::NCOM::CPropVariant
}
// CPaxTime is defined (NumDigits >= 0)
static void PaxTimeToProp(const CPaxTime &pt, NWindows::NCOM::CPropVariant &prop)
{
UInt64 v;
@@ -418,7 +419,7 @@ static void PaxTimeToProp(const CPaxTime &pt, NWindows::NCOM::CPropVariant &prop
ft.dwLowDateTime = (DWORD)v;
ft.dwHighDateTime = (DWORD)(v >> 32);
prop.SetAsTimeFrom_FT_Prec_Ns100(ft,
k_PropVar_TimePrec_Base + pt.NumDigits, pt.Ns % 100);
k_PropVar_TimePrec_Base + (unsigned)pt.NumDigits, pt.Ns % 100);
}
@@ -469,7 +470,7 @@ static void AddSpecBools(AString &s, const char *name, bool b1, bool b2)
}
STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
Z7_COM7F_IMF(CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value))
{
COM_TRY_BEGIN
NCOM::CPropVariant prop;
@@ -483,7 +484,7 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
return E_INVALIDARG;
else
{
RINOK(SkipTo(index));
RINOK(SkipTo(index))
item = &_latestItem;
}
}
@@ -665,8 +666,8 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val
}
HRESULT CHandler::Extract(const UInt32 *indices, UInt32 numItems,
Int32 testMode, IArchiveExtractCallback *extractCallback)
Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems,
Int32 testMode, IArchiveExtractCallback *extractCallback))
{
COM_TRY_BEGIN
ISequentialInStream *stream = _seqStream;
@@ -703,7 +704,7 @@ HRESULT CHandler::Extract(const UInt32 *indices, UInt32 numItems,
{
lps->InSize = totalPackSize;
lps->OutSize = totalSize;
RINOK(lps->SetCur());
RINOK(lps->SetCur())
CMyComPtr<ISequentialOutStream> realOutStream;
Int32 askMode = testMode ?
NExtract::NAskMode::kTest :
@@ -715,20 +716,20 @@ HRESULT CHandler::Extract(const UInt32 *indices, UInt32 numItems,
HRESULT res = SkipTo(index);
if (res == E_INVALIDARG)
break;
RINOK(res);
RINOK(res)
item = &_latestItem;
}
else
item = &_items[index];
RINOK(extractCallback->GetStream(index, &realOutStream, askMode));
RINOK(extractCallback->GetStream(index, &realOutStream, askMode))
const UInt64 unpackSize = item->Get_UnpackSize();
totalSize += unpackSize;
totalPackSize += item->Get_PackSize_Aligned();
if (item->IsDir())
{
RINOK(extractCallback->PrepareOperation(askMode));
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
RINOK(extractCallback->PrepareOperation(askMode))
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK))
continue;
}
bool skipMode = false;
@@ -741,8 +742,8 @@ HRESULT CHandler::Extract(const UInt32 *indices, UInt32 numItems,
if (item->IsHardLink() ||
item->IsSymLink())
{
RINOK(extractCallback->PrepareOperation(askMode));
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK));
RINOK(extractCallback->PrepareOperation(askMode))
RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK))
}
*/
continue;
@@ -750,7 +751,7 @@ HRESULT CHandler::Extract(const UInt32 *indices, UInt32 numItems,
skipMode = true;
askMode = NExtract::NAskMode::kSkip;
}
RINOK(extractCallback->PrepareOperation(askMode));
RINOK(extractCallback->PrepareOperation(askMode))
outStreamSpec->SetStream(realOutStream);
realOutStream.Release();
@@ -770,16 +771,16 @@ HRESULT CHandler::Extract(const UInt32 *indices, UInt32 numItems,
{
if (item->Is_SymLink())
{
RINOK(WriteStream(outStreamSpec, (const char *)item->LinkName, item->LinkName.Len()));
RINOK(WriteStream(outStreamSpec, (const char *)item->LinkName, item->LinkName.Len()))
}
else
{
if (!seqMode)
{
RINOK(_stream->Seek((Int64)item->Get_DataPos(), STREAM_SEEK_SET, NULL));
RINOK(InStream_SeekSet(_stream, item->Get_DataPos()))
}
streamSpec->Init(item->Get_PackSize_Aligned());
RINOK(copyCoder->Code(inStream2, outStream, NULL, NULL, progress));
RINOK(copyCoder->Code(inStream2, outStream, NULL, NULL, progress))
}
if (outStreamSpec->GetRem() != 0)
opRes = NExtract::NOperationResult::kDataError;
@@ -790,16 +791,16 @@ HRESULT CHandler::Extract(const UInt32 *indices, UInt32 numItems,
_curIndex++;
}
outStreamSpec->ReleaseStream();
RINOK(extractCallback->SetOperationResult(opRes));
RINOK(extractCallback->SetOperationResult(opRes))
}
return S_OK;
COM_TRY_END
}
class CSparseStream:
public IInStream,
public CMyUnknownImp
{
Z7_CLASS_IMP_IInStream(
CSparseStream
)
UInt64 _phyPos;
UInt64 _virtPos;
bool _needStartSeek;
@@ -810,10 +811,6 @@ public:
unsigned ItemIndex;
CRecordVector<UInt64> PhyOffsets;
MY_UNKNOWN_IMP2(ISequentialInStream, IInStream)
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
void Init()
{
_virtPos = 0;
@@ -823,7 +820,7 @@ public:
};
STDMETHODIMP CSparseStream::Read(void *data, UInt32 size, UInt32 *processedSize)
Z7_COM7F_IMF(CSparseStream::Read(void *data, UInt32 size, UInt32 *processedSize))
{
if (processedSize)
*processedSize = 0;
@@ -867,7 +864,7 @@ STDMETHODIMP CSparseStream::Read(void *data, UInt32 size, UInt32 *processedSize)
UInt64 phyPos = PhyOffsets[left] + relat;
if (_needStartSeek || _phyPos != phyPos)
{
RINOK(Handler->_stream->Seek((Int64)(item.Get_DataPos() + phyPos), STREAM_SEEK_SET, NULL));
RINOK(InStream_SeekSet(Handler->_stream, (item.Get_DataPos() + phyPos)))
_needStartSeek = false;
_phyPos = phyPos;
}
@@ -894,7 +891,7 @@ STDMETHODIMP CSparseStream::Read(void *data, UInt32 size, UInt32 *processedSize)
return res;
}
STDMETHODIMP CSparseStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition)
Z7_COM7F_IMF(CSparseStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition))
{
switch (seekOrigin)
{
@@ -911,7 +908,7 @@ STDMETHODIMP CSparseStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPos
return S_OK;
}
STDMETHODIMP CHandler::GetStream(UInt32 index, ISequentialInStream **stream)
Z7_COM7F_IMF(CHandler::GetStream(UInt32 index, ISequentialInStream **stream))
{
COM_TRY_BEGIN
@@ -961,7 +958,7 @@ void CHandler::Init()
}
STDMETHODIMP CHandler::SetProperties(const wchar_t * const *names, const PROPVARIANT *values, UInt32 numProps)
Z7_COM7F_IMF(CHandler::SetProperties(const wchar_t * const *names, const PROPVARIANT *values, UInt32 numProps))
{
Init();
@@ -978,12 +975,12 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t * const *names, const PROPVAR
{
// some clients write 'x' property. So we support it
UInt32 level = 0;
RINOK(ParsePropToUInt32(name.Ptr(1), prop, level));
RINOK(ParsePropToUInt32(name.Ptr(1), prop, level))
}
else if (name.IsEqualTo("cp"))
{
UInt32 cp = CP_OEMCP;
RINOK(ParsePropToUInt32(L"", prop, cp));
RINOK(ParsePropToUInt32(L"", prop, cp))
_forceCodePage = true;
_curCodePage = _specifiedCodePage = cp;
}
@@ -1036,7 +1033,7 @@ STDMETHODIMP CHandler::SetProperties(const wchar_t * const *names, const PROPVAR
}
*/
bool processed = false;
RINOK(_handlerTimeOptions.Parse(name, prop, processed));
RINOK(_handlerTimeOptions.Parse(name, prop, processed))
if (processed)
continue;
return E_INVALIDARG;

View File

@@ -1,12 +1,10 @@
// TarHandler.h
#ifndef __TAR_HANDLER_H
#define __TAR_HANDLER_H
#ifndef ZIP7_INC_TAR_HANDLER_H
#define ZIP7_INC_TAR_HANDLER_H
#include "../../../Common/MyCom.h"
#include "../../../Windows/PropVariant.h"
#include "../../Compress/CopyCoder.h"
#include "../Common/HandlerOut.h"
@@ -16,14 +14,12 @@
namespace NArchive {
namespace NTar {
class CHandler:
public IInArchive,
public IArchiveOpenSeq,
public IInArchiveGetStream,
public ISetProperties,
public IOutArchive,
public CMyUnknownImp
{
Z7_CLASS_IMP_CHandler_IInArchive_4(
IArchiveOpenSeq
, IInArchiveGetStream
, ISetProperties
, IOutArchive
)
public:
CObjectVector<CItemEx> _items;
CMyComPtr<IInStream> _stream;
@@ -53,20 +49,6 @@ private:
HRESULT SkipTo(UInt32 index);
void TarStringToUnicode(const AString &s, NWindows::NCOM::CPropVariant &prop, bool toOs = false) const;
public:
MY_UNKNOWN_IMP5(
IInArchive,
IArchiveOpenSeq,
IInArchiveGetStream,
ISetProperties,
IOutArchive
)
INTERFACE_IInArchive(;)
INTERFACE_IOutArchive(;)
STDMETHOD(OpenSeq)(ISequentialInStream *stream);
STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
STDMETHOD(SetProperties)(const wchar_t * const *names, const PROPVARIANT *values, UInt32 numProps);
void Init();
CHandler();
};

View File

@@ -20,7 +20,7 @@ using namespace NWindows;
namespace NArchive {
namespace NTar {
STDMETHODIMP CHandler::GetFileTimeType(UInt32 *type)
Z7_COM7F_IMF(CHandler::GetFileTimeType(UInt32 *type))
{
UInt32 t = NFileTimeType::kUnix;
const UInt32 prec = _handlerTimeOptions.Prec;
@@ -55,7 +55,7 @@ HRESULT GetPropString(IArchiveUpdateCallback *callback, UInt32 index, PROPID pro
UINT codePage, unsigned utfFlags, bool convertSlash)
{
NCOM::CPropVariant prop;
RINOK(callback->GetProperty(index, propId, &prop));
RINOK(callback->GetProperty(index, propId, &prop))
if (prop.vt == VT_BSTR)
{
@@ -94,7 +94,7 @@ static HRESULT GetTime(UInt32 i, UInt32 pid, IArchiveUpdateCallback *callback,
{
pt.Clear();
NCOM::CPropVariant prop;
RINOK(callback->GetProperty(i, pid, &prop));
RINOK(callback->GetProperty(i, pid, &prop))
return Prop_To_PaxTime(prop, pt);
}
@@ -125,7 +125,7 @@ static HRESULT GetDevice(IArchiveUpdateCallback *callback, UInt32 i,
{
defined = false;
NWindows::NCOM::CPropVariant prop;
RINOK(callback->GetProperty(i, pid, &prop));
RINOK(callback->GetProperty(i, pid, &prop))
if (prop.vt == VT_EMPTY)
return S_OK;
if (prop.vt == VT_UI4)
@@ -147,7 +147,7 @@ static HRESULT GetUser(IArchiveUpdateCallback *callback, UInt32 i,
bool isSet = false;
{
NWindows::NCOM::CPropVariant prop;
RINOK(callback->GetProperty(i, pidId, &prop));
RINOK(callback->GetProperty(i, pidId, &prop))
if (prop.vt == VT_UI4)
{
isSet = true;
@@ -160,7 +160,7 @@ static HRESULT GetUser(IArchiveUpdateCallback *callback, UInt32 i,
}
{
NWindows::NCOM::CPropVariant prop;
RINOK(callback->GetProperty(i, pidName, &prop));
RINOK(callback->GetProperty(i, pidName, &prop))
if (prop.vt == VT_BSTR)
{
const UString s = prop.bstrVal;
@@ -181,8 +181,8 @@ static HRESULT GetUser(IArchiveUpdateCallback *callback, UInt32 i,
STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,
IArchiveUpdateCallback *callback)
Z7_COM7F_IMF(CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numItems,
IArchiveUpdateCallback *callback))
{
COM_TRY_BEGIN
@@ -196,8 +196,8 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
/*
// for debug only:
unsigned utfFlags = 0;
utfFlags |= UTF_FLAG__TO_UTF8__EXTRACT_BMP_ESCAPE;
utfFlags |= UTF_FLAG__TO_UTF8__SURROGATE_ERROR;
utfFlags |= Z7_UTF_FLAG_TO_UTF8_EXTRACT_BMP_ESCAPE;
utfFlags |= Z7_UTF_FLAG_TO_UTF8_SURROGATE_ERROR;
*/
for (UInt32 i = 0; i < numItems; i++)
@@ -210,7 +210,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
if (!callback)
return E_FAIL;
RINOK(callback->GetUpdateItemInfo(i, &newData, &newProps, &indexInArc));
RINOK(callback->GetUpdateItemInfo(i, &newData, &newProps, &indexInArc))
ui.NewProps = IntToBool(newProps);
ui.NewData = IntToBool(newData);
@@ -221,7 +221,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
{
{
NCOM::CPropVariant prop;
RINOK(callback->GetProperty(i, kpidIsDir, &prop));
RINOK(callback->GetProperty(i, kpidIsDir, &prop))
if (prop.vt == VT_EMPTY)
ui.IsDir = false;
else if (prop.vt != VT_BOOL)
@@ -232,7 +232,7 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
{
NCOM::CPropVariant prop;
RINOK(callback->GetProperty(i, kpidPosixAttrib, &prop));
RINOK(callback->GetProperty(i, kpidPosixAttrib, &prop))
if (prop.vt == VT_EMPTY)
ui.Mode =
MY_LIN_S_IRWXO
@@ -255,25 +255,25 @@ STDMETHODIMP CHandler::UpdateItems(ISequentialOutStream *outStream, UInt32 numIt
if (_handlerTimeOptions.Write_CTime.Val)
RINOK(GetTime(i, kpidCTime, callback, ui.PaxTimes.CTime))
RINOK(GetPropString(callback, i, kpidPath, ui.Name, codePage, utfFlags, true));
RINOK(GetPropString(callback, i, kpidPath, ui.Name, codePage, utfFlags, true))
if (ui.IsDir && !ui.Name.IsEmpty() && ui.Name.Back() != '/')
ui.Name += '/';
// ui.Name += '/'; // for debug
if (_posixMode)
{
RINOK(GetDevice(callback, i, kpidDeviceMajor, ui.DeviceMajor, ui.DeviceMajor_Defined));
RINOK(GetDevice(callback, i, kpidDeviceMinor, ui.DeviceMinor, ui.DeviceMinor_Defined));
RINOK(GetDevice(callback, i, kpidDeviceMajor, ui.DeviceMajor, ui.DeviceMajor_Defined))
RINOK(GetDevice(callback, i, kpidDeviceMinor, ui.DeviceMinor, ui.DeviceMinor_Defined))
}
RINOK(GetUser(callback, i, kpidUser, kpidUserId, ui.User, ui.UID, codePage, utfFlags));
RINOK(GetUser(callback, i, kpidGroup, kpidGroupId, ui.Group, ui.GID, codePage, utfFlags));
RINOK(GetUser(callback, i, kpidUser, kpidUserId, ui.User, ui.UID, codePage, utfFlags))
RINOK(GetUser(callback, i, kpidGroup, kpidGroupId, ui.Group, ui.GID, codePage, utfFlags))
}
if (IntToBool(newData))
{
NCOM::CPropVariant prop;
RINOK(callback->GetProperty(i, kpidSize, &prop));
RINOK(callback->GetProperty(i, kpidSize, &prop))
if (prop.vt != VT_UI8)
return E_INVALIDARG;
ui.Size = prop.uhVal.QuadPart;

View File

@@ -20,7 +20,7 @@ namespace NFileHeader {
// 7-Zip used kUsTar_00 before 21.07:
const char k_Posix_ustar_00[8] = { 'u', 's', 't', 'a', 'r', 0, '0', '0' } ;
// GNU TAR uses such header:
const char k_GNU_ustar__[8] = { 'u', 's', 't', 'a', 'r', ' ', ' ', 0 } ;
const char k_GNU_ustar[8] = { 'u', 's', 't', 'a', 'r', ' ', ' ', 0 } ;
}
/*

View File

@@ -1,7 +1,7 @@
// Archive/TarHeader.h
#ifndef __ARCHIVE_TAR_HEADER_H
#define __ARCHIVE_TAR_HEADER_H
#ifndef ZIP7_INC_ARCHIVE_TAR_HEADER_H
#define ZIP7_INC_ARCHIVE_TAR_HEADER_H
#include "../../../Common/MyTypes.h"
@@ -81,7 +81,7 @@ namespace NFileHeader
// extern const char * const kGNUTar; // = "GNUtar "; // 7 chars and a null
// extern const char * const kEmpty; // = "\0\0\0\0\0\0\0\0"
extern const char k_Posix_ustar_00[8];
extern const char k_GNU_ustar__[8];
extern const char k_GNU_ustar[8];
}
}

View File

@@ -14,8 +14,8 @@
#define NUM_UNROLL_BYTES (8 * 4)
MY_NO_INLINE static bool IsBufNonZero(const void *data, size_t size);
MY_NO_INLINE static bool IsBufNonZero(const void *data, size_t size)
Z7_NO_INLINE static bool IsBufNonZero(const void *data, size_t size);
Z7_NO_INLINE static bool IsBufNonZero(const void *data, size_t size)
{
const Byte *p = (const Byte *)data;
@@ -159,7 +159,7 @@ API_FUNC_IsArc IsArc_Tar(const Byte *p2, size_t size)
UInt32 mode;
// we allow empty Mode value for LongName prefix items
CHECK(OctalToNumber32(p, mode, true)); p += 8;
CHECK(OctalToNumber32(p, mode, true)) p += 8;
// if (!OctalToNumber32(p, item.UID)) item.UID = 0;
p += 8;
@@ -170,9 +170,9 @@ API_FUNC_IsArc IsArc_Tar(const Byte *p2, size_t size)
Int64 time;
UInt32 checkSum;
bool isBin;
CHECK(ParseSize(p, packSize, isBin)); p += 12;
CHECK(ParseInt64_MTime(p, time, isBin)); p += 12;
CHECK(OctalToNumber32(p, checkSum));
CHECK(ParseSize(p, packSize, isBin)) p += 12;
CHECK(ParseInt64_MTime(p, time, isBin)) p += 12;
CHECK(OctalToNumber32(p, checkSum))
return k_IsArc_Res_YES;
}
@@ -188,7 +188,7 @@ HRESULT CArchive::GetNextItemReal(CItemEx &item)
for (;;)
{
size_t processedSize = NFileHeader::kRecordSize;
RINOK(ReadStream(SeqStream, buf, &processedSize));
RINOK(ReadStream(SeqStream, buf, &processedSize))
if (processedSize == 0)
{
if (!thereAreEmptyRecords)
@@ -220,7 +220,7 @@ HRESULT CArchive::GetNextItemReal(CItemEx &item)
thereAreEmptyRecords = true;
if (OpenCallback)
{
RINOK(Progress(item, 0));
RINOK(Progress(item, 0))
}
}
if (thereAreEmptyRecords)
@@ -243,19 +243,19 @@ HRESULT CArchive::GetNextItemReal(CItemEx &item)
*/
// we allow empty Mode value for LongName prefix items
RIF(OctalToNumber32(p, item.Mode, true)); p += 8;
RIF(OctalToNumber32(p, item.Mode, true)) p += 8;
if (!OctalToNumber32(p, item.UID)) { item.UID = 0; } p += 8;
if (!OctalToNumber32(p, item.GID)) { item.GID = 0; } p += 8;
RIF(ParseSize(p, item.PackSize, item.PackSize_IsBin));
RIF(ParseSize(p, item.PackSize, item.PackSize_IsBin))
item.Size = item.PackSize;
item.Size_IsBin = item.PackSize_IsBin;
p += 12;
RIF(ParseInt64_MTime(p, item.MTime, item.MTime_IsBin)); p += 12;
RIF(ParseInt64_MTime(p, item.MTime, item.MTime_IsBin)) p += 12;
UInt32 checkSum;
RIF(OctalToNumber32(p, checkSum));
RIF(OctalToNumber32(p, checkSum))
memset(p, ' ', 8); p += 8;
item.LinkFlag = *p++;
@@ -273,8 +273,8 @@ HRESULT CArchive::GetNextItemReal(CItemEx &item)
ReadString(p, NFileHeader::kUserNameSize, item.User); p += NFileHeader::kUserNameSize;
ReadString(p, NFileHeader::kGroupNameSize, item.Group); p += NFileHeader::kGroupNameSize;
item.DeviceMajor_Defined = (p[0] != 0); if (item.DeviceMajor_Defined) { RIF(OctalToNumber32(p, item.DeviceMajor)); } p += 8;
item.DeviceMinor_Defined = (p[0] != 0); if (item.DeviceMinor_Defined) { RIF(OctalToNumber32(p, item.DeviceMinor)); } p += 8;
item.DeviceMajor_Defined = (p[0] != 0); if (item.DeviceMajor_Defined) { RIF(OctalToNumber32(p, item.DeviceMajor)) } p += 8;
item.DeviceMinor_Defined = (p[0] != 0); if (item.DeviceMinor_Defined) { RIF(OctalToNumber32(p, item.DeviceMinor)) } p += 8;
if (p[0] != 0
&& item.IsMagic_ustar_5chars()
@@ -338,7 +338,7 @@ HRESULT CArchive::GetNextItemReal(CItemEx &item)
Byte isExtended = (Byte)buf[482];
if (isExtended != 0 && isExtended != 1)
return S_OK;
RIF(ParseSize(buf + 483, item.Size, item.Size_IsBin));
RIF(ParseSize(buf + 483, item.Size, item.Size_IsBin))
UInt64 min = 0;
for (unsigned i = 0; i < 4; i++)
{
@@ -350,8 +350,8 @@ HRESULT CArchive::GetNextItemReal(CItemEx &item)
break;
}
CSparseBlock sb;
RIF(ParseSize(p, sb.Offset));
RIF(ParseSize(p + 12, sb.Size));
RIF(ParseSize(p, sb.Offset))
RIF(ParseSize(p + 12, sb.Size))
item.SparseBlocks.Add(sb);
if (sb.Offset < min || sb.Offset > item.Size)
return S_OK;
@@ -367,7 +367,7 @@ HRESULT CArchive::GetNextItemReal(CItemEx &item)
while (isExtended != 0)
{
size_t processedSize = NFileHeader::kRecordSize;
RINOK(ReadStream(SeqStream, buf, &processedSize));
RINOK(ReadStream(SeqStream, buf, &processedSize))
if (processedSize != NFileHeader::kRecordSize)
{
error = k_ErrorType_UnexpectedEnd;
@@ -378,7 +378,7 @@ HRESULT CArchive::GetNextItemReal(CItemEx &item)
if (OpenCallback)
{
RINOK(Progress(item, 0));
RINOK(Progress(item, 0))
}
isExtended = (Byte)buf[21 * 24];
@@ -394,8 +394,8 @@ HRESULT CArchive::GetNextItemReal(CItemEx &item)
break;
}
CSparseBlock sb;
RIF(ParseSize(p, sb.Offset));
RIF(ParseSize(p + 12, sb.Size));
RIF(ParseSize(p, sb.Offset))
RIF(ParseSize(p + 12, sb.Size))
item.SparseBlocks.Add(sb);
if (sb.Offset < min || sb.Offset > item.Size)
return S_OK;
@@ -459,7 +459,7 @@ HRESULT CArchive::ReadDataToBuffer(const CItemEx &item,
error = k_ErrorType_UnexpectedEnd;
return res;
}
RINOK(res);
RINOK(res)
packSize -= size;
@@ -492,7 +492,7 @@ HRESULT CArchive::ReadDataToBuffer(const CItemEx &item,
if (InStream)
{
RINOK(InStream->Seek((Int64)packSize, STREAM_SEEK_CUR, NULL));
RINOK(InStream->Seek((Int64)packSize, STREAM_SEEK_CUR, NULL))
return S_OK;
}
const unsigned kBufSize = 1 << 15;
@@ -502,7 +502,7 @@ HRESULT CArchive::ReadDataToBuffer(const CItemEx &item,
{
if (OpenCallback)
{
RINOK(Progress(item, pos));
RINOK(Progress(item, pos))
}
unsigned size = kBufSize;
@@ -590,8 +590,8 @@ static bool ParsePaxTime(const AString &src, CPaxTime &pt, bool &doubleTagError)
if (sec >= ((UInt64)1 << 63))
return false;
if (isNegative)
sec = -(Int64)sec;
pt.Sec = sec;
sec = (UInt64)-(Int64)sec;
pt.Sec = (Int64)sec;
}
if (*end == 0)
{
@@ -617,10 +617,10 @@ static bool ParsePaxTime(const AString &src, CPaxTime &pt, bool &doubleTagError)
if (i < kNsDigits)
{
ns *= 10;
ns += c - '0';
ns += (unsigned)(c - '0');
}
}
pt.NumDigits = (i < kNsDigits ? i : kNsDigits);
pt.NumDigits = (int)(i < kNsDigits ? i : kNsDigits);
while (i < kNsDigits)
{
ns *= 10;
@@ -690,7 +690,7 @@ bool CPaxInfo::ParsePax(const CTempBuffer &tb, bool isFile)
return false;
name.SetFrom(s + offset, i - offset);
val.SetFrom(s + i + 1, size - 1 - (i + 1));
val.SetFrom(s + i + 1, (unsigned)(size - 1 - (i + 1)));
bool parsed = false;
if (isFile)
@@ -822,29 +822,34 @@ HRESULT CArchive::ReadItem2(CItemEx &item)
PaxBuf.Init();
PaxBuf_global.Init();
for (unsigned recordIndex = 0;; recordIndex++)
UInt64 numExtraRecords = 0;
for (;;)
{
if (OpenCallback)
{
RINOK(Progress(item, 0));
RINOK(Progress(item, 0))
}
RINOK(GetNextItemReal(item));
RINOK(GetNextItemReal(item))
// NumRecords++;
if (!filled)
{
if (error == k_ErrorType_OK)
if (item.LongName_WasUsed ||
item.LongLink_WasUsed ||
item.Num_Pax_Records != 0)
if (numExtraRecords != 0
|| item.LongName_WasUsed
|| item.LongLink_WasUsed
|| item.Num_Pax_Records != 0)
error = k_ErrorType_Corrupted;
return S_OK;
}
if (error != k_ErrorType_OK)
return S_OK;
numExtraRecords++;
const char lf = item.LinkFlag;
if (lf == NFileHeader::NLinkFlag::kGnu_LongName ||
lf == NFileHeader::NLinkFlag::kGnu_LongLink)
@@ -874,7 +879,7 @@ HRESULT CArchive::ReadItem2(CItemEx &item)
*/
const unsigned kLongNameSizeMax = (unsigned)1 << 14;
RINOK(ReadDataToBuffer(item, *tb, kLongNameSizeMax));
RINOK(ReadDataToBuffer(item, *tb, kLongNameSizeMax))
if (error != k_ErrorType_OK)
return S_OK;
@@ -921,7 +926,7 @@ HRESULT CArchive::ReadItem2(CItemEx &item)
CTempBuffer *tb = (lf == NFileHeader::NLinkFlag::kGlobal ? &PaxBuf_global : &PaxBuf);
RINOK(ReadDataToBuffer(item, *tb, kParsingPaxSizeMax));
RINOK(ReadDataToBuffer(item, *tb, kParsingPaxSizeMax))
if (error != k_ErrorType_OK)
return S_OK;
@@ -951,12 +956,19 @@ HRESULT CArchive::ReadItem2(CItemEx &item)
}
else
_is_PaxGlobal_Error = true;
if (isStartHeader)
if (isStartHeader
&& item.Num_Pax_Records == 1
&& numExtraRecords == 1)
{
// we skip global pax header info after parsing
item.HeaderPos += item.HeaderSize;
item.HeaderSize = 0;
item.Num_Pax_Records = 0;
numExtraRecords = 0;
}
else
_is_PaxGlobal_Error = true;
}
continue;
}
@@ -1071,7 +1083,7 @@ HRESULT CArchive::ReadItem(CItemEx &item)
if (error != k_ErrorType_OK)
_error = error;
RINOK(res);
RINOK(res)
if (filled)
{

View File

@@ -1,7 +1,7 @@
// TarIn.h
#ifndef __ARCHIVE_TAR_IN_H
#define __ARCHIVE_TAR_IN_H
#ifndef ZIP7_INC_ARCHIVE_TAR_IN_H
#define ZIP7_INC_ARCHIVE_TAR_IN_H
#include "../IArchive.h"

View File

@@ -1,7 +1,7 @@
// TarItem.h
#ifndef __ARCHIVE_TAR_ITEM_H
#define __ARCHIVE_TAR_ITEM_H
#ifndef ZIP7_INC_ARCHIVE_TAR_ITEM_H
#define ZIP7_INC_ARCHIVE_TAR_ITEM_H
#include "../../../Common/MyLinux.h"
#include "../../../Common/UTFConvert.h"
@@ -143,7 +143,7 @@ struct CItem
{
memcpy(Magic, posixMode ?
NFileHeader::NMagic::k_Posix_ustar_00 :
NFileHeader::NMagic::k_GNU_ustar__,
NFileHeader::NMagic::k_GNU_ustar,
8);
}
@@ -172,7 +172,7 @@ struct CItem
void Set_LinkFlag_for_File(UInt32 mode)
{
Byte lf = NFileHeader::NLinkFlag::kNormal;
char lf = NFileHeader::NLinkFlag::kNormal;
if (MY_LIN_S_ISCHR(mode)) lf = NFileHeader::NLinkFlag::kCharacter;
else if (MY_LIN_S_ISBLK(mode)) lf = NFileHeader::NLinkFlag::kBlock;
else if (MY_LIN_S_ISFIFO(mode)) lf = NFileHeader::NLinkFlag::kFIFO;
@@ -225,7 +225,7 @@ struct CItem
bool IsMagic_ustar_5chars() const
{
for (unsigned i = 0; i < 5; i++)
if (Magic[i] != NFileHeader::NMagic::k_GNU_ustar__[i])
if (Magic[i] != NFileHeader::NMagic::k_GNU_ustar[i])
return false;
return true;
}
@@ -241,7 +241,7 @@ struct CItem
bool IsMagic_GNU() const
{
for (unsigned i = 0; i < 8; i++)
if (Magic[i] != NFileHeader::NMagic::k_GNU_ustar__[i])
if (Magic[i] != NFileHeader::NMagic::k_GNU_ustar[i])
return false;
return true;
}

View File

@@ -60,7 +60,7 @@ static void WriteOctal_12(char *s, UInt64 val)
}
}
static void WriteOctal_12_Signed(char *s, Int64 val)
static void WriteOctal_12_Signed(char *s, const Int64 val)
{
if (val >= 0)
{
@@ -68,10 +68,10 @@ static void WriteOctal_12_Signed(char *s, Int64 val)
return;
}
s[0] = s[1] = s[2] = s[3] = (char)(Byte)0xFF;
WriteBin_64bit(s + 4, val);
WriteBin_64bit(s + 4, (UInt64)val);
}
static void CopyString(char *dest, const AString &src, unsigned maxSize)
static void CopyString(char *dest, const AString &src, const unsigned maxSize)
{
unsigned len = src.Len();
if (len == 0)
@@ -119,11 +119,11 @@ HRESULT COutArchive::WriteHeaderReal(const CItem &item, bool isPax
COPY_STRING_CHECK (cur,
(!isPax && !Glob_Name.IsEmpty()) ? Glob_Name : item.Name,
kNameSize);
kNameSize)
WRITE_OCTAL_8_CHECK (cur, item.Mode); cur += 8; // & k_7_oct_digits_Val_Max
WRITE_OCTAL_8_CHECK (cur, item.UID); cur += 8;
WRITE_OCTAL_8_CHECK (cur, item.GID); cur += 8;
WRITE_OCTAL_8_CHECK (cur, item.Mode) cur += 8; // & k_7_oct_digits_Val_Max
WRITE_OCTAL_8_CHECK (cur, item.UID) cur += 8;
WRITE_OCTAL_8_CHECK (cur, item.GID) cur += 8;
WriteOctal_12 (cur, /* zero_PackSize ? 0 : */ item.PackSize); cur += 12;
WriteOctal_12_Signed (cur, /* zero_MTime ? 0 : */ item.MTime); cur += 12;
@@ -135,13 +135,13 @@ HRESULT COutArchive::WriteHeaderReal(const CItem &item, bool isPax
*cur++ = item.LinkFlag;
COPY_STRING_CHECK (cur, item.LinkName, kNameSize);
COPY_STRING_CHECK (cur, item.LinkName, kNameSize)
memcpy(cur, item.Magic, 8);
cur += 8;
COPY_STRING_CHECK (cur, item.User, kUserNameSize);
COPY_STRING_CHECK (cur, item.Group, kGroupNameSize);
COPY_STRING_CHECK (cur, item.User, kUserNameSize)
COPY_STRING_CHECK (cur, item.Group, kGroupNameSize)
const bool needDevice = (IsPosixMode && !isPax);
@@ -159,7 +159,7 @@ HRESULT COutArchive::WriteHeaderReal(const CItem &item, bool isPax
if (!isPax && !Prefix.IsEmpty())
{
COPY_STRING_CHECK (cur, Prefix, kPrefixSize);
COPY_STRING_CHECK (cur, Prefix, kPrefixSize)
}
if (item.Is_Sparse())
@@ -194,7 +194,7 @@ HRESULT COutArchive::WriteHeaderReal(const CItem &item, bool isPax
record[148 + 7] = ' '; // we need it, if we use binary init
}
RINOK(Write_Data(record, kRecordSize));
RINOK(Write_Data(record, kRecordSize))
if (item.Is_Sparse())
{
@@ -209,7 +209,7 @@ HRESULT COutArchive::WriteHeaderReal(const CItem &item, bool isPax
WriteOctal_12(p + 12, sb.Size);
}
record[21 * 24] = (char)(i < item.SparseBlocks.Size() ? 1 : 0);
RINOK(Write_Data(record, kRecordSize));
RINOK(Write_Data(record, kRecordSize))
}
}
@@ -237,11 +237,11 @@ static void AddPaxLine(AString &s, const char *name, const AString &val)
s.Add_LF();
}
// pt is defined : (pt.NumDigits >= 0)
static void AddPaxTime(AString &s, const char *name, const CPaxTime &pt,
const CTimeOptions &options)
{
unsigned numDigits = pt.NumDigits;
unsigned numDigits = (unsigned)pt.NumDigits;
if (numDigits > options.NumDigitsMax)
numDigits = options.NumDigitsMax;
@@ -265,14 +265,14 @@ static void AddPaxTime(AString &s, const char *name, const CPaxTime &pt,
if (pt.Sec < 0)
{
sec = -sec;
v += '-';
v.Add_Minus();
if (ns != 0)
{
ns = 1000*1000*1000 - ns;
sec--;
}
}
v.Add_UInt64(sec);
v.Add_UInt64((UInt64)sec);
}
if (needNs)
@@ -291,7 +291,7 @@ static void AddPaxTime(AString &s, const char *name, const CPaxTime &pt,
if (!d.IsEmpty())
{
v += '.';
v.Add_Dot();
v += d;
// v += "1234567009999"; // for debug
// for (int y = 0; y < 1000; y++) v += '8'; // for debug
@@ -467,8 +467,8 @@ HRESULT COutArchive::WriteHeader(const CItem &item)
// mi.LinkFlag = 'Z'; // for debug
mi.PackSize = paxSize;
// for (unsigned y = 0; y < 1; y++) { // for debug
RINOK(WriteHeaderReal(mi, true)); // isPax
RINOK(Write_Data_And_Residual(s, paxSize));
RINOK(WriteHeaderReal(mi, true)) // isPax
RINOK(Write_Data_And_Residual(s, paxSize))
// } // for debug
/*
we can send (zero_MTime) for compatibility with gnu tar output.
@@ -538,8 +538,8 @@ HRESULT COutArchive::WriteHeader(const CItem &item)
const unsigned nameStreamSize = name->Len() + 1;
mi.PackSize = nameStreamSize;
// for (unsigned y = 0; y < 3; y++) { // for debug
RINOK(WriteHeaderReal(mi));
RINOK(Write_Data_And_Residual(name->Ptr(), nameStreamSize));
RINOK(WriteHeaderReal(mi))
RINOK(Write_Data_And_Residual(name->Ptr(), nameStreamSize))
// }
// for debug
@@ -615,7 +615,7 @@ HRESULT COutArchive::Write_AfterDataResidual(UInt64 dataSize)
HRESULT COutArchive::Write_Data_And_Residual(const void *data, unsigned size)
{
RINOK(Write_Data(data, size));
RINOK(Write_Data(data, size))
return Write_AfterDataResidual(size);
}
@@ -636,7 +636,7 @@ HRESULT COutArchive::WriteFinishHeader()
for (unsigned i = 0; i < kNumFinishRecords; i++)
{
RINOK(Write_Data(record, kRecordSize));
RINOK(Write_Data(record, kRecordSize))
}
return S_OK;
}

View File

@@ -1,7 +1,7 @@
// Archive/TarOut.h
#ifndef __ARCHIVE_TAR_OUT_H
#define __ARCHIVE_TAR_OUT_H
#ifndef ZIP7_INC_ARCHIVE_TAR_OUT_H
#define ZIP7_INC_ARCHIVE_TAR_OUT_H
#include "../../../Common/MyCom.h"

View File

@@ -12,7 +12,7 @@ namespace NTar {
static const Byte k_Signature[] = { 'u', 's', 't', 'a', 'r' };
REGISTER_ARC_IO(
"tar", "tar ova", 0, 0xEE,
"tar", "tar ova", NULL, 0xEE,
k_Signature,
NFileHeader::kUstarMagic_Offset,
NArcInfoFlags::kStartOpen

View File

@@ -8,6 +8,7 @@
#include "../../Common/LimitedStreams.h"
#include "../../Common/ProgressUtils.h"
#include "../../Common/StreamUtils.h"
#include "../../Compress/CopyCoder.h"
@@ -44,7 +45,7 @@ HRESULT Prop_To_PaxTime(const NWindows::NCOM::CPropVariant &prop, CPaxTime &pt)
const unsigned prec = prop.wReserved1;
if (prec >= k_PropVar_TimePrec_Base)
{
pt.NumDigits = prec - k_PropVar_TimePrec_Base;
pt.NumDigits = (int)(prec - k_PropVar_TimePrec_Base);
if (prop.wReserved2 < 100)
ns += prop.wReserved2;
}
@@ -58,7 +59,7 @@ static HRESULT GetTime(IStreamGetProp *getProp, UInt32 pid, CPaxTime &pt)
{
pt.Clear();
NWindows::NCOM::CPropVariant prop;
RINOK(getProp->GetProperty(pid, &prop));
RINOK(getProp->GetProperty(pid, &prop))
return Prop_To_PaxTime(prop, pt);
}
@@ -73,7 +74,7 @@ static HRESULT GetUser(IStreamGetProp *getProp,
bool isSet = false;
{
NWindows::NCOM::CPropVariant prop;
RINOK(getProp->GetProperty(pidId, &prop));
RINOK(getProp->GetProperty(pidId, &prop))
if (prop.vt == VT_UI4)
{
isSet = true;
@@ -85,7 +86,7 @@ static HRESULT GetUser(IStreamGetProp *getProp,
}
{
NWindows::NCOM::CPropVariant prop;
RINOK(getProp->GetProperty(pidName, &prop));
RINOK(getProp->GetProperty(pidName, &prop))
if (prop.vt == VT_BSTR)
{
const UString s = prop.bstrVal;
@@ -133,7 +134,7 @@ static HRESULT GetDevice(IStreamGetProp *getProp,
{
defined = false;
NWindows::NCOM::CPropVariant prop;
RINOK(getProp->GetProperty(pid, &prop));
RINOK(getProp->GetProperty(pid, &prop))
if (prop.vt == VT_EMPTY)
return S_OK;
if (prop.vt == VT_UI4)
@@ -158,8 +159,10 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
outArchive.IsPosixMode = options.PosixMode;
outArchive.TimeOptions = options.TimeOptions;
CMyComPtr<IOutStream> outSeekStream;
outStream->QueryInterface(IID_IOutStream, (void **)&outSeekStream);
Z7_DECL_CMyComPtr_QI_FROM(IOutStream, outSeekStream, outStream)
Z7_DECL_CMyComPtr_QI_FROM(IStreamSetRestriction, setRestriction, outStream)
Z7_DECL_CMyComPtr_QI_FROM(IArchiveUpdateCallbackFile, opCallback, outStream)
if (outSeekStream)
{
/*
@@ -169,12 +172,10 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
RINOK(outStream->Write(buf, sizeof(buf), NULL));
*/
// we need real outArchive.Pos, if outSeekStream->SetSize() will be used.
RINOK(outSeekStream->Seek(0, STREAM_SEEK_CUR, &outArchive.Pos));
RINOK(outSeekStream->Seek(0, STREAM_SEEK_CUR, &outArchive.Pos))
}
CMyComPtr<IArchiveUpdateCallbackFile> opCallback;
updateCallback->QueryInterface(IID_IArchiveUpdateCallbackFile, (void **)&opCallback);
if (setRestriction)
RINOK(setRestriction->SetRestriction(0, 0))
UInt64 complexity = 0;
@@ -188,7 +189,7 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
complexity += inputItems[(unsigned)ui.IndexInArc].Get_FullSize_Aligned();
}
RINOK(updateCallback->SetTotal(complexity));
RINOK(updateCallback->SetTotal(complexity))
NCompress::CCopyCoder *copyCoderSpec = new NCompress::CCopyCoder;
CMyComPtr<ICompressCoder> copyCoder = copyCoderSpec;
@@ -198,7 +199,7 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
lps->Init(updateCallback, true);
CLimitedSequentialInStream *streamSpec = new CLimitedSequentialInStream;
CMyComPtr<CLimitedSequentialInStream> inStreamLimited(streamSpec);
CMyComPtr<ISequentialInStream> inStreamLimited(streamSpec);
streamSpec->SetStream(inStream);
complexity = 0;
@@ -208,10 +209,14 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
for (i = 0;; i++)
{
lps->InSize = lps->OutSize = complexity;
RINOK(lps->SetCur());
RINOK(lps->SetCur())
if (i == updateItems.Size())
{
if (outSeekStream && setRestriction)
RINOK(setRestriction->SetRestriction(0, 0))
return outArchive.WriteFinishHeader();
}
const CUpdateItem &ui = updateItems[i];
CItem item;
@@ -253,7 +258,7 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
if (ui.NewData || ui.NewProps)
{
RINOK(GetPropString(updateCallback, ui.IndexInClient, kpidSymLink, symLink,
options.CodePage, options.UtfFlags, true));
options.CodePage, options.UtfFlags, true))
if (!symLink.IsEmpty())
{
item.LinkFlag = NFileHeader::NLinkFlag::kSymLink;
@@ -286,7 +291,7 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
needWrite = false;
else
{
RINOK(res);
RINOK(res)
if (!fileInStream)
{
@@ -295,9 +300,7 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
}
else
{
CMyComPtr<IStreamGetProps> getProps;
CMyComPtr<IStreamGetProp> getProp;
fileInStream->QueryInterface(IID_IStreamGetProp, (void **)&getProp);
Z7_DECL_CMyComPtr_QI_FROM(IStreamGetProp, getProp, fileInStream)
if (getProp)
{
if (options.Write_MTime.Val) RINOK(GetTime(getProp, kpidMTime, item.PaxTimes.MTime))
@@ -312,23 +315,23 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
*/
bool defined = false;
UInt32 val = 0;
RINOK(GetDevice(getProp, kpidDeviceMajor, val, defined));
RINOK(GetDevice(getProp, kpidDeviceMajor, val, defined))
if (defined)
{
item.DeviceMajor = val;
item.DeviceMajor_Defined = true;
item.DeviceMinor = 0;
item.DeviceMinor_Defined = false;
RINOK(GetDevice(getProp, kpidDeviceMinor, item.DeviceMinor, item.DeviceMinor_Defined));
RINOK(GetDevice(getProp, kpidDeviceMinor, item.DeviceMinor, item.DeviceMinor_Defined))
}
}
RINOK(GetUser(getProp, kpidUser, kpidUserId, item.User, item.UID, options.CodePage, options.UtfFlags));
RINOK(GetUser(getProp, kpidGroup, kpidGroupId, item.Group, item.GID, options.CodePage, options.UtfFlags));
RINOK(GetUser(getProp, kpidUser, kpidUserId, item.User, item.UID, options.CodePage, options.UtfFlags))
RINOK(GetUser(getProp, kpidGroup, kpidGroupId, item.Group, item.GID, options.CodePage, options.UtfFlags))
{
NWindows::NCOM::CPropVariant prop;
RINOK(getProp->GetProperty(kpidPosixAttrib, &prop));
RINOK(getProp->GetProperty(kpidPosixAttrib, &prop))
if (prop.vt == VT_EMPTY)
item.Mode =
MY_LIN_S_IRWXO
@@ -346,7 +349,7 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
{
NWindows::NCOM::CPropVariant prop;
RINOK(getProp->GetProperty(kpidSize, &prop));
RINOK(getProp->GetProperty(kpidSize, &prop))
if (prop.vt != VT_UI8)
return E_INVALIDARG;
const UInt64 size = prop.uhVal.QuadPart;
@@ -361,7 +364,7 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
}
else
{
fileInStream->QueryInterface(IID_IStreamGetProps, (void **)&getProps);
Z7_DECL_CMyComPtr_QI_FROM(IStreamGetProps, getProps, fileInStream)
if (getProps)
{
FILETIME mTime, aTime, cTime;
@@ -386,7 +389,7 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
// we must request kpidHardLink after updateCallback->GetStream()
AString hardLink;
RINOK(GetPropString(updateCallback, ui.IndexInClient, kpidHardLink, hardLink,
options.CodePage, options.UtfFlags, true));
options.CodePage, options.UtfFlags, true))
if (!hardLink.IsEmpty())
{
item.LinkFlag = NFileHeader::NLinkFlag::kHardLink;
@@ -408,7 +411,11 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
{
const UInt64 headerPos = outArchive.Pos;
// item.PackSize = ((UInt64)1 << 33); // for debug
RINOK(outArchive.WriteHeader(item));
if (outSeekStream && setRestriction)
RINOK(setRestriction->SetRestriction(outArchive.Pos, (UInt64)(Int64)-1))
RINOK(outArchive.WriteHeader(item))
if (fileInStream)
{
for (unsigned numPasses = 0;; numPasses++)
@@ -424,9 +431,9 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
}
const UInt64 dataPos = outArchive.Pos;
RINOK(copyCoder->Code(fileInStream, outStream, NULL, NULL, progress));
RINOK(copyCoder->Code(fileInStream, outStream, NULL, NULL, progress))
outArchive.Pos += copyCoderSpec->TotalSize;
RINOK(outArchive.Write_AfterDataResidual(copyCoderSpec->TotalSize));
RINOK(outArchive.Write_AfterDataResidual(copyCoderSpec->TotalSize))
// if (numPasses >= 10) // for debug
if (copyCoderSpec->TotalSize == item.PackSize)
@@ -442,11 +449,11 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
if (!outSeekStream)
return E_FAIL;
const UInt64 nextPos = outArchive.Pos;
RINOK(outSeekStream->Seek(-(Int64)(nextPos - headerPos), STREAM_SEEK_CUR, NULL));
RINOK(outSeekStream->Seek(-(Int64)(nextPos - headerPos), STREAM_SEEK_CUR, NULL))
outArchive.Pos = headerPos;
item.PackSize = copyCoderSpec->TotalSize;
RINOK(outArchive.WriteHeader(item));
RINOK(outArchive.WriteHeader(item))
// if (numPasses >= 10) // for debug
if (outArchive.Pos == dataPos)
@@ -454,7 +461,7 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
const UInt64 alignedSize = nextPos - dataPos;
if (alignedSize != 0)
{
RINOK(outSeekStream->Seek(alignedSize, STREAM_SEEK_CUR, NULL));
RINOK(outSeekStream->Seek((Int64)alignedSize, STREAM_SEEK_CUR, NULL))
outArchive.Pos += alignedSize;
}
break;
@@ -462,12 +469,11 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
// size of header was changed.
// we remove data after header and try new attempt, if required
CMyComPtr<IInStream> fileSeekStream;
fileInStream->QueryInterface(IID_IInStream, (void **)&fileSeekStream);
Z7_DECL_CMyComPtr_QI_FROM(IInStream, fileSeekStream, fileInStream)
if (!fileSeekStream)
return E_FAIL;
RINOK(fileSeekStream->Seek(0, STREAM_SEEK_SET, NULL));
RINOK(outSeekStream->SetSize(outArchive.Pos));
RINOK(InStream_SeekToBegin(fileSeekStream))
RINOK(outSeekStream->SetSize(outArchive.Pos))
if (item.PackSize == 0)
break;
}
@@ -476,7 +482,7 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
complexity += item.PackSize;
fileInStream.Release();
RINOK(updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK));
RINOK(updateCallback->SetOperationResult(NArchive::NUpdate::NOperationResult::kOK))
}
else
{
@@ -518,7 +524,7 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
item.UID = existItem.UID;
item.GID = existItem.GID;
RINOK(outArchive.WriteHeader(item));
RINOK(outArchive.WriteHeader(item))
size = existItem.Get_PackSize_Aligned();
pos = existItem.Get_DataPos();
}
@@ -530,10 +536,12 @@ HRESULT UpdateArchive(IInStream *inStream, ISequentialOutStream *outStream,
if (size != 0)
{
RINOK(inStream->Seek((Int64)pos, STREAM_SEEK_SET, NULL));
RINOK(InStream_SeekSet(inStream, pos))
streamSpec->Init(size);
if (outSeekStream && setRestriction)
RINOK(setRestriction->SetRestriction(0, 0))
// 22.00 : we copy Residual data from old archive to new archive instead of zeroing
RINOK(copyCoder->Code(inStreamLimited, outStream, NULL, NULL, progress));
RINOK(copyCoder->Code(inStreamLimited, outStream, NULL, NULL, progress))
if (copyCoderSpec->TotalSize != size)
return E_FAIL;
outArchive.Pos += size;

View File

@@ -1,7 +1,7 @@
// TarUpdate.h
#ifndef __TAR_UPDATE_H
#define __TAR_UPDATE_H
#ifndef ZIP7_INC_TAR_UPDATE_H
#define ZIP7_INC_TAR_UPDATE_H
#include "../IArchive.h"