summaryrefslogtreecommitdiff
path: root/src/os_win/os_dir.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/os_win/os_dir.c')
-rw-r--r--src/os_win/os_dir.c93
1 files changed, 41 insertions, 52 deletions
diff --git a/src/os_win/os_dir.c b/src/os_win/os_dir.c
index 00ec4f252e4..64eae60983c 100644
--- a/src/os_win/os_dir.c
+++ b/src/os_win/os_dir.c
@@ -9,13 +9,12 @@
#include "wt_internal.h"
/*
- * __wt_dirlist --
- * Get a list of files from a directory, optionally filtered by
- * a given prefix.
+ * __wt_win_directory_list --
+ * Get a list of files from a directory, MSVC version.
*/
int
-__wt_dirlist(WT_SESSION_IMPL *session, const char *dir, const char *prefix,
- uint32_t flags, char ***dirlist, u_int *countp)
+__wt_win_directory_list(WT_SESSION_IMPL *session, const char *dir,
+ const char *prefix, uint32_t flags, char ***dirlist, u_int *countp)
{
HANDLE findhandle;
WIN32_FIND_DATA finddata;
@@ -29,72 +28,60 @@ __wt_dirlist(WT_SESSION_IMPL *session, const char *dir, const char *prefix,
*dirlist = NULL;
*countp = 0;
- findhandle = INVALID_HANDLE_VALUE;
- count = 0;
-
WT_RET(__wt_filename(session, dir, &path));
pathlen = strlen(path);
- if (path[pathlen - 1] == '\\') {
+ if (path[pathlen - 1] == '\\')
path[pathlen - 1] = '\0';
- }
-
WT_ERR(__wt_scr_alloc(session, pathlen + 3, &pathbuf));
WT_ERR(__wt_buf_fmt(session, pathbuf, "%s\\*", path));
+ findhandle = INVALID_HANDLE_VALUE;
dirallocsz = 0;
dirsz = 0;
entries = NULL;
- if (flags == 0)
- LF_SET(WT_DIRLIST_INCLUDE);
-
- WT_ERR(__wt_verbose(session, WT_VERB_FILEOPS,
- "wt_dirlist of %s %s prefix %s",
- pathbuf->data, LF_ISSET(WT_DIRLIST_INCLUDE) ? "include" : "exclude",
- prefix == NULL ? "all" : prefix));
findhandle = FindFirstFileA(pathbuf->data, &finddata);
+ if (findhandle == INVALID_HANDLE_VALUE)
+ WT_ERR_MSG(session, __wt_getlasterror(),
+ "%s: directory-list: FindFirstFile", pathbuf->data);
- if (INVALID_HANDLE_VALUE == findhandle)
- WT_ERR_MSG(session, __wt_errno(), "%s: FindFirstFile",
- pathbuf->data);
- else {
- do {
+ count = 0;
+ do {
+ /*
+ * Skip . and ..
+ */
+ if (strcmp(finddata.cFileName, ".") == 0 ||
+ strcmp(finddata.cFileName, "..") == 0)
+ continue;
+
+ /* The list of files is optionally filtered by a prefix. */
+ match = false;
+ if (prefix != NULL &&
+ ((LF_ISSET(WT_DIRLIST_INCLUDE) &&
+ WT_PREFIX_MATCH(finddata.cFileName, prefix)) ||
+ (LF_ISSET(WT_DIRLIST_EXCLUDE) &&
+ !WT_PREFIX_MATCH(finddata.cFileName, prefix))))
+ match = true;
+ if (prefix == NULL || match) {
/*
- * Skip . and ..
+ * We have a file name we want to return.
*/
- if (strcmp(finddata.cFileName, ".") == 0 ||
- strcmp(finddata.cFileName, "..") == 0)
- continue;
- match = false;
- if (prefix != NULL &&
- ((LF_ISSET(WT_DIRLIST_INCLUDE) &&
- WT_PREFIX_MATCH(finddata.cFileName, prefix)) ||
- (LF_ISSET(WT_DIRLIST_EXCLUDE) &&
- !WT_PREFIX_MATCH(finddata.cFileName, prefix))))
- match = true;
- if (prefix == NULL || match) {
- /*
- * We have a file name we want to return.
- */
- count++;
- if (count > dirsz) {
- dirsz += WT_DIR_ENTRY;
- WT_ERR(__wt_realloc_def(session,
- &dirallocsz, dirsz, &entries));
- }
- WT_ERR(__wt_strdup(session,
- finddata.cFileName, &entries[count - 1]));
+ count++;
+ if (count > dirsz) {
+ dirsz += WT_DIR_ENTRY;
+ WT_ERR(__wt_realloc_def(session,
+ &dirallocsz, dirsz, &entries));
}
- } while (FindNextFileA(findhandle, &finddata) != 0);
- }
-
+ WT_ERR(__wt_strdup(session,
+ finddata.cFileName, &entries[count - 1]));
+ }
+ } while (FindNextFileA(findhandle, &finddata) != 0);
if (count > 0)
*dirlist = entries;
*countp = count;
-err:
- if (findhandle != INVALID_HANDLE_VALUE)
+err: if (findhandle != INVALID_HANDLE_VALUE)
(void)FindClose(findhandle);
__wt_free(session, path);
__wt_scr_free(session, &pathbuf);
@@ -108,5 +95,7 @@ err:
__wt_free(session, entries);
}
- WT_RET_MSG(session, ret, "dirlist %s prefix %s", dir, prefix);
+ WT_RET_MSG(session, ret,
+ "%s: directory-list, prefix \"%s\"",
+ dir, prefix == NULL ? "" : prefix);
}