wrowe 2002/12/29 14:40:53
Modified: include/arch/win32 fileio.h
file_io/win32 dir.c
Log:
Close the last testdir emit by always calling FindFirstFile on open/rewind
invocations. We don't fill-in the finfo until we invoke apr_dir_read the
second time and onwards (following the initial invocation of apr_dir_read
by the apr_dir_open or apr_dir_rewind functions.)
Revision Changes Path
1.72 +1 -0 apr/include/arch/win32/fileio.h
Index: fileio.h
===================================================================
RCS file: /home/cvs/apr/include/arch/win32/fileio.h,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -r1.71 -r1.72
--- fileio.h 29 Dec 2002 20:28:58 -0000 1.71
+++ fileio.h 29 Dec 2002 22:40:53 -0000 1.72
@@ -235,6 +235,7 @@
} n;
#endif
};
+ int bof;
};
/* There are many goofy characters the filesystem can't accept
1.67 +44 -3 apr/file_io/win32/dir.c
Index: dir.c
===================================================================
RCS file: /home/cvs/apr/file_io/win32/dir.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -r1.66 -r1.67
--- dir.c 29 Dec 2002 22:17:29 -0000 1.66
+++ dir.c 29 Dec 2002 22:40:53 -0000 1.67
@@ -86,6 +86,8 @@
APR_DECLARE(apr_status_t) apr_dir_open(apr_dir_t **new, const char *dirname,
apr_pool_t *pool)
{
+ apr_status_t rv;
+
int len = strlen(dirname);
(*new) = apr_pcalloc(pool, sizeof(apr_dir_t));
/* Leave room here to add and pop the '*' wildcard for FindFirstFile
@@ -129,7 +131,14 @@
(*new)->dirhand = INVALID_HANDLE_VALUE;
apr_pool_cleanup_register((*new)->pool, (void *)(*new), dir_cleanup,
apr_pool_cleanup_null);
- return APR_SUCCESS;
+
+ rv = apr_dir_read(NULL, 0, *new);
+ if (rv != APR_SUCCESS) {
+ dir_cleanup(*new);
+ *new = NULL;
+ }
+
+ return rv;
}
APR_DECLARE(apr_status_t) apr_dir_close(apr_dir_t *dir)
@@ -151,6 +160,9 @@
apr_wchar_t *eos = NULL;
IF_WIN_OS_IS_UNICODE
{
+ /* This code path is always be invoked by apr_dir_open or
+ * apr_dir_rewind, so return without filling out the finfo.
+ */
if (thedir->dirhand == INVALID_HANDLE_VALUE)
{
apr_status_t rv;
@@ -167,10 +179,20 @@
if (thedir->dirhand == INVALID_HANDLE_VALUE) {
return apr_get_os_error();
}
+ thedir->bof = 1;
+ return APR_SUCCESS;
+ }
+ else if (thedir->bof) {
+ /* Noop - we already called FindFirstFileW from
+ * either apr_dir_open or apr_dir_rewind ... use
+ * that first record.
+ */
+ thedir->bof = 0;
}
else if (!FindNextFileW(thedir->dirhand, thedir->w.entry)) {
return apr_get_os_error();
}
+
while (thedir->rootlen &&
thedir->rootlen + wcslen(thedir->w.entry->cFileName) >=
APR_PATH_MAX)
{
@@ -187,9 +209,12 @@
#if APR_HAS_ANSI_FS
ELSE_WIN_OS_IS_ANSI
{
- char *eop = strchr(thedir->dirname, '\0');
+ /* This code path is always be invoked by apr_dir_open or
+ * apr_dir_rewind, so return without filling out the finfo.
+ */
if (thedir->dirhand == INVALID_HANDLE_VALUE) {
/* '/' terminated, so add the '*' and pop it when we finish */
+ char *eop = strchr(thedir->dirname, '\0');
eop[0] = '*';
eop[1] = '\0';
thedir->dirhand = FindFirstFileA(thedir->dirname,
@@ -198,6 +223,15 @@
if (thedir->dirhand == INVALID_HANDLE_VALUE) {
return apr_get_os_error();
}
+ thedir->bof = 1;
+ return APR_SUCCESS;
+ }
+ else if (thedir->bof) {
+ /* Noop - we already called FindFirstFileW from
+ * either apr_dir_open or apr_dir_rewind ... use
+ * that first record.
+ */
+ thedir->bof = 0;
}
else if (!FindNextFile(thedir->dirhand, thedir->n.entry)) {
return apr_get_os_error();
@@ -263,10 +297,17 @@
APR_DECLARE(apr_status_t) apr_dir_rewind(apr_dir_t *dir)
{
+ apr_status_t rv;
+
/* this will mark the handle as invalid and we'll open it
* again if apr_dir_read() is subsequently called
*/
- return dir_cleanup(dir);
+ rv = dir_cleanup(dir);
+
+ if (rv == APR_SUCCESS)
+ rv = apr_dir_read(NULL, 0, dir);
+
+ return rv;
}
APR_DECLARE(apr_status_t) apr_dir_make(const char *path, apr_fileperms_t
perm,