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.cpp | |
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.cpp')
-rw-r--r-- | CPP/Windows/FileFind.cpp | 133 |
1 files changed, 108 insertions, 25 deletions
diff --git a/CPP/Windows/FileFind.cpp b/CPP/Windows/FileFind.cpp index 591f8df..c655759 100644 --- a/CPP/Windows/FileFind.cpp +++ b/CPP/Windows/FileFind.cpp | |||
@@ -7,6 +7,8 @@ | |||
7 | #ifndef _WIN32 | 7 | #ifndef _WIN32 |
8 | #include <fcntl.h> /* Definition of AT_* constants */ | 8 | #include <fcntl.h> /* Definition of AT_* constants */ |
9 | #include "TimeUtils.h" | 9 | #include "TimeUtils.h" |
10 | // for major | ||
11 | // #include <sys/sysmacros.h> | ||
10 | #endif | 12 | #endif |
11 | 13 | ||
12 | #include "FileFind.h" | 14 | #include "FileFind.h" |
@@ -62,24 +64,35 @@ bool MyGetDiskFreeSpace(CFSTR rootPath, UInt64 &clusterSize, UInt64 &totalSize, | |||
62 | 64 | ||
63 | namespace NFind { | 65 | namespace NFind { |
64 | 66 | ||
67 | /* | ||
68 | #ifdef _WIN32 | ||
65 | #define MY_CLEAR_FILETIME(ft) ft.dwLowDateTime = ft.dwHighDateTime = 0; | 69 | #define MY_CLEAR_FILETIME(ft) ft.dwLowDateTime = ft.dwHighDateTime = 0; |
70 | #else | ||
71 | #define MY_CLEAR_FILETIME(ft) ft.tv_sec = 0; ft.tv_nsec = 0; | ||
72 | #endif | ||
73 | */ | ||
66 | 74 | ||
67 | void CFileInfoBase::ClearBase() throw() | 75 | void CFileInfoBase::ClearBase() throw() |
68 | { | 76 | { |
69 | Size = 0; | 77 | Size = 0; |
70 | MY_CLEAR_FILETIME(CTime); | 78 | FiTime_Clear(CTime); |
71 | MY_CLEAR_FILETIME(ATime); | 79 | FiTime_Clear(ATime); |
72 | MY_CLEAR_FILETIME(MTime); | 80 | FiTime_Clear(MTime); |
81 | |||
82 | #ifdef _WIN32 | ||
73 | Attrib = 0; | 83 | Attrib = 0; |
74 | // ReparseTag = 0; | 84 | // ReparseTag = 0; |
75 | IsAltStream = false; | 85 | IsAltStream = false; |
76 | IsDevice = false; | 86 | IsDevice = false; |
77 | 87 | #else | |
78 | #ifndef _WIN32 | 88 | dev = 0; |
79 | ino = 0; | 89 | ino = 0; |
80 | nlink = 0; | ||
81 | mode = 0; | 90 | mode = 0; |
82 | #endif | 91 | nlink = 0; |
92 | uid = 0; | ||
93 | gid = 0; | ||
94 | rdev = 0; | ||
95 | #endif | ||
83 | } | 96 | } |
84 | 97 | ||
85 | bool CFileInfo::IsDots() const throw() | 98 | bool CFileInfo::IsDots() const throw() |
@@ -439,6 +452,20 @@ also we support paths that are not supported by FindFirstFile: | |||
439 | bool CFileInfo::Find(CFSTR path, bool followLink) | 452 | bool CFileInfo::Find(CFSTR path, bool followLink) |
440 | { | 453 | { |
441 | #ifdef SUPPORT_DEVICE_FILE | 454 | #ifdef SUPPORT_DEVICE_FILE |
455 | |||
456 | if (IS_PATH_SEPAR(path[0]) && | ||
457 | IS_PATH_SEPAR(path[1]) && | ||
458 | path[2] == '.' && | ||
459 | path[3] == 0) | ||
460 | { | ||
461 | // 22.00 : it's virtual directory for devices | ||
462 | // IsDevice = true; | ||
463 | ClearBase(); | ||
464 | Name = path + 2; | ||
465 | Attrib = FILE_ATTRIBUTE_DIRECTORY; | ||
466 | return true; | ||
467 | } | ||
468 | |||
442 | if (IsDevicePath(path)) | 469 | if (IsDevicePath(path)) |
443 | { | 470 | { |
444 | ClearBase(); | 471 | ClearBase(); |
@@ -469,7 +496,7 @@ bool CFileInfo::Find(CFSTR path, bool followLink) | |||
469 | 496 | ||
470 | #if defined(_WIN32) && !defined(UNDER_CE) | 497 | #if defined(_WIN32) && !defined(UNDER_CE) |
471 | 498 | ||
472 | int colonPos = FindAltStreamColon(path); | 499 | const int colonPos = FindAltStreamColon(path); |
473 | if (colonPos >= 0 && path[(unsigned)colonPos + 1] != 0) | 500 | if (colonPos >= 0 && path[(unsigned)colonPos + 1] != 0) |
474 | { | 501 | { |
475 | UString streamName = fs2us(path + (unsigned)colonPos); | 502 | UString streamName = fs2us(path + (unsigned)colonPos); |
@@ -635,7 +662,7 @@ bool CFileInfo::Find(CFSTR path, bool followLink) | |||
635 | return Fill_From_ByHandleFileInfo(path); | 662 | return Fill_From_ByHandleFileInfo(path); |
636 | } | 663 | } |
637 | 664 | ||
638 | bool CFileInfo::Fill_From_ByHandleFileInfo(CFSTR path) | 665 | bool CFileInfoBase::Fill_From_ByHandleFileInfo(CFSTR path) |
639 | { | 666 | { |
640 | BY_HANDLE_FILE_INFORMATION info; | 667 | BY_HANDLE_FILE_INFORMATION info; |
641 | if (!NIO::CFileBase::GetFileInformation(path, &info)) | 668 | if (!NIO::CFileBase::GetFileInformation(path, &info)) |
@@ -950,13 +977,6 @@ static const char *Get_Name_from_Path(CFSTR path) throw() | |||
950 | } | 977 | } |
951 | 978 | ||
952 | 979 | ||
953 | void timespec_To_FILETIME(const MY_ST_TIMESPEC &ts, FILETIME &ft) | ||
954 | { | ||
955 | UInt64 v = NTime::UnixTime64ToFileTime64(ts.tv_sec) + ((UInt64)ts.tv_nsec / 100); | ||
956 | ft.dwLowDateTime = (DWORD)v; | ||
957 | ft.dwHighDateTime = (DWORD)(v >> 32); | ||
958 | } | ||
959 | |||
960 | UInt32 Get_WinAttribPosix_From_PosixMode(UInt32 mode) | 980 | UInt32 Get_WinAttribPosix_From_PosixMode(UInt32 mode) |
961 | { | 981 | { |
962 | UInt32 attrib = S_ISDIR(mode) ? | 982 | UInt32 attrib = S_ISDIR(mode) ? |
@@ -984,7 +1004,7 @@ UInt32 Get_WinAttrib_From_stat(const struct stat &st) | |||
984 | 1004 | ||
985 | void CFileInfo::SetFrom_stat(const struct stat &st) | 1005 | void CFileInfo::SetFrom_stat(const struct stat &st) |
986 | { | 1006 | { |
987 | IsDevice = false; | 1007 | // IsDevice = false; |
988 | 1008 | ||
989 | if (S_ISDIR(st.st_mode)) | 1009 | if (S_ISDIR(st.st_mode)) |
990 | { | 1010 | { |
@@ -995,7 +1015,7 @@ void CFileInfo::SetFrom_stat(const struct stat &st) | |||
995 | Size = (UInt64)st.st_size; // for a symbolic link, size = size of filename | 1015 | Size = (UInt64)st.st_size; // for a symbolic link, size = size of filename |
996 | } | 1016 | } |
997 | 1017 | ||
998 | Attrib = Get_WinAttribPosix_From_PosixMode(st.st_mode); | 1018 | // Attrib = Get_WinAttribPosix_From_PosixMode(st.st_mode); |
999 | 1019 | ||
1000 | // NTime::UnixTimeToFileTime(st.st_ctime, CTime); | 1020 | // NTime::UnixTimeToFileTime(st.st_ctime, CTime); |
1001 | // NTime::UnixTimeToFileTime(st.st_mtime, MTime); | 1021 | // NTime::UnixTimeToFileTime(st.st_mtime, MTime); |
@@ -1010,27 +1030,89 @@ void CFileInfo::SetFrom_stat(const struct stat &st) | |||
1010 | */ | 1030 | */ |
1011 | // timespec_To_FILETIME(st.st_birthtimespec, CTime); | 1031 | // timespec_To_FILETIME(st.st_birthtimespec, CTime); |
1012 | // #else | 1032 | // #else |
1013 | timespec_To_FILETIME(st.st_ctimespec, CTime); | 1033 | // timespec_To_FILETIME(st.st_ctimespec, CTime); |
1014 | // #endif | 1034 | // #endif |
1015 | timespec_To_FILETIME(st.st_mtimespec, MTime); | 1035 | // timespec_To_FILETIME(st.st_mtimespec, MTime); |
1016 | timespec_To_FILETIME(st.st_atimespec, ATime); | 1036 | // timespec_To_FILETIME(st.st_atimespec, ATime); |
1037 | CTime = st.st_ctimespec; | ||
1038 | MTime = st.st_mtimespec; | ||
1039 | ATime = st.st_atimespec; | ||
1040 | |||
1017 | #else | 1041 | #else |
1018 | timespec_To_FILETIME(st.st_ctim, CTime); | 1042 | // timespec_To_FILETIME(st.st_ctim, CTime, &CTime_ns100); |
1019 | timespec_To_FILETIME(st.st_mtim, MTime); | 1043 | // timespec_To_FILETIME(st.st_mtim, MTime, &MTime_ns100); |
1020 | timespec_To_FILETIME(st.st_atim, ATime); | 1044 | // timespec_To_FILETIME(st.st_atim, ATime, &ATime_ns100); |
1045 | CTime = st.st_ctim; | ||
1046 | MTime = st.st_mtim; | ||
1047 | ATime = st.st_atim; | ||
1048 | |||
1021 | #endif | 1049 | #endif |
1022 | 1050 | ||
1023 | dev = st.st_dev; | 1051 | dev = st.st_dev; |
1024 | ino = st.st_ino; | 1052 | ino = st.st_ino; |
1025 | nlink = st.st_nlink; | ||
1026 | mode = st.st_mode; | 1053 | mode = st.st_mode; |
1054 | nlink = st.st_nlink; | ||
1055 | uid = st.st_uid; | ||
1056 | gid = st.st_gid; | ||
1057 | rdev = st.st_rdev; | ||
1058 | |||
1059 | /* | ||
1060 | printf("\n sizeof timespec = %d", (int)sizeof(timespec)); | ||
1061 | printf("\n sizeof st_rdev = %d", (int)sizeof(rdev)); | ||
1062 | printf("\n sizeof st_ino = %d", (int)sizeof(ino)); | ||
1063 | printf("\n sizeof mode_t = %d", (int)sizeof(mode_t)); | ||
1064 | printf("\n sizeof nlink_t = %d", (int)sizeof(nlink_t)); | ||
1065 | printf("\n sizeof uid_t = %d", (int)sizeof(uid_t)); | ||
1066 | printf("\n"); | ||
1067 | */ | ||
1068 | /* | ||
1069 | printf("\n st_rdev = %llx", (long long)rdev); | ||
1070 | printf("\n st_dev = %llx", (long long)dev); | ||
1071 | printf("\n dev : major = %5x minor = %5x", (unsigned)major(dev), (unsigned)minor(dev)); | ||
1072 | printf("\n st_ino = %lld", (long long)(ino)); | ||
1073 | printf("\n rdev : major = %5x minor = %5x", (unsigned)major(rdev), (unsigned)minor(rdev)); | ||
1074 | printf("\n size = %lld \n", (long long)(Size)); | ||
1075 | printf("\n"); | ||
1076 | */ | ||
1077 | } | ||
1078 | |||
1079 | /* | ||
1080 | int Uid_To_Uname(uid_t uid, AString &name) | ||
1081 | { | ||
1082 | name.Empty(); | ||
1083 | struct passwd *passwd; | ||
1084 | |||
1085 | if (uid != 0 && uid == cached_no_such_uid) | ||
1086 | { | ||
1087 | *uname = xstrdup (""); | ||
1088 | return; | ||
1089 | } | ||
1090 | |||
1091 | if (!cached_uname || uid != cached_uid) | ||
1092 | { | ||
1093 | passwd = getpwuid (uid); | ||
1094 | if (passwd) | ||
1095 | { | ||
1096 | cached_uid = uid; | ||
1097 | assign_string (&cached_uname, passwd->pw_name); | ||
1098 | } | ||
1099 | else | ||
1100 | { | ||
1101 | cached_no_such_uid = uid; | ||
1102 | *uname = xstrdup (""); | ||
1103 | return; | ||
1104 | } | ||
1105 | } | ||
1106 | *uname = xstrdup (cached_uname); | ||
1027 | } | 1107 | } |
1108 | */ | ||
1028 | 1109 | ||
1029 | bool CFileInfo::Find_DontFill_Name(CFSTR path, bool followLink) | 1110 | bool CFileInfo::Find_DontFill_Name(CFSTR path, bool followLink) |
1030 | { | 1111 | { |
1031 | struct stat st; | 1112 | struct stat st; |
1032 | if (MY__lstat(path, &st, followLink) != 0) | 1113 | if (MY__lstat(path, &st, followLink) != 0) |
1033 | return false; | 1114 | return false; |
1115 | // printf("\nFind_DontFill_Name : name=%s\n", path); | ||
1034 | SetFrom_stat(st); | 1116 | SetFrom_stat(st); |
1035 | return true; | 1117 | return true; |
1036 | } | 1118 | } |
@@ -1232,6 +1314,7 @@ bool CEnumerator::Fill_FileInfo(const CDirEntry &de, CFileInfo &fileInfo, bool f | |||
1232 | 1314 | ||
1233 | if (res != 0) | 1315 | if (res != 0) |
1234 | return false; | 1316 | return false; |
1317 | // printf("\nname=%s\n", de.Name.Ptr()); | ||
1235 | fileInfo.SetFrom_stat(st); | 1318 | fileInfo.SetFrom_stat(st); |
1236 | fileInfo.Name = de.Name; | 1319 | fileInfo.Name = de.Name; |
1237 | return true; | 1320 | return true; |