[GRASS-dev] g.copy vect/DBF problem & suggestion

Markus Neteler neteler at itc.it
Thu Apr 26 09:42:28 EDT 2007


Markus Neteler wrote on 04/26/2007 12:23 AM:
> Hi,
>
> copying a vector map into a mapset where the DBF driver
> is defined but the dbf/ directory still absent (for
> whatsoever reason), g.copy bails out with
>
> g.copy vect=zipcodes_wake,myzipcodes_wake
> Copy vector <zipcodes_wake at PERMANENT> to current mapset as
> <myzipcodes_wake>
> DBMI-DBF driver error:
> Cannot open dbf database: /home/neteler/grassdata/nc_spm_04/neteler/dbf/
>
>
> WARNUNG: Cannot open database
>          '/home/neteler/grassdata/nc_spm_04/neteler/dbf/'
> no database is open
> WARNUNG: Cannot copy table
> WARNUNG: Cannot copy <zipcodes_wake at PERMANENT> to current mapset as
>          <myzipcodes_wake>
>
> In db/drivers/dbf/db.c, I suggest to add a test around line 89 with
> # pseudocode
> if LOCATION/MAPSET/dbf/ does not exist
>    create it
>
> How to implement this in a portable way?
>   
Inspired by lib/gis/ code, I have now submitted a fix for this.
diff attached.

Markus

------------------
ITC -> dall'1 marzo 2007 Fondazione Bruno Kessler
ITC -> since 1 March 2007 Fondazione Bruno Kessler
------------------
-------------- next part --------------
? OBJ.x86_64-unknown-linux-gnu
? dc.diff
Index: db.c
===================================================================
RCS file: /grassrepository/grass6/db/drivers/dbf/db.c,v
retrieving revision 1.15
diff -u -r1.15 db.c
--- db.c	26 Apr 2007 13:02:12 -0000	1.15
+++ db.c	26 Apr 2007 13:40:31 -0000
@@ -17,6 +17,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <dirent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
 #include <grass/dbmi.h>
 #include <grass/gis.h>
 #include "globals.h"
@@ -78,11 +81,23 @@
 
     G_debug(2, "db.name = %s", db.name);
 
+    errno = 0;
     dir = opendir(db.name);
     if (dir == NULL) {
-	append_error("Cannot open dbf database: %s\n", name);
-	report_error();
-	return DB_FAILED;
+	if (errno == ENOENT) {
+	    int status;
+
+	    status = G_mkdir(db.name);
+	    if (status != 0) {	/* mkdir failed */
+		append_error("Cannot create dbf database: %s\n", name);
+		report_error();
+		return DB_FAILED;
+	    }
+	} else { /* some other problem */
+	    append_error("Cannot open dbf database: %s\n", name);
+	    report_error();
+	    return DB_FAILED;
+	}
     }
 
     while ((ent = readdir(dir))) {


More information about the grass-dev mailing list