[GRASS-dev] G_tempfile() proposed changes [relevant to creating a new location]

Glynn Clements glynn at gclements.plus.com
Sun Jan 7 05:51:35 EST 2007


Hamish wrote:

> Instead of changing G_tempfile() to G_tempfile_in_mapset(), why not leave
> G_tempfile() as-is and make a new G_tempfile_in_tmp() [or similar name] for the
> few cases that need that?

Because *most* usage of G_tempfile() doesn't need the file to reside
in the mapset directory. It's the existing behaviour which is a
special case.

Essentially, there's no reason for the two (mapset directory and
temporary directory) to be linked. Having them linked creates problems
if you need to create a temporary file (e.g. for G_asprintf()) when
you don't have a valid mapset, meaning that many libgis functions may
require a valid mapset for no good reason.

> As noted in an earlier post, there are cases (debugging, d.text, d.graph) where
> it is useful to leave small tmp files around for the rest of the session.

Right. However:

1. Such files don't need to persist between sessions.

2. If a module exits normally, we can assume that any temporary files
which it hasn't removed are meant to persist for the remainder of the
session.

3. If a module exits abnormally using G_fatal_error(), we may want to
automatically remove any temporary files which it created (the only
reason not to would be for debugging, and we can provide an
environment variable for this purpose).

For #3, it would help if we used a directory which was specific to
GRASS (e.g. /tmp/grass-<user>-<session-pid> rather than /tmp) so that
we don't have to worry about deleting something we shouldn't.

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




More information about the grass-dev mailing list