[GRASS-dev] [grass-code I][566] g.rename fails to rename maps

On 21/12/07 15:33, grass-dev@lists.osgeo.org wrote:

But I can't find g.rename anywhere in my source tree; there's nothing on osgeo.org, either:

http://trac.osgeo.org/grass/browser/grass/trunk/general
http://trac.osgeo.org/grass/browser/grass/trunk/scripts

It's in manage:

http://trac.osgeo.org/grass/browser/grass/trunk/general/manage/cmd

Moritz

It's in manage:
http://trac.osgeo.org/grass/browser/grass/trunk/general/manage/cmd

Moritz

Thanks for the pointer. Is it still a bug, though? Can anyone confirm?

~ Eric.

On 21/12/07 16:01, Patton, Eric wrote:

It's in manage:
http://trac.osgeo.org/grass/browser/grass/trunk/general/manage/cmd

Moritz

Thanks for the pointer. Is it still a bug, though? Can anyone confirm?

Yup. It's due to line 28 in /general/manage/lib/do_rename.c (line

if (G_strcasecmp (old,new) == 0) return 1;

If you comment this out and recompile the lib and the command, it works. No idea why this is there. Unless someone objects, I'll remove that line.

Moritz

On 21/12/07 16:24, Moritz Lennert wrote:

On 21/12/07 16:01, Patton, Eric wrote:

It's in manage:
http://trac.osgeo.org/grass/browser/grass/trunk/general/manage/cmd

Moritz

Thanks for the pointer. Is it still a bug, though? Can anyone confirm?

Yup. It's due to line 28 in /general/manage/lib/do_rename.c (line

if (G_strcasecmp (old,new) == 0) return 1;

If you comment this out and recompile the lib and the command, it works. No idea why this is there. Unless someone objects, I'll remove that line.

Actually it is due to:
http://freegis.org/cgi-bin/viewcvs.cgi/grass6/general/manage/lib/do_rename.c.diff?r1=1.6&r2=1.7

where strcmp was replaced with G_strcasecmp, thus making the compare case independent. So, the line should not be removed, but it should either be reverted to strcmp, or we need G_strcmp, which doesn't exist at this stage AFAICT.

Moritz

On Fri, Dec 21, 2007 at 04:30:35PM +0100, Moritz Lennert wrote:

where strcmp was replaced with G_strcasecmp, thus making the compare
case independent. So, the line should not be removed, but it should
either be reverted to strcmp, or we need G_strcmp, which doesn't exist
at this stage AFAICT.

Just curious, what's the point in having wrappers for two POSIX
functions like them?

--
Francesco P. Lovergine

Moritz Lennert wrote:

>>> It's in manage:
>>> http://trac.osgeo.org/grass/browser/grass/trunk/general/manage/cmd
>>
>>> Moritz
>>
>> Thanks for the pointer. Is it still a bug, though? Can anyone confirm?
>
> Yup. It's due to line 28 in /general/manage/lib/do_rename.c (line
>
> if (G_strcasecmp (old,new) == 0) return 1;
>
> If you comment this out and recompile the lib and the command, it works.
> No idea why this is there. Unless someone objects, I'll remove that line.

Actually it is due to:
http://freegis.org/cgi-bin/viewcvs.cgi/grass6/general/manage/lib/do_rename.c.diff?r1=1.6&r2=1.7

where strcmp was replaced with G_strcasecmp, thus making the compare
case independent. So, the line should not be removed, but it should
either be reverted to strcmp, or we need G_strcmp, which doesn't exist
at this stage AFAICT.

The case insensitivity may have been intentional. What happens if you
try this with vector maps or under windows?

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

Francesco P. Lovergine wrote:

> where strcmp was replaced with G_strcasecmp, thus making the compare
> case independent. So, the line should not be removed, but it should
> either be reverted to strcmp, or we need G_strcmp, which doesn't exist
> at this stage AFAICT.
>

Just curious, what's the point in having wrappers for two POSIX
functions like them?

I suspect that G_strcasecmp() was originally added because GRASS ran
on systems which pre-dated the addition of strcasecmp() to POSIX. It
needs to remain, as Windows doesn't have strcasecmp().

There wouldn't be any point in having a G_strcmp() function.

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

On 21/12/07 22:06, Glynn Clements wrote:

Moritz Lennert wrote:

It's in manage:
http://trac.osgeo.org/grass/browser/grass/trunk/general/manage/cmd
Moritz

Thanks for the pointer. Is it still a bug, though? Can anyone confirm?

Yup. It's due to line 28 in /general/manage/lib/do_rename.c (line

if (G_strcasecmp (old,new) == 0) return 1;

If you comment this out and recompile the lib and the command, it works. No idea why this is there. Unless someone objects, I'll remove that line.

Actually it is due to:
http://freegis.org/cgi-bin/viewcvs.cgi/grass6/general/manage/lib/do_rename.c.diff?r1=1.6&r2=1.7

where strcmp was replaced with G_strcasecmp, thus making the compare case independent. So, the line should not be removed, but it should either be reverted to strcmp, or we need G_strcmp, which doesn't exist at this stage AFAICT.

The case insensitivity may have been intentional. What happens if you
try this with vector maps

Seems to work alright. Why should it be different from raster maps ?

or under windows?

Won't be able to try this for a while, unfortunately...

Moritz

The case insensitivity may have been intentional. What happens if you
try this with vector maps or under windows?

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

Again, in spearfish:

$ g.mlist pattern=r*
railroads
roads
rstrct.areas
rushmore

$ g.rename vect=roads,ROADS
Rename vector <roads> to <ROADS>

$ g.mlist -r pattern='^[R|r]'
railroads
roads
rstrct.areas
rushmore

Similarly, with regions:

$ g.list region
----------------------------------------------
region definition files available in mapset <PERMANENT>:
9961 county previous_zoom subregion.NW tributary

----------------------------------------------

$ g.rename region=county,COUNTY
Rename region definition <county> to <COUNTY>

$ g.list region
----------------------------------------------
region definition files available in mapset <PERMANENT>:
9961 county previous_zoom subregion.NW tributary

----------------------------------------------

~ Eric.

On 22/12/07 00:04, Moritz Lennert wrote:

On 21/12/07 22:06, Glynn Clements wrote:

Moritz Lennert wrote:

It's in manage:
http://trac.osgeo.org/grass/browser/grass/trunk/general/manage/cmd
Moritz

Thanks for the pointer. Is it still a bug, though? Can anyone confirm?

Yup. It's due to line 28 in /general/manage/lib/do_rename.c (line

if (G_strcasecmp (old,new) == 0) return 1;

If you comment this out and recompile the lib and the command, it works. No idea why this is there. Unless someone objects, I'll remove that line.

Actually it is due to:
http://freegis.org/cgi-bin/viewcvs.cgi/grass6/general/manage/lib/do_rename.c.diff?r1=1.6&r2=1.7

where strcmp was replaced with G_strcasecmp, thus making the compare case independent. So, the line should not be removed, but it should either be reverted to strcmp, or we need G_strcmp, which doesn't exist at this stage AFAICT.

The case insensitivity may have been intentional. What happens if you
try this with vector maps

Seems to work alright. Why should it be different from raster maps ?

Just to make myself clear: it works with the patch of commenting out the above line (and so I assume would work when using strcmp).

Moritz

Moritz Lennert wrote:

>>>>> It's in manage:
>>>>> http://trac.osgeo.org/grass/browser/grass/trunk/general/manage/cmd
>>>>> Moritz
>>>> Thanks for the pointer. Is it still a bug, though? Can anyone confirm?
>>> Yup. It's due to line 28 in /general/manage/lib/do_rename.c (line
>>>
>>> if (G_strcasecmp (old,new) == 0) return 1;
>>>
>>> If you comment this out and recompile the lib and the command, it works.
>>> No idea why this is there. Unless someone objects, I'll remove that line.
>> Actually it is due to:
>> http://freegis.org/cgi-bin/viewcvs.cgi/grass6/general/manage/lib/do_rename.c.diff?r1=1.6&r2=1.7
>>
>> where strcmp was replaced with G_strcasecmp, thus making the compare
>> case independent. So, the line should not be removed, but it should
>> either be reverted to strcmp, or we need G_strcmp, which doesn't exist
>> at this stage AFAICT.
>
> The case insensitivity may have been intentional. What happens if you
> try this with vector maps

Seems to work alright. Why should it be different from raster maps ?

Vector map names may be used as SQL column names, which aren't case
sensitive.

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

Patton, Eric wrote:

>The case insensitivity may have been intentional. What happens if you
>try this with vector maps or under windows?

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

Again, in spearfish:

$ g.mlist pattern=r*
railroads
roads
rstrct.areas
rushmore

$ g.rename vect=roads,ROADS
Rename vector <roads> to <ROADS>

$ g.mlist -r pattern='^[R|r]'
railroads
roads
rstrct.areas
rushmore

I meant: what happens if you remove the G_strcasecmp() check (or
replace it with strcmp()), then try it.

The problem is that the renaming code (both the generic code in
general/manage/lib/do_rename.c and the vector-specific code in
lib/vector/Vlib/map.c) deletes the destination before renaming the
source. If the source and destination are aliases for the same file
(or database table), then deleting the destination will delete the
source.

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