diff options
author | Bruce Momjian <bruce@momjian.us> | 2014-03-21 13:45:11 -0400 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2014-03-21 13:45:11 -0400 |
commit | 6f03927fce038096f53ca67eeab9adb24938f8a6 (patch) | |
tree | e6ebc4031e1ec37c0766e1ae6baa83f39b0da227 /contrib/pg_archivecleanup/pg_archivecleanup.c | |
parent | 68a2e52bbaf98f136a96b3a0d734ca52ca440a95 (diff) |
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_archivecleanup/pg_archivecleanup.c')
-rw-r--r-- | contrib/pg_archivecleanup/pg_archivecleanup.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/contrib/pg_archivecleanup/pg_archivecleanup.c b/contrib/pg_archivecleanup/pg_archivecleanup.c index 7b5484bb6ac..039829e0049 100644 --- a/contrib/pg_archivecleanup/pg_archivecleanup.c +++ b/contrib/pg_archivecleanup/pg_archivecleanup.c @@ -106,7 +106,7 @@ CleanupPriorWALFiles(void) if ((xldir = opendir(archiveLocation)) != NULL) { - while ((xlde = readdir(xldir)) != NULL) + while (errno = 0, (xlde = readdir(xldir)) != NULL) { strncpy(walfile, xlde->d_name, MAXPGPATH); TrimExtension(walfile, additional_ext); @@ -164,7 +164,19 @@ CleanupPriorWALFiles(void) } } } - closedir(xldir); + +#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) + fprintf(stderr, "%s: could not read archive location \"%s\": %s\n", + progname, archiveLocation, strerror(errno)); + if (closedir(xldir)) + fprintf(stderr, "%s: could not close archive location \"%s\": %s\n", + progname, archiveLocation, strerror(errno)); } else fprintf(stderr, "%s: could not open archive location \"%s\": %s\n", |