|
13 | 13 | #include <fnmatch.h>
|
14 | 14 | #endif
|
15 | 15 |
|
| 16 | +#if !HAVE_DIRENT_D_TYPE |
| 17 | +#define DT_UNKNOWN 0 |
| 18 | +#define DT_DIR 4 |
| 19 | +#define DT_REG 8 |
| 20 | +#define DT_LNK 10 |
| 21 | +#endif |
| 22 | + |
16 | 23 | #include <utility>
|
17 | 24 |
|
18 | 25 | // Do reads/writes in large 256MB chunks.
|
@@ -187,9 +194,9 @@ bool verbMerge::DirectoryFilterDirectories(FilterArgType* findData)
|
187 | 194 | #else // TARGET_WINDOWS
|
188 | 195 | if (findData->d_type == DT_DIR)
|
189 | 196 | {
|
190 |
| - if (strcmp(findData->d_name, ".") == 0) |
| 197 | + if (u16_strcmp(findData->cFileName, W(".")) == 0) |
191 | 198 | return false;
|
192 |
| - if (strcmp(findData->d_name, "..") == 0) |
| 199 | + if (u16_strcmp(findData->cFileName, W("..")) == 0) |
193 | 200 | return false;
|
194 | 201 |
|
195 | 202 | return true;
|
@@ -281,12 +288,47 @@ int verbMerge::FilterDirectory(LPCWSTR dir,
|
281 | 288 | dirent *pEntry = readdir(pDir);
|
282 | 289 | while (pEntry != nullptr)
|
283 | 290 | {
|
284 |
| - if ((fnmatch(searchPatternUtf8.c_str(), pEntry->d_name, 0) == 0) && filter(pEntry)) |
| 291 | + int dirEntryType; |
| 292 | + |
| 293 | +#if HAVE_DIRENT_D_TYPE |
| 294 | + dirEntryType = pEntry->d_type; |
| 295 | +#else |
| 296 | + struct stat sb; |
| 297 | + |
| 298 | + if (fstatat(dirfd(pDir), pEntry->d_name, &sb, 0) == -1) |
| 299 | + { |
| 300 | + continue; |
| 301 | + } |
| 302 | + |
| 303 | + if (S_ISDIR(sb.st_mode)) { |
| 304 | + dirEntryType = DT_DIR; |
| 305 | + } else if (S_ISREG(sb.st_mode)) { |
| 306 | + dirEntryType = DT_REG; |
| 307 | + } else if (S_ISLNK(sb.st_mode)) { |
| 308 | + dirEntryType = DT_LNK; |
| 309 | + } else { |
| 310 | + dirEntryType = DT_UNKNOWN; |
| 311 | + } |
| 312 | +#endif |
| 313 | + if (dirEntryType == DT_UNKNOWN) |
285 | 314 | {
|
286 |
| - FindData findData(pEntry->d_type, ConvertMultiByteToWideChar(pEntry->d_name)); |
287 |
| - first = new findDataList(&findData, first); |
288 |
| - ++elemCount; |
| 315 | + continue; |
289 | 316 | }
|
| 317 | + |
| 318 | + if (fnmatch(searchPatternUtf8.c_str(), pEntry->d_name, 0) != 0) |
| 319 | + { |
| 320 | + continue; |
| 321 | + } |
| 322 | + |
| 323 | + FindData findData(dirEntryType, ConvertMultiByteToWideChar(pEntry->d_name)); |
| 324 | + if (!filter(&findData)) |
| 325 | + { |
| 326 | + continue; |
| 327 | + } |
| 328 | + |
| 329 | + first = new findDataList(&findData, first); |
| 330 | + ++elemCount; |
| 331 | + |
290 | 332 | errno = 0;
|
291 | 333 | pEntry = readdir(pDir);
|
292 | 334 | }
|
|
0 commit comments