aboutsummaryrefslogtreecommitdiff
path: root/contrib/pg_upgrade/file.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2014-03-21 13:45:11 -0400
committerBruce Momjian <bruce@momjian.us>2014-03-21 13:45:11 -0400
commitd73cc5857faca215ee95c858e836bcc12d1d1b70 (patch)
treedc498d422c12b1bf297098b7728d86d9025fbd78 /contrib/pg_upgrade/file.c
parent697becf743b3176a038d78857b14976d441a0027 (diff)
downloadpostgresql-d73cc5857faca215ee95c858e836bcc12d1d1b70.tar.gz
postgresql-d73cc5857faca215ee95c858e836bcc12d1d1b70.zip
Properly check for readdir/closedir() failures
Clear errno before calling readdir() and handle old MinGW errno bug while adding full test coverage for readdir/closedir failures. Backpatch through 8.4.
Diffstat (limited to 'contrib/pg_upgrade/file.c')
-rw-r--r--contrib/pg_upgrade/file.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/contrib/pg_upgrade/file.c b/contrib/pg_upgrade/file.c
index 8fdc86d7d47..de23dedbf2b 100644
--- a/contrib/pg_upgrade/file.c
+++ b/contrib/pg_upgrade/file.c
@@ -291,7 +291,7 @@ pg_scandir_internal(const char *dirname,
*namelist = NULL;
- while ((direntry = readdir(dirdesc)) != NULL)
+ while (errno = 0, (direntry = readdir(dirdesc)) != NULL)
{
/* Invoke the selector function to see if the direntry matches */
if (!selector || (*selector) (direntry))
@@ -324,7 +324,17 @@ pg_scandir_internal(const char *dirname,
}
}
- closedir(dirdesc);
+#ifdef WIN32
+ /* Bug in old Mingw dirent.c; fixed in mingw-runtime-3.2, 2003-10-10 */
+ if (GetLastError() == ERROR_NO_MORE_FILES)
+ errno = 0;
+#endif
+
+ if (errno)
+ pg_log(PG_FATAL, "could not read directory \"%s\": %s\n", dirname, getErrorText(errno));
+
+ if (closedir(dirdesc))
+ pg_log(PG_FATAL, "could not close directory \"%s\": %s\n", dirname, getErrorText(errno));
return count;
}