aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-03-24 02:11:20 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-03-24 02:11:20 +0000
commit0ca91482fa1b2f1c01f926503b3de29291d315fc (patch)
tree986d744c5283a8220f9ebaa67f243143dfbd91b8 /src
parentc58071a5d1b296cc0fcf9829de2b873cb91e9cc2 (diff)
downloadpostgresql-0ca91482fa1b2f1c01f926503b3de29291d315fc.tar.gz
postgresql-0ca91482fa1b2f1c01f926503b3de29291d315fc.zip
Add missing error checking in readdir() loops.
Diffstat (limited to 'src')
-rw-r--r--src/port/copydir.c21
-rw-r--r--src/port/dirmod.c33
2 files changed, 51 insertions, 3 deletions
diff --git a/src/port/copydir.c b/src/port/copydir.c
index e77fcb6aeb7..6062da96a84 100644
--- a/src/port/copydir.c
+++ b/src/port/copydir.c
@@ -11,7 +11,7 @@
* as a service.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/port/copydir.c,v 1.10 2004/12/31 22:03:53 pgsql Exp $
+ * $PostgreSQL: pgsql/src/port/copydir.c,v 1.11 2005/03/24 02:11:20 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -56,6 +56,7 @@ copydir(char *fromdir, char *todir)
return -1;
}
+ errno = 0;
while ((xlde = readdir(xldir)) != NULL)
{
snprintf(fromfl, MAXPGPATH, "%s/%s", fromdir, xlde->d_name);
@@ -68,6 +69,24 @@ copydir(char *fromdir, char *todir)
FreeDir(xldir);
return -1;
}
+ errno = 0;
+ }
+#ifdef WIN32
+
+ /*
+ * This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but
+ * not in released version
+ */
+ if (GetLastError() == ERROR_NO_MORE_FILES)
+ errno = 0;
+#endif
+ if (errno)
+ {
+ ereport(WARNING,
+ (errcode_for_file_access(),
+ errmsg("could not read directory \"%s\": %m", fromdir)));
+ FreeDir(xldir);
+ return -1;
}
FreeDir(xldir);
diff --git a/src/port/dirmod.c b/src/port/dirmod.c
index 776a6e0a6ff..a31cfca0813 100644
--- a/src/port/dirmod.c
+++ b/src/port/dirmod.c
@@ -10,7 +10,7 @@
* Win32 (NT, Win2k, XP). replace() doesn't work on Win95/98/Me.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/port/dirmod.c,v 1.36 2005/02/22 04:43:16 momjian Exp $
+ * $PostgreSQL: pgsql/src/port/dirmod.c,v 1.37 2005/03/24 02:11:20 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -326,10 +326,19 @@ fnames(char *path)
dir = opendir(path);
if (dir == NULL)
+ {
+#ifndef FRONTEND
+ elog(WARNING, "could not open directory \"%s\": %m", path);
+#else
+ fprintf(stderr, _("could not open directory \"%s\": %s\n"),
+ path, strerror(errno));
+#endif
return NULL;
+ }
filenames = (char **) palloc(fnsize * sizeof(char *));
+ errno = 0;
while ((file = readdir(dir)) != NULL)
{
if (strcmp(file->d_name, ".") != 0 && strcmp(file->d_name, "..") != 0)
@@ -342,6 +351,25 @@ fnames(char *path)
}
filenames[numnames++] = pstrdup(file->d_name);
}
+ errno = 0;
+ }
+#ifdef WIN32
+
+ /*
+ * This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but
+ * not in released version
+ */
+ if (GetLastError() == ERROR_NO_MORE_FILES)
+ errno = 0;
+#endif
+ if (errno)
+ {
+#ifndef FRONTEND
+ elog(WARNING, "could not read directory \"%s\": %m", path);
+#else
+ fprintf(stderr, _("could not read directory \"%s\": %s\n"),
+ path, strerror(errno));
+#endif
}
filenames[numnames] = NULL;
@@ -434,7 +462,8 @@ report_and_fail:
#ifndef FRONTEND
elog(WARNING, "could not remove file or directory \"%s\": %m", filepath);
#else
- fprintf(stderr, _("could not remove file or directory \"%s\": %s\n"), filepath, strerror(errno));
+ fprintf(stderr, _("could not remove file or directory \"%s\": %s\n"),
+ filepath, strerror(errno));
#endif
fnames_cleanup(filenames);
return false;