Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
for l in locations/* ; do
ENT=`xmlstarlet sel -t -v "location/locationConfig/callerContext/entityProxy" $l`
if [ ! -z "$ENT" ] ; then
if [ -z `find . -name $ENT` ] ; then
# it's a leak
LOC=`basename $l`
echo "Detected location $LOC has reference to deleted entity $ENT - removing it"
rm $l
FILES=`grep -l $LOC locations/*`
if [ ! -z "$FILES" ] ; then
echo " also referenced from $FILES - removing the references there"
for p in $FILES ; do
# finds "children" references
xmlstarlet ed -O -d "location/children/string[text()='"$LOC"']" $p > ${p}.bk
mv ${p}.bk $p
# finds "RebindingJcloudsLocation" references
xmlstarlet ed -O -d "location/locationConfig/vmInstanceIds/map/entry[locationProxy/text()= \
'"$LOC"']" $p > ${p}.bk
mv ${p}.bk $p
done
FILES=`grep -l $LOC locations/*`
if [ ! -z "$FILES" ] ; then
echo "WARN reference to $LOC in $FILES could not be removed;" \
"may need manual editing or rebind ignore instruction"
fi
fi
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment