[GRASS-SVN] r72989 - grass/trunk/misc/m.nviz.image

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jul 14 17:59:13 PDT 2018


Author: hcho
Date: 2018-07-14 17:59:13 -0700 (Sat, 14 Jul 2018)
New Revision: 72989

Modified:
   grass/trunk/misc/m.nviz.image/main.c
Log:
m.nviz.image: Check for overwrite

Modified: grass/trunk/misc/m.nviz.image/main.c
===================================================================
--- grass/trunk/misc/m.nviz.image/main.c	2018-07-14 18:23:40 UTC (rev 72988)
+++ grass/trunk/misc/m.nviz.image/main.c	2018-07-15 00:59:13 UTC (rev 72989)
@@ -18,6 +18,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #include <grass/gis.h>
 #include <grass/colors.h>
@@ -37,6 +38,7 @@
     double vp_height, z_exag;	/* calculated viewpoint height, z-exag */
     int width, height;		/* output image size */
     char *output_name;
+    int overwrite;
 
     nv_data data;
     struct render_window *offscreen;
@@ -60,6 +62,7 @@
 
     /* define options, call G_parser() */
     parse_command(argc, argv, params);
+    overwrite = G_check_overwrite(argc, argv);
 
     /* check parameters consistency */
     check_parameters(params);
@@ -69,6 +72,13 @@
     G_asprintf(&output_name, "%s.%s", params->output->answer,
 	       params->format->answer);
 
+    if (access(output_name, F_OK) == 0) {
+	if (overwrite)
+	    G_warning(_("File <%s> already exists and will be overwritten"), output_name);
+	else
+	    G_fatal_error(_("option <%s>: <%s> exists. To overwrite, use the --overwrite flag"), params->output->key, output_name);
+    }
+
     GS_libinit();
     GVL_libinit();
 



More information about the grass-commit mailing list