Update to 7-Zip Version 21.02

This commit is contained in:
Tino Reichardt
2021-05-13 16:39:14 +02:00
parent 3724ecfedc
commit 48fa49f76c
620 changed files with 35032 additions and 10925 deletions

View File

@@ -5,8 +5,26 @@
#include "../Common/MyWindows.h"
#define _my_IO_REPARSE_TAG_MOUNT_POINT (0xA0000003L)
#define _my_IO_REPARSE_TAG_SYMLINK (0xA000000CL)
#define _my_IO_REPARSE_TAG_LX_SYMLINK (0xA000001DL)
#define _my_SYMLINK_FLAG_RELATIVE 1
// what the meaning of that FLAG or field (2)?
#define _my_LX_SYMLINK_FLAG 2
#ifdef _WIN32
#if defined(_WIN32) && !defined(UNDER_CE)
#include <winioctl.h>
#include <WinIoCtl.h>
#endif
#else
#include <sys/types.h>
#include <sys/stat.h>
#endif
#include "../Common/MyString.h"
@@ -14,19 +32,17 @@
#include "Defs.h"
#define _my_IO_REPARSE_TAG_MOUNT_POINT (0xA0000003L)
#define _my_IO_REPARSE_TAG_SYMLINK (0xA000000CL)
HRESULT GetLastError_noZero_HRESULT();
#define _my_SYMLINK_FLAG_RELATIVE 1
#define my_FSCTL_SET_REPARSE_POINT CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 41, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) // REPARSE_DATA_BUFFER
#define my_FSCTL_GET_REPARSE_POINT CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 42, METHOD_BUFFERED, FILE_ANY_ACCESS) // REPARSE_DATA_BUFFER
#define my_FSCTL_SET_REPARSE_POINT CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 41, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) // REPARSE_DATA_BUFFER
#define my_FSCTL_GET_REPARSE_POINT CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 42, METHOD_BUFFERED, FILE_ANY_ACCESS) // REPARSE_DATA_BUFFER
#define my_FSCTL_DELETE_REPARSE_POINT CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 43, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) // REPARSE_DATA_BUFFER
namespace NWindows {
namespace NFile {
#if defined(_WIN32) && !defined(UNDER_CE)
bool FillLinkData(CByteBuffer &dest, const wchar_t *path, bool isSymLink);
bool FillLinkData(CByteBuffer &dest, const wchar_t *path, bool isSymLink, bool isWSL);
#endif
struct CReparseShortInfo
@@ -44,28 +60,50 @@ struct CReparseAttr
UString SubsName;
UString PrintName;
AString WslName;
bool HeaderError;
bool TagIsUnknown;
bool MinorError;
DWORD ErrorCode;
CReparseAttr(): Tag(0), Flags(0) {}
// Parse()
// returns true and (errorCode = 0), if (correct MOUNT_POINT or SYMLINK)
// returns false and (errorCode = ERROR_REPARSE_TAG_MISMATCH), if not (MOUNT_POINT or SYMLINK)
bool Parse(const Byte *p, size_t size, DWORD &errorCode);
// returns (true) and (ErrorCode = 0), if (it'a correct known link)
// returns (false) and (ErrorCode = ERROR_REPARSE_TAG_INVALID), if unknown tag
bool Parse(const Byte *p, size_t size);
bool IsMountPoint() const { return Tag == _my_IO_REPARSE_TAG_MOUNT_POINT; } // it's Junction
bool IsSymLink_Win() const { return Tag == _my_IO_REPARSE_TAG_SYMLINK; }
bool IsSymLink_WSL() const { return Tag == _my_IO_REPARSE_TAG_LX_SYMLINK; }
bool IsRelative_Win() const { return Flags == _my_SYMLINK_FLAG_RELATIVE; }
bool IsRelative_WSL() const
{
if (WslName.IsEmpty())
return true;
char c = WslName[0];
return !IS_PATH_SEPAR(c);
}
bool IsMountPoint() const { return Tag == _my_IO_REPARSE_TAG_MOUNT_POINT; } // it's Junction
bool IsSymLink() const { return Tag == _my_IO_REPARSE_TAG_SYMLINK; }
bool IsRelative() const { return Flags == _my_SYMLINK_FLAG_RELATIVE; }
// bool IsVolume() const;
bool IsOkNamePair() const;
UString GetPath() const;
};
#ifdef _WIN32
namespace NIO {
bool GetReparseData(CFSTR path, CByteBuffer &reparseData, BY_HANDLE_FILE_INFORMATION *fileInfo = NULL);
bool SetReparseData(CFSTR path, bool isDir, const void *data, DWORD size);
bool DeleteReparseData(CFSTR path);
class CFileBase
class CFileBase MY_UNCOPYABLE
{
protected:
HANDLE _handle;
@@ -94,13 +132,14 @@ public:
}
public:
bool PreserveATime;
#ifdef SUPPORT_DEVICE_FILE
bool IsDeviceFile;
bool SizeDefined;
UInt64 Size; // it can be larger than real available size
#endif
CFileBase(): _handle(INVALID_HANDLE_VALUE) {};
CFileBase(): _handle(INVALID_HANDLE_VALUE), PreserveATime(false) {};
~CFileBase() { Close(); }
bool Close() throw();
@@ -118,6 +157,7 @@ public:
static bool GetFileInformation(CFSTR path, BY_HANDLE_FILE_INFORMATION *info)
{
// probably it can work for complex paths: unsupported by another things
NIO::CFileBase file;
if (!file.Create(path, 0, FILE_SHARE_READ, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS))
return false;
@@ -189,6 +229,7 @@ public:
bool Read1(void *data, UInt32 size, UInt32 &processedSize) throw();
bool ReadPart(void *data, UInt32 size, UInt32 &processedSize) throw();
bool Read(void *data, UInt32 size, UInt32 &processedSize) throw();
bool ReadFull(void *data, size_t size, size_t &processedSize) throw();
};
class COutFile: public CFileBase
@@ -207,6 +248,83 @@ public:
bool SetLength(UInt64 length) throw();
};
}}}
}
#else // _WIN32
namespace NIO {
bool GetReparseData(CFSTR path, CByteBuffer &reparseData);
// bool SetReparseData(CFSTR path, bool isDir, const void *data, DWORD size);
// parameters are in reverse order of symlink() function !!!
bool SetSymLink(CFSTR from, CFSTR to);
bool SetSymLink_UString(CFSTR from, const UString &to);
class CFileBase
{
protected:
int _handle;
bool OpenBinary(const char *name, int flags);
public:
bool PreserveATime;
CFileBase(): _handle(-1), PreserveATime(false) {};
~CFileBase() { Close(); }
bool Close();
bool GetLength(UInt64 &length) const;
off_t seek(off_t distanceToMove, int moveMethod) const;
off_t seekToBegin() const throw();
// bool SeekToBegin() throw();
int my_fstat(struct stat *st) const { return fstat(_handle, st); }
};
class CInFile: public CFileBase
{
public:
bool Open(const char *name);
bool OpenShared(const char *name, bool shareForWrite);
ssize_t read_part(void *data, size_t size) throw();
// ssize_t read_full(void *data, size_t size, size_t &processed);
bool ReadFull(void *data, size_t size, size_t &processedSize) throw();
};
class COutFile: public CFileBase
{
bool CTime_defined;
bool ATime_defined;
bool MTime_defined;
FILETIME CTime;
FILETIME ATime;
FILETIME MTime;
AString Path;
ssize_t write_part(const void *data, size_t size) throw();
public:
COutFile():
CTime_defined(false),
ATime_defined(false),
MTime_defined(false)
{}
bool Close();
bool Create(const char *name, bool createAlways);
bool Open(const char *name, DWORD creationDisposition);
ssize_t write_full(const void *data, size_t size, size_t &processed) throw();
bool SetLength(UInt64 length) throw();
bool SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime) throw();
bool SetMTime(const FILETIME *mTime) throw();
};
}
#endif // _WIN32
}}
#endif