[GRASS-dev] Re: [bug #4450] (grass) g.remove vect: empty dirs in the $MAPSET/.tmp/$HOSTNAME left

Markus Neteler neteler at itc.it
Sun Jun 18 04:32:08 EDT 2006


On Sun, Jun 18, 2006 at 06:33:50AM +0100, Glynn Clements wrote:
> 
> Markus Neteler wrote:
> 
> > On Sat, Jun 17, 2006 at 09:00:19PM +0200, Markus Neteler wrote:
> > > On Sat, Jun 17, 2006 at 07:53:29PM +0200, Maciek Sieczka wrote:
> > ...
> > > > > > It is 'g.remove vect' that leaves empty temp dirs in the .tmp.
> > 
> > Now I understand and have the bug reproduced.
> > 
> > In fact g.remove vect=map somewhere creates a
> > directory in .tmp/ when removing an existing vector map.
> > It happens in G_find_vector2() which is called in
> > line 24 of 
> > general/manage/lib/do_remove.c
> 
> That's incorrect; it happens in Vect_delete() at line 26 of that file.
> 
> It appears that it moves the vector directory to the .tmp directory
> before trying to delete it, but doesn't delete it correctly. From
> Vect_delete(), in vector/Vlib/map.c:
> 
>     tmp = G_tempfile();
> 
>     G_debug (3, "rename '%s' to '%s'", buf, tmp );
>     ret = rename ( buf, tmp );
> 
>     if ( ret == -1 ) {
> 	G_warning ( "Cannot rename directory '%s' to '%s'", buf, tmp );
> 	return -1;
>     }
> 
>     G_debug (3, "unlink directory '%s'", tmp );
>     ret = unlink ( tmp );
> 
> unlink() doesn't work on directories, you have to use rmdir() instead.
> 
> Or, better still, remove(), which calls either unlink() or rmdir()
> depending upon whether the target is a directory; remove() is ANSI,
> whereas unlink() and rmdir() are POSIX.

Thanks for finding it. I have changed unlink() to remove() which
solves the problem.

Markus




More information about the grass-dev mailing list