Fix pg_regress to check the directory it is actually reading files from,
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 27 Nov 2007 19:13:30 +0000 (19:13 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 27 Nov 2007 19:13:30 +0000 (19:13 +0000)
not the image that (theoretically) should exist in the current directory.

Jørgen Austvik

src/test/regress/pg_regress.c

index f7fb393b966b00762a054febf8fff4e07fc6d8b6..91d6133879275dd81ee38b91baddbdfc1c8ad774 100644 (file)
@@ -399,6 +399,8 @@ convert_sourcefiles_in(char *source, char *dest, char *suffix)
        char            abs_builddir[MAXPGPATH];
        char            testtablespace[MAXPGPATH];
        char            indir[MAXPGPATH];
+       struct stat     st;
+       int                     ret;
        char      **name;
        char      **names;
        int                     count = 0;
@@ -419,11 +421,23 @@ convert_sourcefiles_in(char *source, char *dest, char *suffix)
         * current directory.
         */
        if (srcdir)
-               strcpy(abs_srcdir, srcdir);
+               strlcpy(abs_srcdir, srcdir, MAXPGPATH);
        else
-               strcpy(abs_srcdir, abs_builddir);
+               strlcpy(abs_srcdir, abs_builddir, MAXPGPATH);
 
        snprintf(indir, MAXPGPATH, "%s/%s", abs_srcdir, source);
+
+       /* Check that indir actually exists and is a directory */
+       ret = stat(indir, &st);
+       if (ret != 0 || !S_ISDIR(st.st_mode))
+       {
+               /*
+                * No warning, to avoid noise in tests that do not have
+                * these directories; for example, ecpg, contrib and src/pl.
+                */
+               return;
+       }
+
        names = pgfnames(indir);
        if (!names)
                /* Error logged in pgfnames */
@@ -512,16 +526,8 @@ convert_sourcefiles_in(char *source, char *dest, char *suffix)
 static void
 convert_sourcefiles(void)
 {
-       struct stat st;
-       int                     ret;
-
-       ret = stat("input", &st);
-       if (ret == 0 && S_ISDIR(st.st_mode))
-               convert_sourcefiles_in("input", "sql", "sql");
-
-       ret = stat("output", &st);
-       if (ret == 0 && S_ISDIR(st.st_mode))
-               convert_sourcefiles_in("output", "expected", "out");
+       convert_sourcefiles_in("input", "sql", "sql");
+       convert_sourcefiles_in("output", "expected", "out");
 }
 
 /*