[GRASS5] OVERWRITE

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

Radim

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).

I don't. Specifically when collecting data in the field & you are
working hard all day it is easy to mess up and no way to recollect the
data. Therefore make it hard to overwrite by mistake. This is why I put
an overwrite check in v.in.garmin (usual use for me is to hook up to
laptop and use up arrow in terminal to get last download command and
change the output= name to reflect the date/time).

Messing up while post-processing data is not so bad as long as the raw
data is not damaged. You can always use 'v.info -h' to quickly
reproduce. ?

Personally I like overwrite protection & to have to specifically use
the -o flag.

Hamish

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.

OTOH, such modules could just be re-written to open the output file
earlier.

It isn't strictly necessary to provide an "overwrite" option; the user
can always run g.remove first.

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

Hamish 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).

I don't. Specifically when collecting data in the field & you are
working hard all day it is easy to mess up and no way to recollect the
data. Therefore make it hard to overwrite by mistake. This is why I put
an overwrite check in v.in.garmin (usual use for me is to hook up to
laptop and use up arrow in terminal to get last download command and
change the output= name to reflect the date/time).

Messing up while post-processing data is not so bad as long as the raw
data is not damaged. You can always use 'v.info -h' to quickly
reproduce. ?

Personally I like overwrite protection & to have to specifically use
the -o flag.

For vectors you can use
g.gisenv set=OVERWRITE=0

Radim

Glynn Clements wrote:

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.

OTOH, such modules could just be re-written to open the output file
earlier.

It isn't strictly necessary to provide an "overwrite" option; the user
can always run g.remove first.

Yes, but it is convenient. For now g.remove occasionally we can add -o to modules.

Radim

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@gclements.plus.com>

Glynn Clements wrote:

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.

Done, added also 'overwrite' to GModule which is used by g.copy/rename.
'-o' removed from g.copy/rename, r.composite.

Maps can be overwritten either using --overwrite/--o or OVERWRITE grass
variable can be set to 1 (g.gisenv set=OVERWRITE=1).

Radim