[GRASS-dev] db/drivers/dbf/tables.c contains call to 'mv'

Moritz Lennert mlennert at club.worldonline.be
Tue Feb 27 05:43:08 EST 2007


On 20/02/07 18:18, Glynn Clements wrote:
> Moritz Lennert wrote:
> 
>> On lines 313 and 324 db/drivers/dbf/tables.c contains a call to 'mv'. This
>> fails under Windows as the command cannot be found.
>>
>> There is a #ifdef __MINGW32__ between the two calls. If this becomes true,
>> do we still need the mv calls ?
> 
> IMHO, that code (and the strikingly similar code in close_new() in
> lib/gis/closecell.c) is bogus. It should just be using rename().

Like this ?
I'll have to test on Windows tonight, now that the xdr problem is 
solved, but on GNU/Linux it works.

lib/gis/closecell.c does not use 'mv', so I guess it doesn't cause any 
problems in Windows, but I imagine you suggest to get rid of the

#ifdef __MINGW32__
         if ( CopyFile ( fcb->temp_name, path, FALSE ) == 0 ) {
#else
         if(link (fcb->temp_name, path) < 0) {
#endif

?

Moritz
-------------- next part --------------
--- table.c	2007-02-27 11:35:58.000000000 +0100
+++ table.c.new	2007-02-27 11:35:40.000000000 +0100
@@ -308,28 +308,12 @@
     DBFClose ( dbf );
 
     /* Copy */
-    /*
-    sprintf (cmd, "mv %s %s", name, db.tables[t].file );
-    if ( system (cmd) != 0 ) {
-	return DB_FAILED;
-    }
-    unlink ( name );
-    */
-#ifdef __MINGW32__
-    if ( CopyFile ( name, db.tables[t].file, FALSE ) == 0 ) {
-#else
-    if ( link ( name, db.tables[t].file ) < 0 ) {
-#endif
-        sprintf ( cmd, "mv %s %s", name, db.tables[t].file );
-        if ( system(cmd) ) {
+    if ( rename ( name, db.tables[t].file ) ) {
 	    append_error( "Cannot move %s\nto %s\n", 
                           name, db.tables[t].file );
             return DB_FAILED;
-        }
-    } else {
-	remove ( name );
-    }
-    
+    };
+
     return DB_OK;
 }
 


More information about the grass-dev mailing list