[postgis-tickets] [SCM] PostGIS branch master updated. 3.4.0beta1-13-g8140ae8be

git at osgeo.org git at osgeo.org
Sat Jul 15 15:29:03 PDT 2023


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".

The branch, master has been updated
       via  8140ae8be1ca9b4c7309e56333d19392899333e9 (commit)
      from  a24263108e1e4cbb2944825e02d9d8221b6ec16d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 8140ae8be1ca9b4c7309e56333d19392899333e9
Author: Sandro Santilli <strk at kbt.io>
Date:   Sun Jul 16 00:28:44 2023 +0200

    Make generator parallel-safe

diff --git a/doc/html/images/Makefile.in b/doc/html/images/Makefile.in
index 7a724d053..871d7fcd9 100644
--- a/doc/html/images/Makefile.in
+++ b/doc/html/images/Makefile.in
@@ -273,7 +273,7 @@ generator: $(OBJS) ../../../liblwgeom/.libs/liblwgeom.a
 clean:
 	rm -f $(OBJS)
 	rm -f generator
-	rm -f tmp[0-9].png
+	rm -rf generator-temp-*
 
 distclean: clean
 	rm -f Makefile
diff --git a/doc/html/images/generator.c b/doc/html/images/generator.c
index c1c71ccb0..73d55a690 100644
--- a/doc/html/images/generator.c
+++ b/doc/html/images/generator.c
@@ -43,9 +43,12 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h> /* for rmdir */
 #include <ctype.h>
 #include <sys/wait.h> /* for WEXITSTATUS */
 #include <stdbool.h>
+#include <sys/types.h>
+#include <dirent.h>
 
 #include "liblwgeom_internal.h"
 #include "lwgeom_log.h"
@@ -60,7 +63,8 @@ bool optionVerbose = false;
 // Some global styling variables
 const char *imageSize = "200x200";
 
-int getStyleName(char **styleName, char* line);
+char tempdir_template[] = "generator-temp-XXXXXX";
+char *tmpdir = NULL;
 
 static void
 checked_system(const char* cmd)
@@ -72,6 +76,33 @@ checked_system(const char* cmd)
 	}
 }
 
+static void
+cleanupTempDir(const char *dir)
+{
+	struct dirent *p;
+	DIR *d = opendir(dir);
+	char *buf;
+	size_t maxlen;
+
+	if ( NULL == d ) {
+		perror( dir );
+		exit(EXIT_FAILURE); /* or be tolerant ? */
+	}
+
+	maxlen = strlen(dir) + 64;
+	buf = malloc(maxlen);
+
+	while ( (p=readdir(d)) ) {
+		if ( strcmp(p->d_name, ".") == 0 ) continue;
+		if ( strcmp(p->d_name, ".." ) == 0) continue;
+		snprintf(buf, maxlen-1, "%s/%s", dir, p->d_name);
+		remove(buf);
+	}
+
+	closedir(d);
+	rmdir(dir);
+}
+
 /**
  * Writes the coordinates of a POINTARRAY to a char* where ordinates are
  * separated by a comma and coordinates by a space so that the coordinate
@@ -349,29 +380,18 @@ optimizeImage(char* filename)
 static void
 flattenLayers(char* filename)
 {
-	char *str = malloc( (48 + strlen(filename) + 1) * sizeof(char) );
-	sprintf(str, "convert tmp[0-9].png -background white -flatten %s", filename);
+	char *str = malloc( (48 + strlen(filename) + strlen(tmpdir) + 2) * sizeof(char) );
+	sprintf(str, "convert %s/tmp*.png -background white -flatten %s", tmpdir, filename);
 
 	LWDEBUGF(4, "%s", str);
 	checked_system(str);
-	// TODO: only remove the tmp files if they exist.
-	remove("tmp0.png");
-	remove("tmp1.png");
-	remove("tmp2.png");
-	remove("tmp3.png");
-	remove("tmp4.png");
-	remove("tmp5.png");
-	remove("tmp6.png");
-	remove("tmp7.png");
-	remove("tmp8.png");
-	remove("tmp9.png");
 	free(str);
 }
 
 
 // TODO: comments
-int
-getStyleName(char **styleName, char* line)
+static int
+getStyleName(char **styleName, const char* line)
 {
 	char *ptr = strrchr(line, ';');
 	if (ptr == NULL)
@@ -466,6 +486,12 @@ int main( int argc, const char* argv[] )
 		sprintf(filename + strlen(image_src) - 3, "png" );
 	}
 
+	tmpdir = mkdtemp(tempdir_template);
+	if ( NULL == tmpdir ) {
+		perror ( image_src );
+		exit(EXIT_FAILURE);
+	}
+
 	printf( "generating %s\n", filename );
 
 	layerCount = 0;
@@ -499,7 +525,7 @@ int main( int argc, const char* argv[] )
 		}
 		ptr += drawGeometry( ptr, lwgeom, style );
 
-		ptr += sprintf( ptr, "-flip tmp%d.png", layerCount );
+		ptr += sprintf( ptr, "-flip %s/tmp%d.png", tmpdir, layerCount );
 
 		lwgeom_free( lwgeom );
 
@@ -519,5 +545,8 @@ int main( int argc, const char* argv[] )
 	fclose(pfile);
 	free(filename);
 	freeStyles(&styles);
+
+	cleanupTempDir(tmpdir);
+
 	return 0;
 }

-----------------------------------------------------------------------

Summary of changes:
 doc/html/images/Makefile.in |  2 +-
 doc/html/images/generator.c | 63 +++++++++++++++++++++++++++++++++------------
 2 files changed, 47 insertions(+), 18 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list