]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Add missing error checking in readdir() loops.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 24 Mar 2005 02:11:33 +0000 (02:11 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 24 Mar 2005 02:11:33 +0000 (02:11 +0000)
src/port/copydir.c
src/port/dirmod.c

index e77fcb6aeb75339f9738d5a07cfe87f657cdc2a5..3855a6dcc0464d8e1759f54348e176975ead29e7 100644 (file)
@@ -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.10.4.1 2005/03/24 02:11:33 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);
index 8664a4f4e3b992e572a9dda2debfe3c2aa2ca21c..e8e40775aa5ba1e790821c2602f687f337d1cdf6 100644 (file)
@@ -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.34.4.1 2005/02/13 16:50:54 momjian Exp $
+ *       $PostgreSQL: pgsql/src/port/dirmod.c,v 1.34.4.2 2005/03/24 02:11:33 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -72,7 +72,7 @@ fe_palloc(Size size)
 
        if ((res = malloc(size)) == NULL)
        {
-               fprintf(stderr, gettext("out of memory\n"));
+               fprintf(stderr, "out of memory\n");
                exit(1);
        }
        return res;
@@ -85,7 +85,7 @@ fe_pstrdup(const char *string)
 
        if ((res = strdup(string)) == NULL)
        {
-               fprintf(stderr, gettext("out of memory\n"));
+               fprintf(stderr, "out of memory\n");
                exit(1);
        }
        return res;
@@ -98,7 +98,7 @@ fe_repalloc(void *pointer, Size size)
 
        if ((res = realloc(pointer, size)) == NULL)
        {
-               fprintf(stderr, gettext("out of memory\n"));
+               fprintf(stderr, "out of memory\n");
                exit(1);
        }
        return res;
@@ -325,10 +325,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)
@@ -341,6 +350,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;
@@ -433,7 +461,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;