[GRASS-dev] G_check_input_output() and fully qualified output map name

Hi all,

I realized a strange behaviour of r.buffer, e.g.

$ r.buffer in=e out=e d=1

No error, input and output is the same...

$ r.buffer in=e out=e@user1 d=1
Illegal filename. Character <@> not allowed.
ERROR: <e@user> is an illegal file name

Why so restrictive? The current mapset is 'user1'.

I modified library function G_check_input_output() to handle also this case.

If mapset defined for output map is not the current one:
ERROR: Mapset defined for output map <e@user> is not the current mapset

Any objects to commit to CVS?

Martin

--
Martin Landa <landa.martin@gmail.com> * http://gama.fsv.cvut.cz/~landa *

(attachments)

legal_name.diff (4.4 KB)

Martin Landa wrote:

I realized a strange behaviour of r.buffer, e.g.

$ r.buffer in=e out=e d=1

No error, input and output is the same...

r.buffer uses
   opt2 = G_define_standard_option(G_OPT_R_OUTPUT);

which defines
   Opt->gisprompt = "new,cell,raster";

the parser does check that the given name doesn't already exist.
Have you set the --overwrite enviro variable to be always on?

For the above example I get:
  ERROR: option <output>: <e> exists.

Presumably if you abuse --overwrite you get what you asked for.

$ r.buffer in=e out=e@user1 d=1
Illegal filename. Character <@> not allowed.
ERROR: <e@user> is an illegal file name

Why so restrictive? The current mapset is 'user1'.

output maps can only be written to the current mapset*. Allowing '@' is
redundant, requires code (ie additional habitat for bugs) to check that
what's after the '@' matches G_mapset(), and might put ideas in people's
heads that 'output=map@other_mapset' isn't banned.

[*] i.rectify is the exception, it writes to the target mapset which
was set with i.target

I agree that the error message could be better.
If it were me, I'd keep it simple with something like

if ( G_legal_filename(output) == -1 ) {
   if(strchr(output, '@'))
      G_fatal_error(_("Output map name should not include a mapset"));
   ...

Hamish

Hi Hamish,

2007/10/31, Hamish <hamish_nospam@yahoo.com>:

Martin Landa wrote:
> I realized a strange behaviour of r.buffer, e.g.
>
> $ r.buffer in=e out=e d=1
>
> No error, input and output is the same...

r.buffer uses
   opt2 = G_define_standard_option(G_OPT_R_OUTPUT);

which defines
   Opt->gisprompt = "new,cell,raster";

the parser does check that the given name doesn't already exist.
Have you set the --overwrite enviro variable to be always on?

For the above example I get:
  ERROR: option <output>: <e> exists.

Presumably if you abuse --overwrite you get what you asked for.

Hm, right I used GRASS_OVERWITE=1. But anyway why not use
G_check_input_output() in r.buffer and other modules with input/output
raster/vector maps? To avoid the same input and output?

> $ r.buffer in=e out=e@user1 d=1
> Illegal filename. Character <@> not allowed.
> ERROR: <e@user> is an illegal file name
>
> Why so restrictive? The current mapset is 'user1'.

output maps can only be written to the current mapset*. Allowing '@' is
redundant, requires code (ie additional habitat for bugs) to check that
what's after the '@' matches G_mapset(), and might put ideas in people's
heads that 'output=map@other_mapset' isn't banned.

Right, my question was based on GUI work. You can select from a dialog
as the output existing map from the current mapset (which is always
given as 'map@mapset'). Of course '@mapset' can be removed when
creating command string in GUI or to extend G_check_input_output() to
check also for fully qualified map name.

[*] i.rectify is the exception, it writes to the target mapset which
was set with i.target

I agree that the error message could be better.
If it were me, I'd keep it simple with something like

if ( G_legal_filename(output) == -1 ) {
   if(strchr(output, '@'))
      G_fatal_error(_("Output map name should not include a mapset"));
   ...

Martin

Hamish

--
Martin Landa <landa.martin@gmail.com> * http://gama.fsv.cvut.cz/~landa *