[GRASS-dev] g.mremove bug?
Ivan Shmakov
ivan at theory.asu.ru
Fri Feb 22 01:41:20 EST 2008
May I suggest the following patch?
scripts/g.mremove/g.mremove: Fixed: don't hit the OS command line limits
by using `xargs'.
(nntp://news.gmane.org/gmane.comp.gis.grass.devel/25028)
--- a/scripts/g.mremove/g.mremove
+++ b/scripts/g.mremove/g.mremove
@@ -119,100 +119,40 @@ if [ $force -eq 1 ] ; then
g.message "Forcing ..."
fi
-r=$GIS_OPT_RAST
-r3=$GIS_OPT_RAST3D
-v=$GIS_OPT_VECT
-i=$GIS_OPT_ICON
-l=$GIS_OPT_LABEL
-rg=$GIS_OPT_REGION
-g=$GIS_OPT_GROUP
-d=$GIS_OPT_DVIEW
-
-if [ -n "$r" ] ; then
- rast=`g.mlist $regex type=rast sep=, mapset=$MAPSET pattern="$r"`
-fi
-
-if [ -n "$r3" ] ; then
- rast3d=`g.mlist $regex type=rast3d sep=, mapset=$MAPSET pattern="$r3"`
-fi
-
-if [ -n "$v" ] ; then
- vect=`g.mlist $regex type=vect sep=, mapset=$MAPSET pattern="$v"`
-fi
-
-if [ -n "$i" ] ; then
- icon=`g.mlist $regex type=icon sep=, mapset=$MAPSET pattern="$i"`
-fi
-
-if [ -n "$l" ] ; then
- labels=`g.mlist $regex type=labels sep=, mapset=$MAPSET pattern="$l"`
-fi
-
-if [ -n "$rg" ] ; then
- region=`g.mlist $regex type=region sep=, mapset=$MAPSET pattern="$rg"`
-fi
-
-if [ -n "$g" ] ; then
- group=`g.mlist $regex type=group sep=, mapset=$MAPSET pattern="$g"`
-fi
-
-if [ -n "$d" ] ; then
- dview=`g.mlist $regex type=3dview sep=, mapset=$MAPSET pattern="$d"`
-fi
-
-found=
-if [ "$rast" ] ; then
- found=1
- rast="rast=$rast"
-fi
-
-if [ "$rast3d" ] ; then
- found=1
- rast3d="rast3d=$rast3d"
-fi
-
-if [ "$vect" ] ; then
- found=1
- vect="vect=$vect"
-fi
-
-if [ "$icon" ] ; then
- found=1
- icon="icon=$icon"
-fi
-
-if [ "$labels" ] ; then
- found=1
- labels="labels=$labels"
-fi
-
-if [ "$region" ] ; then
- found=1
- region="region=$region"
-fi
-
-if [ "$group" ] ; then
- found=1
- group="group=$group"
-fi
-
-if [ "$dview" ] ; then
- found=1
- dview="3dview=$dview"
-fi
-
-if [ ! "$found" ] ; then
+tmp="$(g.tempfile pid=$$)"
+
+may_be () {
+ if [ -z "$2" ]; then
+ ## .
+ return
+ fi
+ g.mlist $regex type="$1" mapset="$MAPSET" pattern="$2" \
+ | sed -e s,^,"$1"=,
+}
+
+{
+ may_be rast "$GIS_OPT_RAST"
+ may_be rast3d "$GIS_OPT_RAST3D"
+ may_be vect "$GIS_OPT_VECT"
+ may_be icon "$GIS_OPT_ICON"
+ may_be labels "$GIS_OPT_LABEL"
+ may_be region "$GIS_OPT_REGION"
+ may_be group "$GIS_OPT_GROUP"
+ may_be 3dview "$GIS_OPT_DVIEW"
+} > "$tmp"
+
+if ! grep -q . -- "$tmp" ; then
g.message -e "No data found."
exit 1
fi
if [ $force -eq 0 ] ; then
g.message "The following files would be deleted:"
- echo "g.remove $rast $rast3d $vect $icon $labels $region $group $dview"
+ ## FIXME: should probably use `g.message'
+ cat -- "$tmp"
g.message message=""
g.message "You must use the force flag to actually remove them. Exiting."
exit 0
fi
-
-exec g.remove $rast $rast3d $vect $icon $labels $region $group $dview
+xargs g.remove < "$tmp"
More information about the grass-dev
mailing list