瀏覽代碼

vlib: fix GRASS_VECTOR_TEMPORARY when creating temporary maps using Vect_open_new_tmp()

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@65677 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 9 年之前
父節點
當前提交
49d0fd1fff
共有 4 個文件被更改,包括 23 次插入12 次删除
  1. 1 1
      lib/vector/Vlib/close.c
  2. 10 4
      lib/vector/Vlib/close_nat.c
  3. 5 0
      lib/vector/Vlib/local_proto.h
  4. 7 7
      lib/vector/Vlib/open.c

+ 1 - 1
lib/vector/Vlib/close.c

@@ -5,7 +5,7 @@
 
    Higher level functions for reading/writing/manipulating vectors.
 
-   (C) 2001-2009, 2011-2012 by the GRASS Development Team
+   (C) 2001-2015 by the GRASS Development Team
 
    This program is free software under the GNU General Public License
    (>=v2). Read the file COPYING that comes with GRASS for details.

+ 10 - 4
lib/vector/Vlib/close_nat.c

@@ -59,7 +59,7 @@ int V1_close_nat(struct Map_info *Map)
         char *env = getenv("GRASS_VECTOR_TEMPORARY");
 
         delete = TRUE;
-        if (env) {
+        if (Map->temporary == TEMPORARY_MAP_ENV && env) {
             if (G_strcasecmp(env, "move") == 0) {
                 /* copy temporary vector map to the current mapset */
                 char path_tmp[GPATH_MAX], path_map[GPATH_MAX];
@@ -82,6 +82,7 @@ int V1_close_nat(struct Map_info *Map)
 
 #ifdef TEMPORARY_MAP_DB
                 int i, ndblinks;
+                int tmp;
                 
                 struct field_info *fi;
                 dbConnection connection;
@@ -109,9 +110,10 @@ int V1_close_nat(struct Map_info *Map)
                 }
                 G_free(Map->dblnk);
                 Map->dblnk = dblinks;
-                Map->temporary = FALSE;
+                tmp = Map->temporary;
+                Map->temporary = TEMPORARY_MAP_DISABLED;
                 Vect_write_dblinks(Map);
-                Map->temporary = TRUE;
+                Map->temporary = tmp;
 #endif
             }
             else if (G_strcasecmp(env, "delete") == 0) {
@@ -125,7 +127,11 @@ int V1_close_nat(struct Map_info *Map)
                 delete = FALSE;
             }
         }
-
+        else if (Map->temporary == TEMPORARY_MAP) {
+            G_debug(1, "V1_close_nat(): temporary map <%s> TO BE DELETED", Map->name);
+            delete = TRUE;
+        }
+        
         if (delete) {
             char path_tmp[GPATH_MAX];
 

+ 5 - 0
lib/vector/Vlib/local_proto.h

@@ -10,6 +10,11 @@
 /*! Attributes of temporary maps */
 /* #define TEMPORARY_MAP_DB */
 
+/*! Temporary mode */
+#define TEMPORARY_MAP_DISABLED 0
+#define TEMPORARY_MAP_ENV      1
+#define TEMPORARY_MAP          2
+
 /* Internal vector library subroutines which are not part of public
    API*/
 

+ 7 - 7
lib/vector/Vlib/open.c

@@ -6,7 +6,7 @@
   
   Higher level functions for reading/writing/manipulating vectors.
   
-  (C) 2001-2009, 2012-2013 by the GRASS Development Team
+  (C) 2001-2015 by the GRASS Development Team
   
   This program is free software under the GNU General Public License
   (>=v2).  Read the file COPYING that comes with GRASS for details.
@@ -154,7 +154,7 @@ int Vect_set_open_level(int level)
  \param update non-zero to open for update otherwise read-only mode
  \param head_only read only header info from 'head', 'dbln', 'topo',
  'cidx' is not opened. The header may be opened on level 2 only.
- \param is_tmp TRUE for temporary maps
+ \param is_tmp non-zero code for temporary maps
 
  \return level of openness (1, 2)
  \return -1 in error
@@ -175,7 +175,7 @@ int Vect__open_old(struct Map_info *Map, const char *name, const char *mapset,
             is_tmp);
     
     if (update && !is_tmp) {
-        is_tmp = getenv("GRASS_VECTOR_TEMPORARY") ? TRUE : FALSE;
+        is_tmp = getenv("GRASS_VECTOR_TEMPORARY") ? TEMPORARY_MAP_ENV : TEMPORARY_MAP_DISABLED;
         G_debug(1, "Vect__open_old(): is_tmp = %d (check GRASS_VECTOR_TEMPORARY)", is_tmp);
     }
 
@@ -912,7 +912,7 @@ int Vect_open_new(struct Map_info *Map, const char *name, int with_z)
 {
     int is_tmp;
     
-    is_tmp = getenv("GRASS_VECTOR_TEMPORARY") ? TRUE : FALSE;
+    is_tmp = getenv("GRASS_VECTOR_TEMPORARY") ? TEMPORARY_MAP_ENV : TEMPORARY_MAP_DISABLED;
     G_debug(1, "Vect_open_new(): is_tmp = %d", is_tmp);
     
     return open_new(Map, name, with_z, is_tmp);
@@ -950,7 +950,7 @@ int Vect_open_tmp_new(struct Map_info *Map, const char *name, int with_z)
     }
     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 */
+    return open_new(Map, tmp_name, with_z, TEMPORARY_MAP); /* temporary map */
 }
 
 /*!
@@ -1300,7 +1300,7 @@ int map_format(struct Map_info *Map)
              * in the native format and when closing the map
              * transferred to output OGR layer */
             format = GV_FORMAT_NATIVE;
-            Map->temporary = TRUE;
+            Map->temporary = TEMPORARY_MAP;
         }
         fp = G_fopen_old("", "OGR", G_mapset());
         if (!fp) {
@@ -1417,7 +1417,7 @@ int map_format(struct Map_info *Map)
                  * in the native format and when closing the map
                  * transferred to output PostGIS layer */
                 format = GV_FORMAT_NATIVE;
-                Map->temporary = TRUE;
+                Map->temporary = TEMPORARY_MAP;
             }
         }
     }