mirror of https://github.com/Icinga/icinga2.git
Windows bugfixes for Utility::DirName and Utility::Glob.
This commit is contained in:
parent
06999e40e9
commit
85e469019f
|
@ -267,12 +267,27 @@ bool Utility::Match(const String& pattern, const String& text)
|
||||||
*/
|
*/
|
||||||
String Utility::DirName(const String& path)
|
String Utility::DirName(const String& path)
|
||||||
{
|
{
|
||||||
char *dir = strdup(path.CStr());
|
char *dir;
|
||||||
String result;
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
String dupPath = path;
|
||||||
|
|
||||||
|
/* PathRemoveFileSpec doesn't properly handle forward slashes. */
|
||||||
|
BOOST_FOREACH(char& ch, dupPath) {
|
||||||
|
if (ch == '/')
|
||||||
|
ch = '\\';
|
||||||
|
}
|
||||||
|
|
||||||
|
dir = strdup(dupPath.CStr());
|
||||||
|
#else /* _WIN32 */
|
||||||
|
dir = strdup(path.CStr());
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
if (dir == NULL)
|
if (dir == NULL)
|
||||||
BOOST_THROW_EXCEPTION(bad_alloc());
|
BOOST_THROW_EXCEPTION(bad_alloc());
|
||||||
|
|
||||||
|
String result;
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
result = dirname(dir);
|
result = dirname(dir);
|
||||||
#else /* _WIN32 */
|
#else /* _WIN32 */
|
||||||
|
@ -464,7 +479,7 @@ bool Utility::Glob(const String& pathSpec, const function<void (const String&)>&
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
callback(wfd.cFileName);
|
callback(DirName(pathSpec) + "/" + wfd.cFileName);
|
||||||
} while (FindNextFile(handle, &wfd));
|
} while (FindNextFile(handle, &wfd));
|
||||||
|
|
||||||
if (!FindClose(handle))
|
if (!FindClose(handle))
|
||||||
|
|
Loading…
Reference in New Issue