From c0835935a43b59da043b826bf9ce00d5622560f2 Mon Sep 17 00:00:00 2001 From: David Nichols Date: Sat, 16 Apr 2016 14:44:56 +0200 Subject: [PATCH] refs #761 fixed glob() on windows with a leading path --- doxygen/lang/900_release_notes.dox.tmpl | 3 ++- include/qore/intern/glob.h | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/doxygen/lang/900_release_notes.dox.tmpl b/doxygen/lang/900_release_notes.dox.tmpl index b8f25e5bad..71aa63d971 100644 --- a/doxygen/lang/900_release_notes.dox.tmpl +++ b/doxygen/lang/900_release_notes.dox.tmpl @@ -498,7 +498,8 @@ - fixed a bug where the @ref int_type "int" type restriction would accept any data type at runtime instead of throwing a \c RUNTIME-TYPE-ERROR exception (issue 683) - fixed bugs reporting the current method context with certain @ref Qore::HTTPClient "HTTPClient" methods that would report the @ref Qore::Socket "Socket" class instead (issue 689) - fixed a bug handling aborted HTTP chunked transfers; now any data available for reading on a socket when a chunked transfer is aborted is read instead of having a \c SOCKET-SEND-ERROR thrown when the remote end closes the socket during the transfer (issue 691) - - fixed a bug where SSL send failures did not cause an exception to be thrown in all cases (issue 732) + - fixed a bug with socket handling where SSL send failures did not cause an exception to be thrown in all cases (issue 732) + - fixed a bug on Windows where @ref Qore::glob() returned files matched without the leading path component (issue 761) @section qore_0811 Qore 0.8.11 diff --git a/include/qore/intern/glob.h b/include/qore/intern/glob.h index 813bc6d342..2b08897ca2 100644 --- a/include/qore/intern/glob.h +++ b/include/qore/intern/glob.h @@ -71,8 +71,16 @@ class QoreGlobWin { // normalize the path QoreString path(pattern); - q_normalize_path(path); + // save the original dir name + QoreString orig_dir((const char*)q_dirname(path.c_str())); + printd(0, "glob() dir: '%s'\n", orig_dir.c_str()); + if (orig_dir == ".") + orig_dir.clear(); + else + orig_dir.concat('\\'); + + q_normalize_path(path); char* dirp = q_dirname(path.c_str()); unsigned len = strlen(dirp); QoreString dir(dirp, len, len + 1, QCS_DEFAULT); @@ -83,6 +91,12 @@ class QoreGlobWin { HANDLE h = ::FindFirstFile(dir.getBuffer(), &pfd); ON_BLOCK_EXIT(::FindClose, h); + // remove wildcard to reuse directory name for matches + if (len > 1) + dir.terminate(dir.size() - 3); + else + dir.clear(); + // make regex pattern QoreString str(q_basenameptr(path.c_str())); @@ -105,7 +119,9 @@ class QoreGlobWin { if (pfd.cFileName[0] == '.' && !get_dot) continue; if (qrn->exec(pfd.cFileName, strlen(pfd.cFileName))) { - names.push_back(pfd.cFileName); + QoreString str(orig_dir); + str.concat(pfd.cFileName); + names.push_back(str.c_str()); //printd(5, "QoreGlobWin::set(pattern='%s') dir='%s' regex='%s' %s MATCHED\n", pattern, dir.getBuffer(), str.getBuffer(), pfd.cFileName); } }