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

@@ -7,13 +7,23 @@
#ifndef _WIN32
// #include <grp.h>
// #include <pwd.h>
// for major minor:
// BSD: <sys/types.h>
/*
inclusion of <sys/sysmacros.h> by <sys/types.h> is deprecated since glibc 2.25.
Since glibc 2.3.3, macros have been aliases for three GNU-specific
functions: gnu_dev_makedev(), gnu_dev_major(), and gnu_dev_minor()
*/
// for major()/minor():
#include <sys/types.h>
#if defined(__FreeBSD__) || defined(BSD) || defined(__APPLE__)
#else
#ifndef major
#include <sys/sysmacros.h>
#endif
#endif
#ifndef _7ZIP_ST
#endif // _WIN32
#ifndef Z7_ST
#include "../../../Windows/Synchronization.h"
#endif
@@ -32,14 +42,14 @@
#include "UpdateCallback.h"
#if defined(_WIN32) && !defined(UNDER_CE)
#define _USE_SECURITY_CODE
#define Z7_USE_SECURITY_CODE
#include "../../../Windows/SecurityUtils.h"
#endif
using namespace NWindows;
using namespace NFile;
#ifndef _7ZIP_ST
#ifndef Z7_ST
static NSynchronization::CCriticalSection g_CriticalSection;
#define MT_LOCK NSynchronization::CCriticalSectionLock lock(g_CriticalSection);
#else
@@ -47,25 +57,11 @@ static NSynchronization::CCriticalSection g_CriticalSection;
#endif
#ifdef _USE_SECURITY_CODE
#ifdef Z7_USE_SECURITY_CODE
bool InitLocalPrivileges();
#endif
CArchiveUpdateCallback::CArchiveUpdateCallback():
_hardIndex_From((UInt32)(Int32)-1),
Callback(NULL),
DirItems(NULL),
ParentDirItem(NULL),
Arc(NULL),
ArcItems(NULL),
UpdatePairs(NULL),
NewNames(NULL),
CommentIndex(-1),
Comment(NULL),
PreserveATime(false),
ShareForWrite(false),
StopAfterOpenError(false),
@@ -88,29 +84,42 @@ CArchiveUpdateCallback::CArchiveUpdateCallback():
Need_LatestMTime(false),
LatestMTime_Defined(false),
ProcessedItemsStatuses(NULL)
Callback(NULL),
DirItems(NULL),
ParentDirItem(NULL),
Arc(NULL),
ArcItems(NULL),
UpdatePairs(NULL),
NewNames(NULL),
Comment(NULL),
CommentIndex(-1),
ProcessedItemsStatuses(NULL),
_hardIndex_From((UInt32)(Int32)-1)
{
#ifdef _USE_SECURITY_CODE
#ifdef Z7_USE_SECURITY_CODE
_saclEnabled = InitLocalPrivileges();
#endif
}
STDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 size)
Z7_COM7F_IMF(CArchiveUpdateCallback::SetTotal(UInt64 size))
{
COM_TRY_BEGIN
return Callback->SetTotal(size);
COM_TRY_END
}
STDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 *completeValue)
Z7_COM7F_IMF(CArchiveUpdateCallback::SetCompleted(const UInt64 *completeValue))
{
COM_TRY_BEGIN
return Callback->SetCompleted(completeValue);
COM_TRY_END
}
STDMETHODIMP CArchiveUpdateCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)
Z7_COM7F_IMF(CArchiveUpdateCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize))
{
COM_TRY_BEGIN
return Callback->SetRatioInfo(inSize, outSize);
@@ -131,17 +140,17 @@ static const CStatProp kProps[] =
{ NULL, kpidIsAnti, VT_BOOL}
};
STDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG **)
Z7_COM7F_IMF(CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG **)
{
return CStatPropEnumerator::CreateEnumerator(kProps, ARRAY_SIZE(kProps), enumerator);
return CStatPropEnumerator::CreateEnumerator(kProps, Z7_ARRAY_SIZE(kProps), enumerator);
}
*/
STDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 index,
Int32 *newData, Int32 *newProps, UInt32 *indexInArchive)
Z7_COM7F_IMF(CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 index,
Int32 *newData, Int32 *newProps, UInt32 *indexInArchive))
{
COM_TRY_BEGIN
RINOK(Callback->CheckBreak());
RINOK(Callback->CheckBreak())
const CUpdatePair2 &up = (*UpdatePairs)[index];
if (newData) *newData = BoolToInt(up.NewData);
if (newProps) *newProps = BoolToInt(up.NewProps);
@@ -156,7 +165,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 index,
}
STDMETHODIMP CArchiveUpdateCallback::GetRootProp(PROPID propID, PROPVARIANT *value)
Z7_COM7F_IMF(CArchiveUpdateCallback::GetRootProp(PROPID propID, PROPVARIANT *value))
{
NCOM::CPropVariant prop;
switch (propID)
@@ -172,14 +181,14 @@ STDMETHODIMP CArchiveUpdateCallback::GetRootProp(PROPID propID, PROPVARIANT *val
return S_OK;
}
STDMETHODIMP CArchiveUpdateCallback::GetParent(UInt32 /* index */, UInt32 *parent, UInt32 *parentType)
Z7_COM7F_IMF(CArchiveUpdateCallback::GetParent(UInt32 /* index */, UInt32 *parent, UInt32 *parentType))
{
*parentType = NParentType::kDir;
*parent = (UInt32)(Int32)-1;
return S_OK;
}
STDMETHODIMP CArchiveUpdateCallback::GetNumRawProps(UInt32 *numProps)
Z7_COM7F_IMF(CArchiveUpdateCallback::GetNumRawProps(UInt32 *numProps))
{
*numProps = 0;
if (StoreNtSecurity)
@@ -187,25 +196,27 @@ STDMETHODIMP CArchiveUpdateCallback::GetNumRawProps(UInt32 *numProps)
return S_OK;
}
STDMETHODIMP CArchiveUpdateCallback::GetRawPropInfo(UInt32 /* index */, BSTR *name, PROPID *propID)
Z7_COM7F_IMF(CArchiveUpdateCallback::GetRawPropInfo(UInt32 /* index */, BSTR *name, PROPID *propID))
{
*name = NULL;
*propID = kpidNtSecure;
return S_OK;
}
STDMETHODIMP CArchiveUpdateCallback::GetRootRawProp(PROPID
#ifdef _USE_SECURITY_CODE
Z7_COM7F_IMF(CArchiveUpdateCallback::GetRootRawProp(PROPID
propID
#endif
, const void **data, UInt32 *dataSize, UInt32 *propType)
, const void **data, UInt32 *dataSize, UInt32 *propType))
{
*data = 0;
#ifndef Z7_USE_SECURITY_CODE
UNUSED_VAR(propID)
#endif
*data = NULL;
*dataSize = 0;
*propType = 0;
if (!StoreNtSecurity)
return S_OK;
#ifdef _USE_SECURITY_CODE
#ifdef Z7_USE_SECURITY_CODE
if (propID == kpidNtSecure)
{
if (StdInMode)
@@ -229,12 +240,10 @@ STDMETHODIMP CArchiveUpdateCallback::GetRootRawProp(PROPID
return S_OK;
}
// #ifdef _USE_SECURITY_CODE
// #endif
STDMETHODIMP CArchiveUpdateCallback::GetRawProp(UInt32 index, PROPID propID, const void **data, UInt32 *dataSize, UInt32 *propType)
Z7_COM7F_IMF(CArchiveUpdateCallback::GetRawProp(UInt32 index, PROPID propID, const void **data, UInt32 *dataSize, UInt32 *propType))
{
*data = 0;
*data = NULL;
*dataSize = 0;
*propType = 0;
@@ -261,7 +270,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetRawProp(UInt32 index, PROPID propID, con
const CDirItem &di = DirItems->Items[(unsigned)up.DirIndex];
#endif
#ifdef _USE_SECURITY_CODE
#ifdef Z7_USE_SECURITY_CODE
if (propID == kpidNtSecure)
{
if (!StoreNtSecurity)
@@ -345,7 +354,7 @@ static UString GetRelativePath(const UString &to, const UString &from)
#endif
STDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
Z7_COM7F_IMF(CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value))
{
COM_TRY_BEGIN
const CUpdatePair2 &up = (*UpdatePairs)[index];
@@ -381,7 +390,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PR
CReparseAttr attr;
if (attr.Parse(di.ReparseData, di.ReparseData.Size()))
{
UString simpleName = attr.GetPath();
const UString simpleName = attr.GetPath();
if (!attr.IsSymLink_WSL() && attr.IsRelative_Win())
prop = simpleName;
else
@@ -480,6 +489,11 @@ STDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PR
// case kpidShortName: prop = di.ShortName; break;
#else
#if defined(__APPLE__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
case kpidDeviceMajor:
/*
printf("\ndi.mode = %o\n", di.mode);
@@ -495,6 +509,10 @@ STDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PR
prop = (UInt32)minor(di.rdev);
break;
#if defined(__APPLE__)
#pragma GCC diagnostic pop
#endif
// case kpidDevice: if (S_ISCHR(di.mode) || S_ISBLK(di.mode)) prop = (UInt64)(di.rdev); break;
case kpidUserId: if (StoreOwnerId) prop = (UInt32)di.uid; break;
@@ -515,22 +533,22 @@ STDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PR
COM_TRY_END
}
#ifndef _7ZIP_ST
static NSynchronization::CCriticalSection CS;
#ifndef Z7_ST
static NSynchronization::CCriticalSection g_CS;
#endif
void CArchiveUpdateCallback::UpdateProcessedItemStatus(unsigned dirIndex)
{
if (ProcessedItemsStatuses)
{
#ifndef _7ZIP_ST
NSynchronization::CCriticalSectionLock lock(CS);
#ifndef Z7_ST
NSynchronization::CCriticalSectionLock lock(g_CS);
#endif
ProcessedItemsStatuses[dirIndex] = 1;
}
}
STDMETHODIMP CArchiveUpdateCallback::GetStream2(UInt32 index, ISequentialInStream **inStream, UInt32 mode)
Z7_COM7F_IMF(CArchiveUpdateCallback::GetStream2(UInt32 index, ISequentialInStream **inStream, UInt32 mode))
{
COM_TRY_BEGIN
*inStream = NULL;
@@ -538,7 +556,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetStream2(UInt32 index, ISequentialInStrea
if (!up.NewData)
return E_FAIL;
RINOK(Callback->CheckBreak());
RINOK(Callback->CheckBreak())
// RINOK(Callback->Finalize());
bool isDir = IsDir(up);
@@ -550,7 +568,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetStream2(UInt32 index, ISequentialInStrea
name = (*ArcItems)[(unsigned)up.ArcIndex].Name;
else if (up.DirIndex >= 0)
name = DirItems->GetLogPath((unsigned)up.DirIndex);
RINOK(Callback->GetStream(name, isDir, true, mode));
RINOK(Callback->GetStream(name, isDir, true, mode))
/* 9.33: fixed. Handlers expect real stream object for files, even for anti-file.
so we return empty stream */
@@ -565,7 +583,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetStream2(UInt32 index, ISequentialInStrea
return S_OK;
}
RINOK(Callback->GetStream(DirItems->GetLogPath((unsigned)up.DirIndex), isDir, false, mode));
RINOK(Callback->GetStream(DirItems->GetLogPath((unsigned)up.DirIndex), isDir, false, mode))
if (isDir)
return S_OK;
@@ -636,8 +654,9 @@ STDMETHODIMP CArchiveUpdateCallback::GetStream2(UInt32 index, ISequentialInStrea
#endif
inStreamSpec->SupportHardLinks = StoreHardLinks;
inStreamSpec->Set_PreserveATime(PreserveATime
|| mode == NUpdateNotifyOp::kAnalyze); // 22.00 : we don't change access time in Analyze pass.
const bool preserveATime = (PreserveATime
|| mode == NUpdateNotifyOp::kAnalyze); // 22.00 : we don't change access time in Analyze pass.
inStreamSpec->Set_PreserveATime(preserveATime);
const FString path = DirItems->GetPhyPath((unsigned)up.DirIndex);
_openFiles_Indexes.Add(index);
@@ -651,12 +670,32 @@ STDMETHODIMP CArchiveUpdateCallback::GetStream2(UInt32 index, ISequentialInStrea
if (!inStreamSpec->OpenShared(path, ShareForWrite))
{
const DWORD error = ::GetLastError();
const HRESULT hres = Callback->OpenFileError(path, error);
if (StopAfterOpenError)
bool isOpen = false;
if (preserveATime)
{
inStreamSpec->Set_PreserveATime(false);
isOpen = inStreamSpec->OpenShared(path, ShareForWrite);
}
if (!isOpen)
{
const DWORD error = ::GetLastError();
const HRESULT hres = Callback->OpenFileError(path, error);
if (hres == S_OK || hres == S_FALSE)
if (StopAfterOpenError ||
// v23: we check also for some critical errors:
#ifdef _WIN32
error == ERROR_NO_SYSTEM_RESOURCES
#else
error == EMFILE
#endif
)
{
if (error == 0)
return E_FAIL;
return HRESULT_FROM_WIN32(error);
return hres;
}
return hres;
}
}
/*
@@ -675,7 +714,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetStream2(UInt32 index, ISequentialInStrea
inStreamSpec->ReloadProps();
}
// #if defined(USE_WIN_FILE) || !defined(_WIN32)
// #if defined(Z7_FILE_STREAMS_USE_WIN_FILE) || !defined(_WIN32)
if (StoreHardLinks)
{
CStreamFileProps props;
@@ -687,8 +726,8 @@ STDMETHODIMP CArchiveUpdateCallback::GetStream2(UInt32 index, ISequentialInStrea
pair.Key1 = props.VolID;
pair.Key2 = props.FileID_Low;
pair.Value = index;
unsigned numItems = _map.Size();
unsigned pairIndex = _map.AddToUniqueSorted2(pair);
const unsigned numItems = _map.Size();
const unsigned pairIndex = _map.AddToUniqueSorted2(pair);
if (numItems == _map.Size())
{
// const CKeyKeyValPair &pair2 = _map.Pairs[pairIndex];
@@ -710,14 +749,14 @@ STDMETHODIMP CArchiveUpdateCallback::GetStream2(UInt32 index, ISequentialInStrea
COM_TRY_END
}
STDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 opRes)
Z7_COM7F_IMF(CArchiveUpdateCallback::SetOperationResult(Int32 opRes))
{
COM_TRY_BEGIN
return Callback->SetOperationResult(opRes);
COM_TRY_END
}
STDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream)
Z7_COM7F_IMF(CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream))
{
COM_TRY_BEGIN
return GetStream2(index, inStream,
@@ -727,7 +766,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream
COM_TRY_END
}
STDMETHODIMP CArchiveUpdateCallback::ReportOperation(UInt32 indexType, UInt32 index, UInt32 op)
Z7_COM7F_IMF(CArchiveUpdateCallback::ReportOperation(UInt32 indexType, UInt32 index, UInt32 op))
{
COM_TRY_BEGIN
@@ -766,9 +805,9 @@ STDMETHODIMP CArchiveUpdateCallback::ReportOperation(UInt32 indexType, UInt32 in
}
else if (Arc)
{
RINOK(Arc->GetItem_Path(index, s2));
RINOK(Arc->GetItem_Path(index, s2))
s = s2;
RINOK(Archive_IsItem_Dir(Arc->Archive, index, isDir));
RINOK(Archive_IsItem_Dir(Arc->Archive, index, isDir))
}
}
}
@@ -787,7 +826,7 @@ STDMETHODIMP CArchiveUpdateCallback::ReportOperation(UInt32 indexType, UInt32 in
COM_TRY_END
}
STDMETHODIMP CArchiveUpdateCallback::ReportExtractResult(UInt32 indexType, UInt32 index, Int32 opRes)
Z7_COM7F_IMF(CArchiveUpdateCallback::ReportExtractResult(UInt32 indexType, UInt32 index, Int32 opRes))
{
COM_TRY_BEGIN
@@ -821,12 +860,12 @@ STDMETHODIMP CArchiveUpdateCallback::ReportExtractResult(UInt32 indexType, UInt3
s = (*ArcItems)[index].Name;
else if (Arc)
{
RINOK(Arc->GetItem_Path(index, s2));
RINOK(Arc->GetItem_Path(index, s2))
s = s2;
}
if (Archive)
{
RINOK(Archive_GetItemBoolProp(Archive, index, kpidEncrypted, isEncrypted));
RINOK(Archive_GetItemBoolProp(Archive, index, kpidEncrypted, isEncrypted))
}
}
}
@@ -844,7 +883,7 @@ STDMETHODIMP CArchiveUpdateCallback::ReportExtractResult(UInt32 indexType, UInt3
/*
STDMETHODIMP CArchiveUpdateCallback::DoNeedArcProp(PROPID propID, Int32 *answer)
Z7_COM7F_IMF(CArchiveUpdateCallback::DoNeedArcProp(PROPID propID, Int32 *answer))
{
*answer = 0;
if (Need_ArcMTime_Report && propID == kpidComboMTime)
@@ -852,7 +891,7 @@ STDMETHODIMP CArchiveUpdateCallback::DoNeedArcProp(PROPID propID, Int32 *answer)
return S_OK;
}
STDMETHODIMP CArchiveUpdateCallback::ReportProp(UInt32 indexType, UInt32 index, PROPID propID, const PROPVARIANT *value)
Z7_COM7F_IMF(CArchiveUpdateCallback::ReportProp(UInt32 indexType, UInt32 index, PROPID propID, const PROPVARIANT *value))
{
if (indexType == NArchive::NEventIndexType::kArcProp)
{
@@ -875,19 +914,19 @@ STDMETHODIMP CArchiveUpdateCallback::ReportProp(UInt32 indexType, UInt32 index,
return Callback->ReportProp(indexType, index, propID, value);
}
STDMETHODIMP CArchiveUpdateCallback::ReportRawProp(UInt32 indexType, UInt32 index,
PROPID propID, const void *data, UInt32 dataSize, UInt32 propType)
Z7_COM7F_IMF(CArchiveUpdateCallback::ReportRawProp(UInt32 indexType, UInt32 index,
PROPID propID, const void *data, UInt32 dataSize, UInt32 propType))
{
return Callback->ReportRawProp(indexType, index, propID, data, dataSize, propType);
}
STDMETHODIMP CArchiveUpdateCallback::ReportFinished(UInt32 indexType, UInt32 index, Int32 opRes)
Z7_COM7F_IMF(CArchiveUpdateCallback::ReportFinished(UInt32 indexType, UInt32 index, Int32 opRes))
{
return Callback->ReportFinished(indexType, index, opRes);
}
*/
STDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)
Z7_COM7F_IMF(CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size))
{
if (VolumesSizes.Size() == 0)
return S_FALSE;
@@ -897,7 +936,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)
return S_OK;
}
STDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream)
Z7_COM7F_IMF(CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream))
{
COM_TRY_BEGIN
char temp[16];
@@ -906,7 +945,7 @@ STDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOu
while (res.Len() < 2)
res.InsertAtFront(FTEXT('0'));
FString fileName = VolName;
fileName += '.';
fileName.Add_Dot();
fileName += res;
fileName += VolExt;
COutFileStream *streamSpec = new COutFileStream;
@@ -918,14 +957,14 @@ STDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOu
COM_TRY_END
}
STDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)
Z7_COM7F_IMF(CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password))
{
COM_TRY_BEGIN
return Callback->CryptoGetTextPassword2(passwordIsDefined, password);
COM_TRY_END
}
STDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword(BSTR *password)
Z7_COM7F_IMF(CArchiveUpdateCallback::CryptoGetTextPassword(BSTR *password))
{
COM_TRY_BEGIN
return Callback->CryptoGetTextPassword(password);
@@ -945,7 +984,7 @@ HRESULT CArchiveUpdateCallback::InFileStream_On_Error(UINT_PTR val, DWORD error)
{
if (_openFiles_Indexes[i] == index)
{
RINOK(Callback->ReadingFileError(_openFiles_Paths[i], error));
RINOK(Callback->ReadingFileError(_openFiles_Paths[i], error))
break;
}
}