[GRASS-SVN] r57444 - in grass/trunk/lib/vector: Vlib diglib

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Aug 11 11:08:11 PDT 2013


Author: martinl
Date: 2013-08-11 11:08:11 -0700 (Sun, 11 Aug 2013)
New Revision: 57444

Modified:
   grass/trunk/lib/vector/Vlib/cindex.c
   grass/trunk/lib/vector/Vlib/close_nat.c
   grass/trunk/lib/vector/Vlib/level_two.c
   grass/trunk/lib/vector/Vlib/open.c
   grass/trunk/lib/vector/Vlib/open_nat.c
   grass/trunk/lib/vector/diglib/head.c
Log:
vlib: fix open topo/cidx for temporary vector maps
      introduce GRASS_VECTOR_TEMPORARY variable
      debug messages cosmetics


Modified: grass/trunk/lib/vector/Vlib/cindex.c
===================================================================
--- grass/trunk/lib/vector/Vlib/cindex.c	2013-08-11 09:11:11 UTC (rev 57443)
+++ grass/trunk/lib/vector/Vlib/cindex.c	2013-08-11 18:08:11 UTC (rev 57444)
@@ -485,7 +485,7 @@
 int Vect_cidx_open(struct Map_info *Map, int head_only)
 {
     int ret;
-    char buf[500], file_path[2000];
+    char file_path[GPATH_MAX], *path;
     struct gvfile fp;
     struct Plus_head *Plus;
 
@@ -494,16 +494,18 @@
 
     Plus = &(Map->plus);
 
-    sprintf(buf, "%s/%s", GV_DIRECTORY, Map->name);
-    G_file_name(file_path, buf, GV_CIDX_ELEMENT, Map->mapset);
+    path = Vect__get_path(Map);
+    G_file_name(file_path, path, GV_CIDX_ELEMENT, Map->mapset);
 
-    if (access(file_path, F_OK) != 0)	/* does not exist */
+    if (access(file_path, F_OK) != 0) {	/* does not exist */
+        G_free(path);
 	return 1;
+    }
 
-
     dig_file_init(&fp);
-    fp.file = G_fopen_old(buf, GV_CIDX_ELEMENT, Map->mapset);
-
+    fp.file = G_fopen_old(path, GV_CIDX_ELEMENT, Map->mapset);
+    G_free(path);
+    
     if (fp.file == NULL) {	/* category index file is not available */
 	G_warning(_("Unable to open category index file for vector map <%s>"),
 		  Vect_get_full_name(Map));

Modified: grass/trunk/lib/vector/Vlib/close_nat.c
===================================================================
--- grass/trunk/lib/vector/Vlib/close_nat.c	2013-08-11 09:11:11 UTC (rev 57443)
+++ grass/trunk/lib/vector/Vlib/close_nat.c	2013-08-11 18:08:11 UTC (rev 57444)
@@ -50,9 +50,15 @@
     fclose(Map->dig_fp.file);
     dig_file_free(&(Map->dig_fp));
 
-    /* delete temporary map */
+    /* delete temporary map ? */
     if (Map->temporary) {
-        Vect__delete(Map->name, TRUE);
+        if (getenv("GRASS_VECTOR_TEMPORARY") == NULL) {
+            G_debug(1, "V1_close_nat(): temporary map <%s> TO BE DELETED", Map->name);
+            Vect__delete(Map->name, TRUE);
+        }
+        else {
+            G_debug(1, "V1_close_nat(): temporary map <%s> IS NOT DELETED", Map->name);
+        }
     }
 
     return 0;

Modified: grass/trunk/lib/vector/Vlib/level_two.c
===================================================================
--- grass/trunk/lib/vector/Vlib/level_two.c	2013-08-11 09:11:11 UTC (rev 57443)
+++ grass/trunk/lib/vector/Vlib/level_two.c	2013-08-11 18:08:11 UTC (rev 57444)
@@ -457,6 +457,8 @@
 */
 void Vect_set_updated(struct Map_info *Map, int enable)
 {
+    G_debug(1, "Vect_set_updated(): name = '%s' enabled = %d", Map->name, enable);
+    
     check_level(Map);
     
     Map->plus.uplist.do_uplist = enable != 0 ? TRUE : FALSE;

Modified: grass/trunk/lib/vector/Vlib/open.c
===================================================================
--- grass/trunk/lib/vector/Vlib/open.c	2013-08-11 09:11:11 UTC (rev 57443)
+++ grass/trunk/lib/vector/Vlib/open.c	2013-08-11 18:08:11 UTC (rev 57444)
@@ -171,8 +171,13 @@
     const char *fmapset;
 
     G_debug(1, "Vect__open_old(): name = %s, mapset = %s, layer = %s, update = %d, "
-            "head_only = %d, is_tmp = %d", name, mapset, layer ? layer : "", update, head_only,
+            "head_only = %d, is_tmp = %d", name, mapset, layer ? layer : "NULL", update, head_only,
             is_tmp);
+    
+    if (!is_tmp) {
+        is_tmp = getenv("GRASS_VECTOR_TEMPORARY") ? TRUE : FALSE;
+        G_debug(1, "Vect__open_old(): is_tmp = %d (check GRASS_VECTOR_TEMPORARY)", is_tmp);
+    }
 
     /* zero Map_info structure */
     G_zero(Map, sizeof(struct Map_info));
@@ -845,7 +850,12 @@
 */
 int Vect_open_new(struct Map_info *Map, const char *name, int with_z)
 {
-    return open_new(Map, name, with_z, FALSE);
+    int is_tmp;
+    
+    is_tmp = getenv("GRASS_VECTOR_TEMPORARY") ? TRUE : FALSE;
+    G_debug(1, "Vect_open_new(): is_tmp = %d", is_tmp);
+    
+    return open_new(Map, name, with_z, is_tmp);
 }
 
 /*!
@@ -878,7 +888,8 @@
     else {
         sprintf(tmp_name, "%s", name);
     }
-    
+    G_debug(1, "Vect_open_tmp_new(): name = '%s' with_z = %d", name, with_z);
+
     return open_new(Map, tmp_name, with_z, TRUE); /* temporary map */
 }
 
@@ -1017,24 +1028,27 @@
 int Vect_open_topo(struct Map_info *Map, int head_only)
 {
     int err, ret;
-    char buf[GPATH_MAX], file_path[GPATH_MAX];
+    char file_path[GPATH_MAX], *path;
     struct gvfile fp;
     struct Coor_info CInfo;
     struct Plus_head *Plus;
 
-    G_debug(1, "Vect_open_topo(): name = %s mapset= %s", Map->name,
+    G_debug(1, "Vect_open_topo(): name = %s mapset = %s", Map->name,
             Map->mapset);
 
     Plus = &(Map->plus);
 
-    sprintf(buf, "%s/%s", GV_DIRECTORY, Map->name);
-    G_file_name(file_path, buf, GV_TOPO_ELEMENT, Map->mapset);
-
-    if (access(file_path, F_OK) != 0)   /* does not exist */
+    path = Vect__get_path(Map);
+    G_file_name(file_path, path, GV_TOPO_ELEMENT, Map->mapset);
+    
+    if (access(file_path, F_OK) != 0) {  /* does not exist */
+        G_free(path);
         return 1;
+    }
 
     dig_file_init(&fp);
-    fp.file = G_fopen_old(buf, GV_TOPO_ELEMENT, Map->mapset);
+    fp.file = G_fopen_old(path, GV_TOPO_ELEMENT, Map->mapset);
+    G_free(path);
 
     if (fp.file == NULL) {      /* topo file is not available */
         G_debug(1, "Cannot open topo file for vector '%s@%s'.",

Modified: grass/trunk/lib/vector/Vlib/open_nat.c
===================================================================
--- grass/trunk/lib/vector/Vlib/open_nat.c	2013-08-11 09:11:11 UTC (rev 57443)
+++ grass/trunk/lib/vector/Vlib/open_nat.c	2013-08-11 18:08:11 UTC (rev 57444)
@@ -38,32 +38,36 @@
 */
 int V1_open_old_nat(struct Map_info *Map, int update)
 {
-    char buf[1000];
+    char *path;
     struct Coor_info CInfo;
 
     G_debug(1, "V1_open_old_nat(): name = %s mapset = %s", Map->name,
 	    Map->mapset);
 
-    sprintf(buf, "%s/%s", GV_DIRECTORY, Map->name);
+    path = Vect__get_path(Map);
     dig_file_init(&(Map->dig_fp));
     if (update)
-	Map->dig_fp.file = G_fopen_modify(buf, GV_COOR_ELEMENT);
+	Map->dig_fp.file = G_fopen_modify(path, GV_COOR_ELEMENT);
     else
 	Map->dig_fp.file =
-	    G_fopen_old(buf, GV_COOR_ELEMENT, Map->mapset);
-
+	    G_fopen_old(path, GV_COOR_ELEMENT, Map->mapset);
+    G_free(path);
+    
     if (Map->dig_fp.file == NULL) {
         G_warning(_("Unable to open coor file for vector map <%s>"),
 		  Vect_get_full_name(Map));
         return -1;
     }
 
-    /* needed to determine file size, Map->head.size will be updated by dig__read_head(Map) */
+    /* needed to determine file size, Map->head.size will be updated
+       by dig__read_head(Map) */
     Vect_coor_info(Map, &CInfo); 
     Map->head.size = CInfo.size;
     
-    if (!(dig__read_head(Map)))
-	return (-1);
+    if (!(dig__read_head(Map))) {
+        G_debug(1, "dig__read_head(): failed");
+	return -1;
+    }
 
     /* compare coor size stored in head with real size */
     /* check should catch if LFS is required but not available */

Modified: grass/trunk/lib/vector/diglib/head.c
===================================================================
--- grass/trunk/lib/vector/diglib/head.c	2013-08-11 09:11:11 UTC (rev 57443)
+++ grass/trunk/lib/vector/diglib/head.c	2013-08-11 18:08:11 UTC (rev 57444)
@@ -85,6 +85,7 @@
     unsigned char buf[10];
     struct Port_info port;
 
+    G_debug(2, "dig__read_head(): name = '%s'", Map->name);
     dig_fseek(&(Map->dig_fp), 0L, 0);
 
     /* bytes 1 - 5 */
@@ -96,8 +97,7 @@
     Map->head.coor_version.back_minor = buf[3];
     Map->head.port.byte_order = buf[4];
 
-    G_debug(2,
-	    "Coor header: file version %d.%d , supported from GRASS version %d.%d",
+    G_debug(2, "Coor header: file version %d.%d , supported from GRASS version %d.%d",
 	    Map->head.coor_version.major, Map->head.coor_version.minor,
 	    Map->head.coor_version.back_major, Map->head.coor_version.back_minor);
 



More information about the grass-commit mailing list