[GRASS-SVN] r42321 - grass/trunk/lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Thu May 20 07:09:38 EDT 2010


Author: mmetz
Date: 2010-05-20 07:09:16 -0400 (Thu, 20 May 2010)
New Revision: 42321

Modified:
   grass/trunk/lib/vector/Vlib/open.c
   grass/trunk/lib/vector/Vlib/open_nat.c
Log:
fix r42320

Modified: grass/trunk/lib/vector/Vlib/open.c
===================================================================
--- grass/trunk/lib/vector/Vlib/open.c	2010-05-19 17:57:55 UTC (rev 42320)
+++ grass/trunk/lib/vector/Vlib/open.c	2010-05-20 11:09:16 UTC (rev 42321)
@@ -773,13 +773,31 @@
 {
     char buf[2000], path[2000];
     struct stat stat_buf;
-
+    
     switch (Map->format) {
     case GV_FORMAT_NATIVE:
-	dig_fseek(&(Map->dig_fp), 0L, SEEK_END);
-	G_debug(2, "dig_ftell = %d", dig_ftell(&(Map->dig_fp)));
-	Info->size = dig_ftell(&(Map->dig_fp));
-	Info->mtime = 0L;
+	sprintf(buf, "%s/%s", GV_DIRECTORY, Map->name);
+	G__file_name(path, buf, GV_COOR_ELEMENT, Map->mapset);
+	G_debug(1, "get coor info: %s", path);
+	if (0 != stat(path, &stat_buf)) {
+	    G_warning(_("Unable to stat file <%s>"), path);
+	    Info->size = -1L;
+	    Info->mtime = -1L;
+	}
+	else {
+	    Info->size = (off_t)stat_buf.st_size;      /* file size */
+	    Info->mtime = (long)stat_buf.st_mtime;      /* last modified time */
+	}
+	
+        /* stat does not give correct size on MINGW
+         * if the file is opened */
+#ifdef __MINGW32__
+	if (Map->open == VECT_OPEN_CODE) {
+	    dig_fseek(&(Map->dig_fp), 0L, SEEK_END);
+	    G_debug(2, "dig_ftell = %d", dig_ftell(&(Map->dig_fp)));
+	    Info->size = dig_ftell(&(Map->dig_fp));
+	}
+#endif
 	break;
     case GV_FORMAT_OGR:
     case GV_FORMAT_OGR_DIRECT:
@@ -884,6 +902,7 @@
     }
 
     /* get coor info */
+    /* NOTE: coor file not yet opened */
     Vect_coor_info(Map, &CInfo);
 
     /* load head */
@@ -973,6 +992,7 @@
 	}
 
 	/* get coor info */
+	/* NOTE: coor file not yet opened */
 	Vect_coor_info(Map, &CInfo);
 
 	/* initialize spatial index */

Modified: grass/trunk/lib/vector/Vlib/open_nat.c
===================================================================
--- grass/trunk/lib/vector/Vlib/open_nat.c	2010-05-19 17:57:55 UTC (rev 42320)
+++ grass/trunk/lib/vector/Vlib/open_nat.c	2010-05-20 11:09:16 UTC (rev 42321)
@@ -59,9 +59,15 @@
         return -1;
     }
 
+    /* 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);
 
+    /* compare coor size stored in head with real size */
+    /* check should catch if LFS is required but not available */
     check_coor(Map);
 
     /* set conversion matrices */
@@ -111,6 +117,8 @@
     if (Map->dig_fp.file == NULL)
 	return (-1);
 
+    /* if overwrite OK, any existing files have already been deleted by
+     * Vect_open_new(): remove this check ? */
     /* check to see if dig_plus file exists and if so, remove it */
     G__file_name(name_buf, buf, GV_TOPO_ELEMENT, G_mapset());
     if (stat(name_buf, &info) == 0)	/* file exists? */
@@ -137,17 +145,18 @@
     struct Coor_info CInfo;
     off_t dif;
 
+    /* NOTE: coor file is open */
     Vect_coor_info(Map, &CInfo);
     dif = CInfo.size - Map->head.size;
     G_debug(1, "coor size in head = %lu, real coor file size= %lu",
 	    (unsigned long) Map->head.size, (unsigned long) CInfo.size);
 
     if (dif > 0) {
-	G_warning(_("Coor files of vector map <%s@%s> is larger than it should be "
+	G_warning(_("Coor file of vector map <%s@%s> is larger than it should be "
 		   "(%ld bytes excess)"), Map->name, Map->mapset, dif);
     }
     else if (dif < 0) {
-	G_warning(_("Coor files of vector <%s@%s> is shorter than it should be "
+	G_warning(_("Coor file of vector <%s@%s> is shorter than it should be "
 		   "(%ld bytes missing)."), Map->name, Map->mapset, -dif);
     }
     return 1;



More information about the grass-commit mailing list