[GRASS-dev] SEARCH_PATH: current mapset name laundering

Hi,

I sometimes need to rename mapsets and regularly run into the trap that
also the first row in the SEARCH_PATH files needs to be updated accordingly.
Since I tend to forget about this, maps in the current mapset are no longer
found and obscure errors pop up.

Questions:
- why does the current mapset needs to be specified at all in SEARCH_PATH?
- wouldn't it be better to auto-add the current mapset name internally?
- otherwise, could a test be added upon startup of GRASS to auto-add
   the current mapset name is missing from SEARCH_PATH?

Markus

Markus Neteler wrote:

I sometimes need to rename mapsets and regularly run into the trap that
also the first row in the SEARCH_PATH files needs to be updated accordingly.
Since I tend to forget about this, maps in the current mapset are no longer
found and obscure errors pop up.

Questions:
- why does the current mapset needs to be specified at all in SEARCH_PATH?

It doesn't "need" to be specified. You can have a search path which
doesn't include the current mapset.

However, this configuration will break many scripts, which tend to
assume that a map created by a previous command will be accessible via
its unqualified name.

Note that similar problems can occur if other mapsets are ahead of the
current mapset, as an unqualified name refers to the first map found
in the search path, not necessarily the one in the current mapset.

- wouldn't it be better to auto-add the current mapset name internally?
- otherwise, could a test be added upon startup of GRASS to auto-add
   the current mapset name is missing from SEARCH_PATH?

Realistically, I think that the current mapset must always be at the
head of the search path. Allowing it to be otherwise will be
error-prone.

Otherwise, we have to fix existing scripts to explicitly add the
current mapset to any temporary map names. It's much simpler to change
the library to match existing practice.

Currently, g.mapsets adds the current mapset to the front of the
search path if it isn't already present.

In libgis, if SEARCH_PATH doesn't exist, a default path is created
containing the current mapset followed by PERMANENT. If SEARCH_PATH
does exist, it is used verbatim; the current mapset won't be searched
if it isn't in SEARCH_PATH.

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

On Mon, May 2, 2011 at 7:05 PM, Glynn Clements <glynn@gclements.plus.com> wrote:

Markus Neteler wrote:

I sometimes need to rename mapsets and regularly run into the trap that
also the first row in the SEARCH_PATH files needs to be updated accordingly.
Since I tend to forget about this, maps in the current mapset are no longer
found and obscure errors pop up.

Questions:
- why does the current mapset needs to be specified at all in SEARCH_PATH?

It doesn't "need" to be specified. You can have a search path which
doesn't include the current mapset.

That's right (but rarely used).

However, this configuration will break many scripts, which tend to
assume that a map created by a previous command will be accessible via
its unqualified name.

Note that similar problems can occur if other mapsets are ahead of the
current mapset, as an unqualified name refers to the first map found
in the search path, not necessarily the one in the current mapset.

... in fact, it will be mostly asking for troubles.

- wouldn't it be better to auto-add the current mapset name internally?
- otherwise, could a test be added upon startup of GRASS to auto-add
the current mapset name is missing from SEARCH_PATH?

Realistically, I think that the current mapset must always be at the
head of the search path. Allowing it to be otherwise will be
error-prone.

Otherwise, we have to fix existing scripts to explicitly add the
current mapset to any temporary map names. It's much simpler to change
the library to match existing practice.

Definitely - I'd vote for a library update.

Currently, g.mapsets adds the current mapset to the front of the
search path if it isn't already present.

Yes, but this helps only if you call g.mapsets which is not necessarily
the case.

In libgis, if SEARCH_PATH doesn't exist, a default path is created
containing the current mapset followed by PERMANENT. If SEARCH_PATH
does exist, it is used verbatim; the current mapset won't be searched
if it isn't in SEARCH_PATH.

.. which was the trap I met too often in the past.

Markus

Markus Neteler wrote:

> Realistically, I think that the current mapset must always be at the
> head of the search path. Allowing it to be otherwise will be
> error-prone.
>
> Otherwise, we have to fix existing scripts to explicitly add the
> current mapset to any temporary map names. It's much simpler to change
> the library to match existing practice.

Definitely - I'd vote for a library update.

Try r46173.

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

On Tue, May 3, 2011 at 9:13 PM, Glynn Clements <glynn@gclements.plus.com> wrote:

Markus Neteler wrote:

> Realistically, I think that the current mapset must always be at the
> head of the search path. Allowing it to be otherwise will be
> error-prone.
>
> Otherwise, we have to fix existing scripts to explicitly add the
> current mapset to any temporary map names. It's much simpler to change
> the library to match existing practice.

Definitely - I'd vote for a library update.

Try r46173.

Thanks.
Attached the backport to GRASS 6 for a review.

Markus

(attachments)

mapset_nme.diff (1.01 KB)

On Tue, May 3, 2011 at 9:13 PM, Glynn Clements <glynn@gclements.plus.com> wrote:

Markus Neteler wrote:

> Realistically, I think that the current mapset must always be at the
> head of the search path. Allowing it to be otherwise will be
> error-prone.
>
> Otherwise, we have to fix existing scripts to explicitly add the
> current mapset to any temporary map names. It's much simpler to change
> the library to match existing practice.

Definitely - I'd vote for a library update.

Try r46173.

I now tested and something seems to be odd:

grass70 ~/grassdata/nc_spm_08/us/

GRASS 7.0.svn (nc_spm_08):~/grassdata/nc_spm_08 > g.gisenv
LOCATION_NAME=nc_spm_08
GISDBASE=/home/neteler/grassdata
MAPSET=neteler <--- ? should be "us"?
GRASS_GUI=text

by chance it is reflecting
cat ~/.grassrc7
DEBUG: 0
LOCATION_NAME: patUTM32
GISDBASE: /home/neteler/grassdata
MAPSET: neteler
GRASS_GUI: text

Subsequently/unrelatedly my GRASS 6 backport is
not functional yet.

Markus

Hi,

2011/5/7 Markus Neteler <neteler@osgeo.org>:

by chance it is reflecting
cat ~/.grassrc7

it should be .grass7/rc.

Martin

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

On Sat, May 7, 2011 at 11:28 PM, Markus Neteler <neteler@osgeo.org> wrote:

On Tue, May 3, 2011 at 9:13 PM, Glynn Clements <glynn@gclements.plus.com> wrote:

Markus Neteler wrote:

> Realistically, I think that the current mapset must always be at the
> head of the search path. Allowing it to be otherwise will be
> error-prone.
>
> Otherwise, we have to fix existing scripts to explicitly add the
> current mapset to any temporary map names. It's much simpler to change
> the library to match existing practice.

Definitely - I'd vote for a library update.

Try r46173.

I now tested and something seems to be odd:

grass70 ~/grassdata/nc_spm_08/us/

GRASS 7.0.svn (nc_spm_08):~/grassdata/nc_spm_08 > g.gisenv
LOCATION_NAME=nc_spm_08
GISDBASE=/home/neteler/grassdata
MAPSET=neteler <--- ? should be "us"?
GRASS_GUI=text

by chance it is reflecting

cat ~/.grass7/rc
LOCATION_NAME: nc_spm_08
GISDBASE: /home/neteler/grassdata
MAPSET: neteler
GRASS_GUI: text

Subsequently/unrelatedly my GRASS 6 backport is
not functional yet.

... still an issue...

Markus

On Tue, May 3, 2011 at 9:13 PM, Glynn Clements <glynn@gclements.plus.com> wrote:

Markus Neteler wrote:

> Realistically, I think that the current mapset must always be at the
> head of the search path. Allowing it to be otherwise will be
> error-prone.
>
> Otherwise, we have to fix existing scripts to explicitly add the
> current mapset to any temporary map names. It's much simpler to change
> the library to match existing practice.

Definitely - I'd vote for a library update.

Try r46173.

Something is odd now (yes, I did "make distclean"):

grass70 /grassdata/indonesia_utm49s/PERMANENT/

GRASS 7.0.svn (nc_spm_08):~ > g.gisenv
MAPSET=neteler
GISDBASE=/grassdata
LOCATION_NAME=nc_spm_08
GRASS_GUI=text

I guess because:
cat /home/neteler/.grass7/rc
MAPSET: neteler
GISDBASE: /grassdata
LOCATION_NAME: nc_spm_08
GRASS_GUI: text

I end up in a wrong location...

But perhaps it is unrelated to r46173, no idea.

Markus

Markus Neteler wrote:

Something is odd now (yes, I did "make distclean"):

grass70 /grassdata/indonesia_utm49s/PERMANENT/

GRASS 7.0.svn (nc_spm_08):~ > g.gisenv
MAPSET=neteler
GISDBASE=/grassdata
LOCATION_NAME=nc_spm_08
GRASS_GUI=text

I guess because:
cat /home/neteler/.grass7/rc
MAPSET: neteler
GISDBASE: /grassdata
LOCATION_NAME: nc_spm_08
GRASS_GUI: text

I end up in a wrong location...

But perhaps it is unrelated to r46173, no idea.

This looks like a bug in the startup script.

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

On Wed, May 25, 2011 at 1:22 PM, Glynn Clements
<glynn@gclements.plus.com> wrote:

Markus Neteler wrote:

Something is odd now (yes, I did "make distclean"):

grass70 /grassdata/indonesia_utm49s/PERMANENT/

GRASS 7.0.svn (nc_spm_08):~ > g.gisenv
MAPSET=neteler
GISDBASE=/grassdata
LOCATION_NAME=nc_spm_08
GRASS_GUI=text

I guess because:
cat /home/neteler/.grass7/rc
MAPSET: neteler
GISDBASE: /grassdata
LOCATION_NAME: nc_spm_08
GRASS_GUI: text

I end up in a wrong location...

But perhaps it is unrelated to r46173, no idea.

This looks like a bug in the startup script.

Should be fixed in r46463.

Markus M

On Tue, May 31, 2011 at 9:31 AM, Markus Metz
<markus.metz.giswork@googlemail.com> wrote:

On Wed, May 25, 2011 at 1:22 PM, Glynn Clements

Markus Neteler wrote:

...

I end up in a wrong location...

...

This looks like a bug in the startup script.

Should be fixed in r46463.

Markus M

Works, thanks.
Funny that nobody had the same problem over the past 12 or so months :slight_smile:

Markus

Hi,

2011/5/31 Markus Neteler <neteler@osgeo.org>:

Funny that nobody had the same problem over the past 12 or so months :slight_smile:

this bug has been probably introduced when modifying `-c` flag...

Martin

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