From 65ccaf61a4c298a79747ec39a8dd75ec998a1125 Mon Sep 17 00:00:00 2001
From: Michael Paquier <michael@otacoo.com>
Date: Mon, 23 Feb 2015 15:02:14 +0900
Subject: [PATCH 1/2] Enforce creation of input and output paths in pg_regress

This is particularly useful for extensions that have only regression tests
in input/ and output/ dynamically generated when running the tests to keep
the code tree of such extensions clean without empty folders containing as
only content a .gitignore ignoring everything else other than its own
existence.
---
 src/test/regress/pg_regress.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/test/regress/pg_regress.c b/src/test/regress/pg_regress.c
index 3af0e57..a7aa580 100644
--- a/src/test/regress/pg_regress.c
+++ b/src/test/regress/pg_regress.c
@@ -496,6 +496,7 @@ convert_sourcefiles_in(char *source_subdir, char *dest_dir, char *dest_subdir, c
 {
 	char		testtablespace[MAXPGPATH];
 	char		indir[MAXPGPATH];
+	char		result_dir[MAXPGPATH];
 	struct stat st;
 	int			ret;
 	char	  **name;
@@ -520,6 +521,14 @@ convert_sourcefiles_in(char *source_subdir, char *dest_dir, char *dest_subdir, c
 		/* Error logged in pgfnames */
 		exit(2);
 
+	/*
+	 * Enforce creation of destination directory if it does not exist yet.
+	 * This is useful for tests using only source files.
+	 */
+	snprintf(result_dir, MAXPGPATH, "%s/%s", dest_dir, dest_subdir);
+	if (!directory_exists(result_dir))
+		make_directory(result_dir);
+
 	snprintf(testtablespace, MAXPGPATH, "%s/testtablespace", outputdir);
 
 #ifdef WIN32
@@ -565,7 +574,7 @@ convert_sourcefiles_in(char *source_subdir, char *dest_dir, char *dest_subdir, c
 		/* build the full actual paths to open */
 		snprintf(prefix, strlen(*name) - 6, "%s", *name);
 		snprintf(srcfile, MAXPGPATH, "%s/%s", indir, *name);
-		snprintf(destfile, MAXPGPATH, "%s/%s/%s.%s", dest_dir, dest_subdir,
+		snprintf(destfile, MAXPGPATH, "%s/%s.%s", result_dir,
 				 prefix, suffix);
 
 		infile = fopen(srcfile, "r");
-- 
2.3.0

