Skip to content

Instantly share code, notes, and snippets.

@ahgittin
Created October 26, 2016 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahgittin/0189585a359cdb772766ba2a173c1da3 to your computer and use it in GitHub Desktop.
Save ahgittin/0189585a359cdb772766ba2a173c1da3 to your computer and use it in GitHub Desktop.
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