diff options
author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2022-06-20 00:00:00 +0000 |
---|---|---|
committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2023-12-17 13:35:20 +0500 |
commit | a3e1d227377188734b82f023f96f8e25dc40f3e6 (patch) | |
tree | 23cad8d47eb23d26ea727b4f7f4a65124f724065 /CPP/Windows/FileFind.h | |
parent | f19f813537c7aea1c20749c914e756b54a9c3cf5 (diff) | |
download | 7zip-22.00.tar.gz 7zip-22.00.tar.bz2 7zip-22.00.zip |
22.0022.00
Diffstat (limited to 'CPP/Windows/FileFind.h')
-rw-r--r-- | CPP/Windows/FileFind.h | 95 |
1 files changed, 65 insertions, 30 deletions
diff --git a/CPP/Windows/FileFind.h b/CPP/Windows/FileFind.h index 8f28ee3..fcfe02c 100644 --- a/CPP/Windows/FileFind.h +++ b/CPP/Windows/FileFind.h | |||
@@ -9,10 +9,14 @@ | |||
9 | #include <dirent.h> | 9 | #include <dirent.h> |
10 | #endif | 10 | #endif |
11 | 11 | ||
12 | #include "../Common/MyLinux.h" | ||
12 | #include "../Common/MyString.h" | 13 | #include "../Common/MyString.h" |
13 | #include "../Common/MyWindows.h" | 14 | #include "../Common/MyWindows.h" |
15 | |||
14 | #include "Defs.h" | 16 | #include "Defs.h" |
15 | 17 | ||
18 | #include "FileIO.h" | ||
19 | |||
16 | namespace NWindows { | 20 | namespace NWindows { |
17 | namespace NFile { | 21 | namespace NFile { |
18 | namespace NFind { | 22 | namespace NFind { |
@@ -32,6 +36,7 @@ bool DoesFileOrDirExist(CFSTR name); | |||
32 | 36 | ||
33 | DWORD GetFileAttrib(CFSTR path); | 37 | DWORD GetFileAttrib(CFSTR path); |
34 | 38 | ||
39 | #ifdef _WIN32 | ||
35 | 40 | ||
36 | namespace NAttributes | 41 | namespace NAttributes |
37 | { | 42 | { |
@@ -42,21 +47,38 @@ namespace NAttributes | |||
42 | inline bool IsArchived(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ARCHIVE) != 0; } | 47 | inline bool IsArchived(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ARCHIVE) != 0; } |
43 | inline bool IsCompressed(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_COMPRESSED) != 0; } | 48 | inline bool IsCompressed(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_COMPRESSED) != 0; } |
44 | inline bool IsEncrypted(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ENCRYPTED) != 0; } | 49 | inline bool IsEncrypted(DWORD attrib) { return (attrib & FILE_ATTRIBUTE_ENCRYPTED) != 0; } |
50 | |||
51 | inline UInt32 Get_PosixMode_From_WinAttrib(DWORD attrib) | ||
52 | { | ||
53 | UInt32 v = IsDir(attrib) ? MY_LIN_S_IFDIR : MY_LIN_S_IFREG; | ||
54 | /* 21.06: as WSL we allow write permissions (0222) for directories even for (FILE_ATTRIBUTE_READONLY). | ||
55 | So extracting at Linux will be allowed to write files inside (0777) directories. */ | ||
56 | v |= ((IsReadOnly(attrib) && !IsDir(attrib)) ? 0555 : 0777); | ||
57 | return v; | ||
58 | } | ||
45 | } | 59 | } |
46 | 60 | ||
61 | #else | ||
62 | |||
63 | UInt32 Get_WinAttribPosix_From_PosixMode(UInt32 mode); | ||
64 | |||
65 | #endif | ||
66 | |||
47 | class CFileInfoBase | 67 | class CFileInfoBase |
48 | { | 68 | { |
69 | #ifdef _WIN32 | ||
49 | bool MatchesMask(UINT32 mask) const { return ((Attrib & mask) != 0); } | 70 | bool MatchesMask(UINT32 mask) const { return ((Attrib & mask) != 0); } |
71 | #endif | ||
50 | public: | 72 | public: |
51 | UInt64 Size; | 73 | UInt64 Size; |
52 | FILETIME CTime; | 74 | CFiTime CTime; |
53 | FILETIME ATime; | 75 | CFiTime ATime; |
54 | FILETIME MTime; | 76 | CFiTime MTime; |
77 | #ifdef _WIN32 | ||
55 | DWORD Attrib; | 78 | DWORD Attrib; |
56 | bool IsAltStream; | 79 | bool IsAltStream; |
57 | bool IsDevice; | 80 | bool IsDevice; |
58 | 81 | ||
59 | #ifdef _WIN32 | ||
60 | /* | 82 | /* |
61 | #ifdef UNDER_CE | 83 | #ifdef UNDER_CE |
62 | DWORD ObjectID; | 84 | DWORD ObjectID; |
@@ -64,24 +86,25 @@ public: | |||
64 | UINT32 ReparseTag; | 86 | UINT32 ReparseTag; |
65 | #endif | 87 | #endif |
66 | */ | 88 | */ |
67 | #else | 89 | #else |
68 | dev_t dev; | 90 | dev_t dev; /* ID of device containing file */ |
69 | ino_t ino; | 91 | ino_t ino; |
70 | nlink_t nlink; | ||
71 | mode_t mode; | 92 | mode_t mode; |
93 | nlink_t nlink; | ||
94 | uid_t uid; /* user ID of owner */ | ||
95 | gid_t gid; /* group ID of owner */ | ||
96 | dev_t rdev; /* device ID (defined, if S_ISCHR(mode) || S_ISBLK(mode)) */ | ||
72 | // bool Use_lstat; | 97 | // bool Use_lstat; |
73 | #endif | 98 | #endif |
74 | 99 | ||
75 | CFileInfoBase() { ClearBase(); } | 100 | CFileInfoBase() { ClearBase(); } |
76 | void ClearBase() throw(); | 101 | void ClearBase() throw(); |
77 | 102 | ||
78 | void SetAsDir() | 103 | #ifdef _WIN32 |
79 | { | 104 | |
80 | Attrib = FILE_ATTRIBUTE_DIRECTORY; | 105 | bool Fill_From_ByHandleFileInfo(CFSTR path); |
81 | #ifndef _WIN32 | 106 | void SetAsDir() { Attrib = FILE_ATTRIBUTE_DIRECTORY; } // |= (FILE_ATTRIBUTE_UNIX_EXTENSION + (S_IFDIR << 16)); |
82 | Attrib |= (FILE_ATTRIBUTE_UNIX_EXTENSION + (S_IFDIR << 16)); | 107 | void SetAsFile() { Attrib = 0; } |
83 | #endif | ||
84 | } | ||
85 | 108 | ||
86 | bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); } | 109 | bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); } |
87 | bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); } | 110 | bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); } |
@@ -96,13 +119,33 @@ public: | |||
96 | bool IsSystem() const { return MatchesMask(FILE_ATTRIBUTE_SYSTEM); } | 119 | bool IsSystem() const { return MatchesMask(FILE_ATTRIBUTE_SYSTEM); } |
97 | bool IsTemporary() const { return MatchesMask(FILE_ATTRIBUTE_TEMPORARY); } | 120 | bool IsTemporary() const { return MatchesMask(FILE_ATTRIBUTE_TEMPORARY); } |
98 | 121 | ||
99 | #ifndef _WIN32 | 122 | UInt32 GetWinAttrib() const { return Attrib; } |
100 | bool IsPosixLink() const | 123 | UInt32 GetPosixAttrib() const |
101 | { | 124 | { |
102 | const UInt32 mod = Attrib >> 16; | 125 | return NAttributes::Get_PosixMode_From_WinAttrib(Attrib); |
103 | return S_ISLNK(mod); | ||
104 | } | 126 | } |
105 | #endif | 127 | bool Has_Attrib_ReparsePoint() const { return (Attrib & FILE_ATTRIBUTE_REPARSE_POINT) != 0; } |
128 | |||
129 | #else | ||
130 | |||
131 | UInt32 GetPosixAttrib() const { return mode; } | ||
132 | UInt32 GetWinAttrib() const { return Get_WinAttribPosix_From_PosixMode(mode); } | ||
133 | |||
134 | bool IsDir() const { return S_ISDIR(mode); } | ||
135 | void SetAsDir() { mode = S_IFDIR; } | ||
136 | void SetAsFile() { mode = S_IFREG; } | ||
137 | |||
138 | bool IsReadOnly() const | ||
139 | { | ||
140 | // does linux support writing to ReadOnly files? | ||
141 | if ((mode & 0222) == 0) // S_IWUSR in p7zip | ||
142 | return true; | ||
143 | return false; | ||
144 | } | ||
145 | |||
146 | bool IsPosixLink() const { return S_ISLNK(mode); } | ||
147 | |||
148 | #endif | ||
106 | 149 | ||
107 | bool IsOsSymLink() const | 150 | bool IsOsSymLink() const |
108 | { | 151 | { |
@@ -126,7 +169,7 @@ struct CFileInfo: public CFileInfoBase | |||
126 | bool Find_FollowLink(CFSTR path) { return Find(path, true); } | 169 | bool Find_FollowLink(CFSTR path) { return Find(path, true); } |
127 | 170 | ||
128 | #ifdef _WIN32 | 171 | #ifdef _WIN32 |
129 | bool Fill_From_ByHandleFileInfo(CFSTR path); | 172 | // bool Fill_From_ByHandleFileInfo(CFSTR path); |
130 | // bool FollowReparse(CFSTR path, bool isDir); | 173 | // bool FollowReparse(CFSTR path, bool isDir); |
131 | #else | 174 | #else |
132 | bool Find_DontFill_Name(CFSTR path, bool followLink = false); | 175 | bool Find_DontFill_Name(CFSTR path, bool followLink = false); |
@@ -287,16 +330,8 @@ inline UInt32 Get_WinAttrib_From_PosixMode(UInt32 mode) | |||
287 | } | 330 | } |
288 | */ | 331 | */ |
289 | 332 | ||
290 | UInt32 Get_WinAttribPosix_From_PosixMode(UInt32 mode); | ||
291 | |||
292 | // UInt32 Get_WinAttrib_From_stat(const struct stat &st); | 333 | // UInt32 Get_WinAttrib_From_stat(const struct stat &st); |
293 | #if defined(_AIX) | ||
294 | #define MY_ST_TIMESPEC st_timespec | ||
295 | #else | ||
296 | #define MY_ST_TIMESPEC timespec | ||
297 | #endif | ||
298 | 334 | ||
299 | void timespec_To_FILETIME(const MY_ST_TIMESPEC &ts, FILETIME &ft); | ||
300 | 335 | ||
301 | #endif // WIN32 | 336 | #endif // WIN32 |
302 | 337 | ||