MCPcopy Create free account
hub / github.com/Icinga/icinga2 / GlobHelper

Function GlobHelper

lib/base/utility.cpp:392–430  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

390
391#ifdef _WIN32
392static bool GlobHelper(const String& pathSpec, int type, std::vector<String>& files, std::vector<String>& dirs)
393{
394 HANDLE handle;
395 WIN32_FIND_DATA wfd;
396
397 handle = FindFirstFile(pathSpec.CStr(), &wfd);
398
399 if (handle == INVALID_HANDLE_VALUE) {
400 DWORD errorCode = GetLastError();
401
402 if (errorCode == ERROR_FILE_NOT_FOUND)
403 return false;
404
405 BOOST_THROW_EXCEPTION(win32_error()
406 << boost::errinfo_api_function("FindFirstFile")
407 << errinfo_win32_error(errorCode)
408 << boost::errinfo_file_name(pathSpec));
409 }
410
411 do {
412 if (strcmp(wfd.cFileName, ".") == 0 || strcmp(wfd.cFileName, "..") == 0)
413 continue;
414
415 String path = Utility::DirName(pathSpec) + "/" + wfd.cFileName;
416
417 if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (type & GlobDirectory))
418 dirs.push_back(path);
419 else if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (type & GlobFile))
420 files.push_back(path);
421 } while (FindNextFile(handle, &wfd));
422
423 if (!FindClose(handle)) {
424 BOOST_THROW_EXCEPTION(win32_error()
425 << boost::errinfo_api_function("FindClose")
426 << errinfo_win32_error(GetLastError()));
427 }
428
429 return true;
430}
431#endif /* _WIN32 */
432
433#ifndef _WIN32

Callers 1

GlobMethod · 0.85

Calls 4

win32_errorClass · 0.85
DirNameFunction · 0.85
CStrMethod · 0.80
push_backMethod · 0.80

Tested by

no test coverage detected