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

Glynn Clements glynn at gclements.plus.com
Sun Jun 18 01:33:50 EDT 2006


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.

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list