[icinga-checkins] icinga.org: icinga2/master: Windows bugfixes for Utility:: DirName and Utility::Glob.

git at icinga.org git at icinga.org
Sat Feb 9 11:42:29 CET 2013


Module: icinga2
Branch: master
Commit: 85e469019f8e9e02b28354df21ddaf3564e905d7
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=85e469019f8e9e02b28354df21ddaf3564e905d7

Author: Gunnar Beutner <gunnar at beutner.name>
Date:   Sat Feb  9 10:43:11 2013 +0100

Windows bugfixes for Utility::DirName and Utility::Glob.

---

 lib/base/utility.cpp |   21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/lib/base/utility.cpp b/lib/base/utility.cpp
index 49707a7..f22f611 100644
--- a/lib/base/utility.cpp
+++ b/lib/base/utility.cpp
@@ -267,12 +267,27 @@ bool Utility::Match(const String& pattern, const String& text)
  */
 String Utility::DirName(const String& path)
 {
-	char *dir = strdup(path.CStr());
-	String result;
+	char *dir;
+
+#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)
 		BOOST_THROW_EXCEPTION(bad_alloc());
 
+	String result;
+
 #ifndef _WIN32
 	result = dirname(dir);
 #else /* _WIN32 */
@@ -464,7 +479,7 @@ bool Utility::Glob(const String& pathSpec, const function<void (const String&)>&
 	}
 
 	do {
-		callback(wfd.cFileName);
+		callback(DirName(pathSpec) + "/" + wfd.cFileName);
 	} while (FindNextFile(handle, &wfd));
 
 	if (!FindClose(handle))





More information about the icinga-checkins mailing list