This commit is contained in:
Igor Pavlov
2017-08-29 20:49:43 +01:00
committed by Kornel
parent 2efa10565a
commit b5dc853b24
110 changed files with 4714 additions and 1700 deletions

View File

@@ -988,7 +988,7 @@ if (askExtractMode == NArchive::NExtract::NAskMode::kExtract && !_testMode)
|| !pathParts.IsEmpty()
|| !(_removePartsForAltStreams || _pathMode == NExtract::NPathMode::kNoPathsAlt))
#endif
Correct_FsPath(_pathMode == NExtract::NPathMode::kAbsPaths, pathParts, _item.MainIsDir);
Correct_FsPath(_pathMode == NExtract::NPathMode::kAbsPaths, _keepAndReplaceEmptyDirPrefixes, pathParts, _item.MainIsDir);
#ifdef SUPPORT_ALT_STREAMS
@@ -1542,7 +1542,7 @@ STDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 opRes)
NumFiles++;
if (!_stdOutMode && _extractMode && _fi.AttribDefined)
SetFileAttrib(_diskFilePath, _fi.Attrib);
SetFileAttrib_PosixHighDetect(_diskFilePath, _fi.Attrib);
RINOK(_extractCallback2->SetOperationResult(opRes, BoolToInt(_encrypted)));

View File

@@ -172,6 +172,7 @@ class CArchiveExtractCallback:
FString _dirPathPrefix_Full;
NExtract::NPathMode::EEnum _pathMode;
NExtract::NOverwriteMode::EEnum _overwriteMode;
bool _keepAndReplaceEmptyDirPrefixes; // replace them to "_";
#ifndef _SFX
@@ -278,11 +279,13 @@ public:
void InitForMulti(bool multiArchives,
NExtract::NPathMode::EEnum pathMode,
NExtract::NOverwriteMode::EEnum overwriteMode)
NExtract::NOverwriteMode::EEnum overwriteMode,
bool keepAndReplaceEmptyDirPrefixes)
{
_multiArchives = multiArchives;
_pathMode = pathMode;
_overwriteMode = overwriteMode;
_keepAndReplaceEmptyDirPrefixes = keepAndReplaceEmptyDirPrefixes;
NumFolders = NumFiles = NumAltStreams = UnpackSize = AltStreams_UnpackSize = 0;
}

View File

@@ -2376,15 +2376,7 @@ static UInt32 GetNumThreadsNext(unsigned i, UInt32 numThreads)
static bool AreSameMethodNames(const char *fullName, const char *shortName)
{
for (;;)
{
char c2 = *shortName++;
if (c2 == 0)
return true;
char c1 = *fullName++;
if (MyCharLower_Ascii(c1) != MyCharLower_Ascii(c2))
return false;
}
return StringsAreEqualNoCase_Ascii(fullName, shortName);
}
@@ -2545,27 +2537,24 @@ static const char * const k_PF[] =
#endif
static void PrintSize(AString &s, UInt64 ptr)
static void PrintSize(AString &s, UInt64 v)
{
UInt64 v = ptr;
UInt64 t = v >> 40;
UInt64 g = v >> 30;
UInt64 m = v >> 20;
UInt64 k = v >> 10;
UInt32 d = (UInt32)v;
char c = 0;
if (t >= 1000) { d = (UInt32)t; c = 'T'; }
else if (g >= 1000) { d = (UInt32)g; c = 'G'; }
else if (m >= 1000) { d = (UInt32)m; c = 'M'; }
else if (k >= 10) { d = (UInt32)k; c = 'K'; }
s.Add_UInt32(d);
// s += ' ';
if ((v & 0x3FF) == 0) { v >>= 10; c = 'K';
if ((v & 0x3FF) == 0) { v >>= 10; c = 'M';
if ((v & 0x3FF) == 0) { v >>= 10; c = 'G';
if ((v & 0x3FF) == 0) { v >>= 10; c = 'T';
}}}}
else
{
PrintHex(s, v);
return;
}
char temp[32];
ConvertUInt64ToString(v, temp);
s += temp;
if (c)
s += c;
// PrintHex(s, (DWORD_PTR)v);
}
@@ -2631,12 +2620,19 @@ static void SysInfo_To_String(AString &s, const SYSTEM_INFO &si)
s += " ";
DWORD_PTR minAdd = (DWORD_PTR)si.lpMinimumApplicationAddress;
if (minAdd != (1 << 16))
UInt64 maxSize = (UInt64)(DWORD_PTR)si.lpMaximumApplicationAddress + 1;
const UInt32 kReserveSize = ((UInt32)1 << 16);
if (minAdd != kReserveSize)
{
PrintSize(s, minAdd);
s += "-";
}
PrintSize(s, (UInt64)(DWORD_PTR)si.lpMaximumApplicationAddress + 1);
else
{
if ((maxSize & (kReserveSize - 1)) == 0)
maxSize += kReserveSize;
}
PrintSize(s, maxSize);
}
#ifndef _WIN64
@@ -3006,26 +3002,34 @@ HRESULT Bench(
UInt32 complexity = 10000;
const UInt32 *checkSum = NULL;
{
for (unsigned i = 0; i < ARRAY_SIZE(g_Hash); i++)
unsigned i;
for (i = 0; i < ARRAY_SIZE(g_Hash); i++)
{
const CBenchHash &h = g_Hash[i];
AString s (h.Name);
AString hProp;
int propPos = s.Find(':');
AString benchMethod (h.Name);
AString benchProps;
int propPos = benchMethod.Find(':');
if (propPos >= 0)
{
hProp = s.Ptr(propPos + 1);
s.DeleteFrom(propPos);
benchProps = benchMethod.Ptr(propPos + 1);
benchMethod.DeleteFrom(propPos);
}
if (AreSameMethodNames(s, methodName))
if (AreSameMethodNames(benchMethod, methodName))
{
complexity = h.Complex;
checkSum = &h.CheckSum;
if (method.PropsString.IsEqualTo_Ascii_NoCase(hProp))
break;
if (benchProps.IsEmpty()
|| benchMethod.IsEqualTo_Ascii_NoCase("crc32") && benchProps == "8" && method.PropsString.IsEmpty()
|| method.PropsString.IsPrefixedBy_Ascii_NoCase(benchProps))
{
complexity = h.Complex;
checkSum = &h.CheckSum;
if (method.PropsString.IsEqualTo_Ascii_NoCase(benchProps))
break;
}
}
}
if (i == ARRAY_SIZE(g_Hash))
return E_NOTIMPL;
}
f.NewLine();
@@ -3316,18 +3320,35 @@ HRESULT Bench(
bool needSetComplexity = true;
if (!methodName.IsEqualTo_Ascii_NoCase("LZMA"))
{
for (unsigned i = 0; i < ARRAY_SIZE(g_Bench); i++)
unsigned i;
for (i = 0; i < ARRAY_SIZE(g_Bench); i++)
{
const CBenchMethod &h = g_Bench[i];
if (AreSameMethodNames(h.Name, methodName))
AString benchMethod (h.Name);
AString benchProps;
int propPos = benchMethod.Find(':');
if (propPos >= 0)
{
callback.BenchProps.EncComplex = h.EncComplex;
callback.BenchProps.DecComplexCompr = h.DecComplexCompr;
callback.BenchProps.DecComplexUnc = h.DecComplexUnc;;
needSetComplexity = false;
break;
benchProps = benchMethod.Ptr(propPos + 1);
benchMethod.DeleteFrom(propPos);
}
if (AreSameMethodNames(benchMethod, methodName))
{
if (benchProps.IsEmpty()
|| benchProps == "x5" && method.PropsString.IsEmpty()
|| method.PropsString.IsPrefixedBy_Ascii_NoCase(benchProps))
{
callback.BenchProps.EncComplex = h.EncComplex;
callback.BenchProps.DecComplexCompr = h.DecComplexCompr;
callback.BenchProps.DecComplexUnc = h.DecComplexUnc;;
needSetComplexity = false;
break;
}
}
}
if (i == ARRAY_SIZE(g_Bench))
return E_NOTIMPL;
}
if (needSetComplexity)
callback.BenchProps.SetLzmaCompexity();

View File

@@ -39,7 +39,6 @@ using namespace NWindows;
#define kArcIncludeSwitches " -an -ai"
#define kHashIncludeSwitches " -i"
#define kStopSwitchParsing " --"
#define kLargePagesDisable " -slp-"
extern HWND g_HWND;
@@ -94,8 +93,8 @@ static HRESULT Call7zGui(const UString &params,
static void AddLagePagesSwitch(UString &params)
{
if (!ReadLockMemoryEnable())
params += kLargePagesDisable;
if (ReadLockMemoryEnable())
params += " -slp";
}
class CRandNameGenerator
@@ -289,6 +288,7 @@ void Benchmark(bool totalMode)
UString params ('b');
if (totalMode)
params += " -mm=*";
AddLagePagesSwitch(params);
HRESULT result = Call7zGui(params, false, NULL);
if (result != S_OK)
ErrorMessageHRESULT(result);

View File

@@ -21,7 +21,7 @@ struct CDirItemsStat
UInt64 NumErrors;
UInt64 Get_NumItems() const { return NumDirs + NumFiles + NumAltStreams; }
// UInt64 Get_NumItems() const { return NumDirs + NumFiles + NumAltStreams; }
UInt64 Get_NumDataItems() const { return NumFiles + NumAltStreams; }
UInt64 GetTotalBytes() const { return FilesSize + AltStreamsSize; }
@@ -43,6 +43,30 @@ struct CDirItemsStat
{}
};
struct CDirItemsStat2: public CDirItemsStat
{
UInt64 Anti_NumDirs;
UInt64 Anti_NumFiles;
UInt64 Anti_NumAltStreams;
// UInt64 Get_NumItems() const { return Anti_NumDirs + Anti_NumFiles + Anti_NumAltStreams + CDirItemsStat::Get_NumItems(); }
UInt64 Get_NumDataItems2() const { return Anti_NumFiles + Anti_NumAltStreams + CDirItemsStat::Get_NumDataItems(); }
bool IsEmpty() const { return CDirItemsStat::IsEmpty()
&& 0 == Anti_NumDirs
&& 0 == Anti_NumFiles
&& 0 == Anti_NumAltStreams; }
CDirItemsStat2():
Anti_NumDirs(0),
Anti_NumFiles(0),
Anti_NumAltStreams(0)
{}
};
#define INTERFACE_IDirItemsCallback(x) \
virtual HRESULT ScanError(const FString &path, DWORD systemError) x; \
virtual HRESULT ScanProgress(const CDirItemsStat &st, const FString &path, bool isDir) x; \

View File

@@ -343,6 +343,7 @@ static HRESULT EnumerateAltStreams(
const NWildcard::CCensorNode &curNode,
int phyParent, int logParent, const FString &fullPath,
const UStringVector &addArchivePrefix, // prefix from curNode
bool addAllItems,
CDirItems &dirItems)
{
NFind::CStreamEnumerator enumerator(fullPath);
@@ -363,6 +364,10 @@ static HRESULT EnumerateAltStreams(
addArchivePrefixNew.Back() += reducedName;
if (curNode.CheckPathToRoot(false, addArchivePrefixNew, true))
continue;
if (!addAllItems)
if (!curNode.CheckPathToRoot(true, addArchivePrefixNew, true))
continue;
NFind::CFileInfo fi2 = fi;
fi2.Name += us2fs(reducedName);
fi2.Size = si.Size;
@@ -413,6 +418,8 @@ static HRESULT EnumerateForItem(
}
int dirItemIndex = -1;
bool addAllSubStreams = false;
if (curNode.CheckPathToRoot(true, addArchivePrefixNew, !fi.IsDir()))
{
int secureIndex = -1;
@@ -427,6 +434,8 @@ static HRESULT EnumerateForItem(
dirItems.AddDirFileInfo(phyParent, logParent, secureIndex, fi);
if (fi.IsDir())
enterToSubFolders2 = true;
addAllSubStreams = true;
}
#ifndef UNDER_CE
@@ -434,7 +443,9 @@ static HRESULT EnumerateForItem(
{
RINOK(EnumerateAltStreams(fi, curNode, phyParent, logParent,
phyPrefix + fi.Name,
addArchivePrefixNew, dirItems));
addArchivePrefixNew,
addAllSubStreams,
dirItems));
}
if (dirItemIndex >= 0)
@@ -643,7 +654,9 @@ static HRESULT EnumerateDirItems(
UStringVector pathParts;
pathParts.Add(fs2us(fi.Name));
RINOK(EnumerateAltStreams(fi, curNode, phyParent, logParent,
fullPath, pathParts, dirItems));
fullPath, pathParts,
true, /* addAllSubStreams */
dirItems));
}
#endif

View File

@@ -279,7 +279,9 @@ HRESULT Extract(
CArchiveExtractCallback *ecs = new CArchiveExtractCallback;
CMyComPtr<IArchiveExtractCallback> ec(ecs);
bool multi = (numArcs > 1);
ecs->InitForMulti(multi, options.PathMode, options.OverwriteMode);
ecs->InitForMulti(multi, options.PathMode, options.OverwriteMode,
false // keepEmptyDirParts
);
#ifndef _SFX
ecs->SetHashMethods(hash);
#endif

View File

@@ -146,6 +146,9 @@ static void CorrectUnsupportedName(UString &name)
static void Correct_PathPart(UString &s)
{
// "." and ".."
if (s.IsEmpty())
return;
if (s[0] == '.' && (s[1] == 0 || s[1] == '.' && s[2] == 0))
s.Empty();
#ifdef _WIN32
@@ -172,7 +175,7 @@ UString Get_Correct_FsFile_Name(const UString &name)
}
void Correct_FsPath(bool absIsAllowed, UStringVector &parts, bool isDir)
void Correct_FsPath(bool absIsAllowed, bool keepAndReplaceEmptyPrefixes, UStringVector &parts, bool isDir)
{
unsigned i = 0;
@@ -181,6 +184,7 @@ void Correct_FsPath(bool absIsAllowed, UStringVector &parts, bool isDir)
#if defined(_WIN32) && !defined(UNDER_CE)
bool isDrive = false;
#endif
if (parts[0].IsEmpty())
{
i = 1;
@@ -191,7 +195,7 @@ void Correct_FsPath(bool absIsAllowed, UStringVector &parts, bool isDir)
if (parts.Size() > 2 && parts[2] == L"?")
{
i = 3;
if (parts.Size() > 3 && NWindows::NFile::NName::IsDrivePath2(parts[3]))
if (parts.Size() > 3 && NWindows::NFile::NName::IsDrivePath2(parts[3]))
{
isDrive = true;
i = 4;
@@ -220,6 +224,9 @@ void Correct_FsPath(bool absIsAllowed, UStringVector &parts, bool isDir)
#endif
}
if (i != 0)
keepAndReplaceEmptyPrefixes = false;
for (; i < parts.Size();)
{
UString &s = parts[i];
@@ -228,15 +235,17 @@ void Correct_FsPath(bool absIsAllowed, UStringVector &parts, bool isDir)
if (s.IsEmpty())
{
if (isDir || i != parts.Size() - 1)
{
parts.Delete(i);
continue;
}
if (!keepAndReplaceEmptyPrefixes)
if (isDir || i != parts.Size() - 1)
{
parts.Delete(i);
continue;
}
s = k_EmptyReplaceName;
}
else
{
keepAndReplaceEmptyPrefixes = false;
#ifdef _WIN32
CorrectUnsupportedName(s);
#endif

View File

@@ -12,7 +12,19 @@ void Correct_AltStream_Name(UString &s);
// replaces unsuported characters, and replaces "." , ".." and "" to "[]"
UString Get_Correct_FsFile_Name(const UString &name);
void Correct_FsPath(bool absIsAllowed, UStringVector &parts, bool isDir);
/*
Correct_FsPath() corrects path parts to prepare it for File System operations.
It also corrects empty path parts like "\\\\":
- frontal empty path parts : it removes them or changes them to "_"
- another empty path parts : it removes them
if (absIsAllowed && path is absolute) : it removes empty path parts after start absolute path prefix marker
else
{
if (!keepAndReplaceEmptyPrefixes) : it removes empty path parts
if ( keepAndReplaceEmptyPrefixes) : it changes each empty frontal path part to "_"
}
*/
void Correct_FsPath(bool absIsAllowed, bool keepAndReplaceEmptyPrefixes, UStringVector &parts, bool isDir);
UString MakePathFromParts(const UStringVector &parts);

View File

@@ -19,12 +19,16 @@
using namespace NWindows;
static const char g_WinAttribChars[16 + 1] = "RHS8DAdNTsLCOnE_";
static const unsigned kNumWinAtrribFlags = 21;
static const char g_WinAttribChars[kNumWinAtrribFlags + 1] = "RHS8DAdNTsLCOIEV.X.PU";
/*
FILE_ATTRIBUTE_
0 READONLY
1 HIDDEN
2 SYSTEM
3 (Volume label - obsolete)
4 DIRECTORY
5 ARCHIVE
6 DEVICE
@@ -34,12 +38,19 @@ static const char g_WinAttribChars[16 + 1] = "RHS8DAdNTsLCOnE_";
10 REPARSE_POINT
11 COMPRESSED
12 OFFLINE
13 NOT_CONTENT_INDEXED
13 NOT_CONTENT_INDEXED (I - Win10 attrib/Explorer)
14 ENCRYPTED
16 VIRTUAL
15 INTEGRITY_STREAM (V - ReFS Win8/Win2012)
16 VIRTUAL (reserved)
17 NO_SCRUB_DATA (X - ReFS Win8/Win2012 attrib)
18 RECALL_ON_OPEN or EA
19 PINNED
20 UNPINNED
21 STRICTLY_SEQUENTIAL
22 RECALL_ON_DATA_ACCESS
*/
static const char kPosixTypes[16] = { '0', 'p', 'c', '3', 'd', '5', 'b', '7', '-', '9', 'l', 'B', 's', 'D', 'E', 'F' };
#define MY_ATTR_CHAR(a, n, c) ((a) & (1 << (n))) ? c : '-';
@@ -65,24 +76,57 @@ static void ConvertPosixAttribToString(char *s, UInt32 a) throw()
}
}
void ConvertWinAttribToString(char *s, UInt32 wa) throw()
{
for (int i = 0; i < 16; i++)
if ((wa & (1 << i)) && i != 7)
*s++ = g_WinAttribChars[i];
*s = 0;
// we support p7zip trick that stores posix attributes in high 16 bits, and 0x8000 flag
// we also support ZIP archives created in Unix, that store posix attributes in high 16 bits without 0x8000 flag
/*
some programs store posix attributes in high 16 bits.
p7zip - stores additional 0x8000 flag marker.
macos - stores additional 0x4000 flag marker.
info-zip - no additional marker.
*/
// if (wa & 0x8000)
if ((wa >> 16) != 0)
bool isPosix = ((wa & 0xF0000000) != 0);
UInt32 posix = 0;
if (isPosix)
{
posix = wa >> 16;
wa &= (UInt32)0x3FFF;
}
for (unsigned i = 0; i < kNumWinAtrribFlags; i++)
{
UInt32 flag = (1 << i);
if ((wa & flag) != 0)
{
char c = g_WinAttribChars[i];
if (c != '.')
{
wa &= ~flag;
// if (i != 7) // we can disable N (NORMAL) printing
*s++ = c;
}
}
}
if (wa != 0)
{
*s++ = ' ';
ConvertPosixAttribToString(s, wa >> 16);
ConvertUInt32ToHex8Digits(wa, s);
s += strlen(s);
}
*s = 0;
if (isPosix)
{
*s++ = ' ';
ConvertPosixAttribToString(s, posix);
}
}
void ConvertPropertyToShortString2(char *dest, const PROPVARIANT &prop, PROPID propID, int level) throw()
{
*dest = 0;

View File

@@ -657,38 +657,74 @@ static HRESULT Compress(
FOR_VECTOR (i, updatePairs2)
{
const CUpdatePair2 &up = updatePairs2[i];
if (up.NewData)
// 17.01: anti-item is (up.NewData && (p.UseArcProps in most cases))
if (up.NewData && !up.UseArcProps)
{
CDirItemsStat &stat = stat2.NewData;
const CDirItem &di = dirItems.Items[up.DirIndex];
if (di.IsDir())
stat.NumDirs++;
else if (di.IsAltStream)
if (up.ExistOnDisk())
{
stat.NumAltStreams++;
stat.AltStreamsSize += di.Size;
}
else
{
stat.NumFiles++;
stat.FilesSize += di.Size;
CDirItemsStat2 &stat = stat2.NewData;
const CDirItem &di = dirItems.Items[up.DirIndex];
if (di.IsDir())
{
if (up.IsAnti)
stat.Anti_NumDirs++;
else
stat.NumDirs++;
}
else if (di.IsAltStream)
{
if (up.IsAnti)
stat.Anti_NumAltStreams++;
else
{
stat.NumAltStreams++;
stat.AltStreamsSize += di.Size;
}
}
else
{
if (up.IsAnti)
stat.Anti_NumFiles++;
else
{
stat.NumFiles++;
stat.FilesSize += di.Size;
}
}
}
}
else if (up.ArcIndex >= 0)
{
CDirItemsStat &stat = stat2.OldData;
CDirItemsStat2 &stat = *(up.NewData ? &stat2.NewData : &stat2.OldData);
const CArcItem &ai = arcItems[up.ArcIndex];
if (ai.IsDir)
stat.NumDirs++;
{
if (up.IsAnti)
stat.Anti_NumDirs++;
else
stat.NumDirs++;
}
else if (ai.IsAltStream)
{
stat.NumAltStreams++;
stat.AltStreamsSize += ai.Size;
if (up.IsAnti)
stat.Anti_NumAltStreams++;
else
{
stat.NumAltStreams++;
stat.AltStreamsSize += ai.Size;
}
}
else
{
stat.NumFiles++;
stat.FilesSize += ai.Size;
if (up.IsAnti)
stat.Anti_NumFiles++;
else
{
stat.NumFiles++;
stat.FilesSize += ai.Size;
}
}
}
}
@@ -1592,8 +1628,18 @@ HRESULT UpdateArchive(
{
if (processedItems[i] != 0 || dirItem.Size == 0)
{
RINOK(callback->DeletingAfterArchiving(phyPath, false));
DeleteFileAlways(phyPath);
NFind::CFileInfo fileInfo;
if (fileInfo.Find(phyPath))
{
// maybe we must exclude also files with archive name: "a a.7z * -sdel"
if (fileInfo.Size == dirItem.Size
&& CompareFileTime(&fileInfo.MTime, &dirItem.MTime) == 0
&& CompareFileTime(&fileInfo.CTime, &dirItem.CTime) == 0)
{
RINOK(callback->DeletingAfterArchiving(phyPath, false));
DeleteFileAlways(phyPath);
}
}
}
else
{

View File

@@ -17,13 +17,13 @@
struct CArcToDoStat
{
CDirItemsStat NewData;
CDirItemsStat OldData;
CDirItemsStat DeleteData;
CDirItemsStat2 NewData;
CDirItemsStat2 OldData;
CDirItemsStat2 DeleteData;
UInt64 Get_NumDataItems_Total() const
{
return NewData.Get_NumDataItems() + OldData.Get_NumDataItems();
return NewData.Get_NumDataItems2() + OldData.Get_NumDataItems2();
}
};

View File

@@ -48,9 +48,14 @@ namespace NCompression
UString Options;
UString EncryptionMethod;
void Reset_BlockLogSize()
{
BlockLogSize = (UInt32)(Int32)-1;
}
void ResetForLevelChange()
{
BlockLogSize = NumThreads = Level = Dictionary = Order = UInt32(-1);
BlockLogSize = NumThreads = Level = Dictionary = Order = (UInt32)(Int32)-1;
Method.Empty();
// Options.Empty();
// EncryptionMethod.Empty();