Re: [GRASS-dev] libgis: ERROR: Unable to make mapset element cell_misc/...

2009-03-07 Thread Markus Neteler
On Sat, Mar 7, 2009 at 8:29 AM, Glynn Clements gl...@gclements.plus.com wrote:
 Markus Neteler wrote:

  access() sets errno when it fails.
 
  If you want the reason why mkdir() failed, you need to test the return
  value from G_mkdir(), e.g.:
...
 Or is a second try to access unavoidable?

 It should be safe to remove the second access() call, but I would be
 inclined to leave it. Checking that the directory actually exists is
 more robust than assuming that it will from the fact that G_mkdir()
 succeeded.

Submitted with double error trapping.

Markus
___
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev


Re: [GRASS-dev] libgis: ERROR: Unable to make mapset element cell_misc/...

2009-03-06 Thread Markus Neteler
On Fri, Mar 6, 2009 at 10:35 AM, Maris Nartiss maris@gmail.com wrote:
 Hello,
 with ETX3 You can't have more than 31998 sub-directories per one
 directory [1]. It doesn't matter if You use 32 or 64 bit arch.

Sniff, right:
grep _LINK_MAX /usr/include/*/*
...
/usr/include/bits/posix1_lim.h:#define  _POSIX_LINK_MAX 8
/usr/include/ext2fs/ext2_fs.h:#define EXT2_LINK_MAX 32000
/usr/include/linux/ext2_fs.h:#define EXT2_LINK_MAX  32000
/usr/include/linux/ext3_fs.h:#define EXT3_LINK_MAX  32000
...
/usr/include/linux/minix_fs.h:#define MINIX_LINK_MAX250
/usr/include/linux/minix_fs.h:#define MINIX2_LINK_MAX   65530
/usr/include/linux/reiserfs_fs.h:#define REISERFS_LINK_MAX (MAX_US_INT - 1000)

grep MAX_US_INT /usr/include/*/*
/usr/include/linux/reiserfs_fs.h:#define MAX_US_INT 0x

Seems that I do need to split the mapset (expected 45000 maps).

Is this patch reasonable?

svn diff mapset_msc.c
Index: mapset_msc.c
===
--- mapset_msc.c(revision 36196)
+++ mapset_msc.c(working copy)
@@ -12,6 +12,7 @@
 #include string.h
 #include unistd.h
 #include stdlib.h
+#include errno.h
 #include sys/types.h
 #include sys/stat.h
 #include grass/gis.h
@@ -56,9 +57,10 @@
*p = 0;
if (access(path, 0) != 0)
G_mkdir(path);
-   if (access(path, 0) != 0)
-   G_fatal_error(_(Unable to make mapset element %s (%s)),
- p_element, path);
+   if (access(path, 0) != 0) {
+   G_fatal_error(_(Unable to make mapset element %s (%s): %s),
+ p_element, path, strerror(errno));
+   }
if (*element == 0)
return 1;
}

Strangly, it says:

r.in.gdal -o --o aqua_lst1km20090130.QC_Day.tif out=aqua_lst1km20090130.QC_Day
WARNING: Over-riding projection check
 100%
ERROR: Unable to make mapset element cell_misc/aqua_lst1km20090130.QC_Day
   
(/home/neteler/grassdata/patUTM32/modisLST005filt/cell_misc/aqua_lst1km20090130.QC_Day):
   No such file or directory

while it should say:

mkdir 
/home/neteler/grassdata/patUTM32/modisLST005filt/cell_misc/aqua_lst1km20090130.QC_Day
mkdir: cannot create directory
`/home/neteler/grassdata/patUTM32/modisLST005filt/cell_misc/aqua_lst1km20090130.QC_Day':
Too many links

?
Markus

PS: Just discovered that I had this problem already in Oct 2008.
Time to add better error trapping.
___
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev


Re: [GRASS-dev] libgis: ERROR: Unable to make mapset element cell_misc/...

2009-03-06 Thread Glynn Clements

Markus Neteler wrote:

 Is this patch reasonable?
 
 svn diff mapset_msc.c
 Index: mapset_msc.c
 ===
 --- mapset_msc.c(revision 36196)
 +++ mapset_msc.c(working copy)
 @@ -12,6 +12,7 @@
  #include string.h
  #include unistd.h
  #include stdlib.h
 +#include errno.h
  #include sys/types.h
  #include sys/stat.h
  #include grass/gis.h
 @@ -56,9 +57,10 @@
 *p = 0;
 if (access(path, 0) != 0)
 G_mkdir(path);
 -   if (access(path, 0) != 0)
 -   G_fatal_error(_(Unable to make mapset element %s (%s)),
 - p_element, path);
 +   if (access(path, 0) != 0) {
 +   G_fatal_error(_(Unable to make mapset element %s (%s): %s),
 + p_element, path, strerror(errno));
 +   }
 if (*element == 0)
 return 1;
 }
 
 Strangly, it says:
 
 r.in.gdal -o --o aqua_lst1km20090130.QC_Day.tif out=aqua_lst1km20090130.QC_Day
 WARNING: Over-riding projection check
  100%
 ERROR: Unable to make mapset element cell_misc/aqua_lst1km20090130.QC_Day

 (/home/neteler/grassdata/patUTM32/modisLST005filt/cell_misc/aqua_lst1km20090130.QC_Day):
No such file or directory
 
 while it should say:
 
 mkdir 
 /home/neteler/grassdata/patUTM32/modisLST005filt/cell_misc/aqua_lst1km20090130.QC_Day
 mkdir: cannot create directory
 `/home/neteler/grassdata/patUTM32/modisLST005filt/cell_misc/aqua_lst1km20090130.QC_Day':
 Too many links

access() sets errno when it fails.

If you want the reason why mkdir() failed, you need to test the return
value from G_mkdir(), e.g.:

if (access(path, 0) != 0)
if (G_mkdir(path) != 0)
G_fatal_error(_(Unable to make mapset element %s (%s): %s),
p_element, path, strerror(errno));

-- 
Glynn Clements gl...@gclements.plus.com
___
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev


Re: [GRASS-dev] libgis: ERROR: Unable to make mapset element cell_misc/...

2009-03-06 Thread Markus Neteler
On Sat, Mar 7, 2009 at 8:01 AM, Markus Neteler nete...@osgeo.org wrote:
 On Sat, Mar 7, 2009 at 6:34 AM, Glynn Clements gl...@gclements.plus.com 
 wrote:
 Markus Neteler wrote:
 ...
 access() sets errno when it fails.

 If you want the reason why mkdir() failed, you need to test the return
 value from G_mkdir(), e.g.:

        if (access(path, 0) != 0)
            if (G_mkdir(path) != 0)
                G_fatal_error(_(Unable to make mapset element %s (%s): %s),
                                p_element, path, strerror(errno));

 Ah thanks. I see now that access() is used twice:
 http://trac.osgeo.org/grass/browser/grass/trunk/lib/gis/mapset_msc.c#L57

 I assume that I can remove the first try? see attached patch.
 Or is a second try to access unavoidable?

For that please consider attached patch.

Markus


mapset_msc_dualtest.diff
Description: Binary data
___
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

Re: [GRASS-dev] libgis: ERROR: Unable to make mapset element cell_misc/...

2009-03-06 Thread Glynn Clements

Markus Neteler wrote:

  access() sets errno when it fails.
 
  If you want the reason why mkdir() failed, you need to test the return
  value from G_mkdir(), e.g.:
 
         if (access(path, 0) != 0)
             if (G_mkdir(path) != 0)
                 G_fatal_error(_(Unable to make mapset element %s (%s): %s),
                                 p_element, path, strerror(errno));
 
 Ah thanks. I see now that access() is used twice:
 http://trac.osgeo.org/grass/browser/grass/trunk/lib/gis/mapset_msc.c#L57
 
 I assume that I can remove the first try? see attached patch.
 Or is a second try to access unavoidable?

It should be safe to remove the second access() call, but I would be
inclined to leave it. Checking that the directory actually exists is
more robust than assuming that it will from the fact that G_mkdir()
succeeded.

-- 
Glynn Clements gl...@gclements.plus.com
___
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev