[GRASS5] OVERWRITE

Glynn Clements glynn at gclements.plus.com
Sat Dec 4 15:35:05 EST 2004


Radim Blazek wrote:

> >>New GRASS users are usually surprised that most GRASS modules silently 
> >>or with warning overwrite existing maps. Most normal users
> >>however like this feature (AFAIK).
> >>
> >>Some modules have -o (overwrite) option ( e.g. r.composite, g.copy ).
> >>For vector maps it is possible to set OVERWRITE variable to 0
> >>to disable overwriting but default (if not set) is 1 (overwrite).
> >>
> >>My suggestion is:
> >>1) use OVERWRITE GRASS variable also in G_open_cell_new,
> >>    if OVERWRITE=0 and raster exists G_open_cell_new will call
> >>    G_fatal_error (?, not sure)
> >>2) change OVERWRITE default value to 0 (don't overwrite)
> >>3) Add a new function G_force_overwrite which can force
> >>    overwriting even if OVERWRITE=0. Modules with -o flag can use
> >>    if ( flag_o->answer )
> >>        G_force_overwrite();
> >>    before calling G_open_cell_new
> > 
> > 
> > Arguably, the check should be done in G_parser() rather than
> > G_open_cell_new() etc. I.e. if the gisprompt field contains "new",
> > G_parser() would generate an error if the map/file already exists.
> > The reason being that a module could spend a long time processing
> > before it opens the output file.
> 
> In G_parser() it is impossible to use overwrite flag.

Unless the flag is "registered" as the overwrite flag before
G_parser() is called. We can't just hardcode -o as some modules give
it a different meaning (e.g. d.rast, r.in.gdal).

We could have a dedicated flag, e.g. --overwrite (including
abbreviations, e.g. --o). Although that would require scanning the
argument list twice, unless it was required to come first.

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




More information about the grass-dev mailing list