diff options
author | Mike Frysinger <vapier@gentoo.org> | 2021-10-02 02:14:19 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2021-10-02 02:14:19 -0400 |
commit | 0bb79addc38cc95fd0e98b681ea7c626f0d7d21b (patch) | |
tree | 47d1f58c60c6e19505691600a0a6278839c3f7f6 | |
parent | Prepend ROOT with "/." when "//" redirects to network (as in Cygwin). (diff) | |
download | build-docbook-catalog-0bb79addc38cc95fd0e98b681ea7c626f0d7d21b.tar.gz build-docbook-catalog-0bb79addc38cc95fd0e98b681ea7c626f0d7d21b.tar.bz2 build-docbook-catalog-0bb79addc38cc95fd0e98b681ea7c626f0d7d21b.zip |
handle corrupt catalogs gracefully
If the files get corrupted for any reason (i.e. are not valid XML),
the current code gets wedged and is unable to recover until the user
deletes or fixes them. Instead, let's throw them away and start over.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
-rwxr-xr-x | build-docbook-catalog | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/build-docbook-catalog b/build-docbook-catalog index 1c7f103..6950f3e 100755 --- a/build-docbook-catalog +++ b/build-docbook-catalog @@ -161,6 +161,11 @@ multi_xmlcatalog_add() { create_catalogs() { local adds + # Initialize catalogs if they don't exist or are corrupt. + if ! xmllint "${ROOT}${ROOTCATALOG}" >&/dev/null ; then + rm -f "${ROOTCATALOG}" + echo "Deleting corrupt ${ROOT}${ROOTCATALOG} and starting over" + fi if [[ ! -r ${ROOT}${ROOTCATALOG} ]] ; then echo "Creating XML Catalog root ${ROOTCATALOG}" xmlcatalog --noout --create "${ROOT}${ROOTCATALOG}" @@ -174,6 +179,11 @@ create_catalogs() { clean_catalog "file://${CATALOG}" "${ROOTCATALOG}" fi + # Initialize catalogs if they don't exist or are corrupt. + if ! xmllint "${ROOT}${CATALOG}" >&/dev/null ; then + rm -f "${ROOT}${CATALOG}" + echo "Deleting corrupt ${CATALOG} and starting over" + fi if [[ ! -r ${ROOT}${CATALOG} ]] ; then echo "Creating DocBook XML Catalog ${CATALOG}" xmlcatalog --noout --create "${ROOT}${CATALOG}" |