This patch fixes the major problem: if /var/db/xmlcatalog gets empty
(after fail of the xmlcatalog(1), for example), it won't be either
accepted by xmlcatalog(1) or overwritten, causing strange errors
during calls of XML transformation tools. This, in particular, broke
my builds. Unfortunately, those tools do not say anything about this
file, I've debugged the problem by looking closely at ktrace output.

So I think in this case it's better to be safe than sorry. As an
additional feature, this scripts keeps the backup copy of database:
in this case, if the xmlcatalog(1) fails, the DB won't be altered
at all.

Comments? Okays?
--
zhuk@


Index: Makefile
===================================================================
RCS file: /cvs/ports/textproc/libxml/Makefile,v
retrieving revision 1.151
diff -u -p -r1.151 Makefile
--- Makefile    25 Sep 2013 12:32:22 -0000      1.151
+++ Makefile    24 Dec 2013 17:11:56 -0000
@@ -7,6 +7,8 @@ VERSION=                2.9.1
 DISTNAME=              libxml2-${VERSION}
 PKGNAME-main=          libxml-${VERSION}
 PKGNAME-python=                py-libxml-${VERSION}
+REVISION=              0
+
 SHARED_LIBS += xml2                 15.1     # 11.0
 CATEGORIES=            textproc
 MASTER_SITES=          http://gd.tuwien.ac.at/pub/libxml/ \
Index: files/rebuild
===================================================================
RCS file: /cvs/ports/textproc/libxml/files/rebuild,v
retrieving revision 1.1
diff -u -p -r1.1 rebuild
--- files/rebuild       4 Sep 2005 23:38:18 -0000       1.1
+++ files/rebuild       24 Dec 2013 17:11:56 -0000
@@ -1,18 +1,44 @@
 #! /bin/sh
 # written by Marc Espie, 2005.
+# improvements by Vadim Zhukov, 2013.
 # public domain
 
+set -e
+
 PREFIX=@PREFIX@
 dir=$PREFIX/share/libxml2
 catalog=/var/db/xmlcatalog
 cmd=$PREFIX/bin/xmlcatalog
+
+if [ -e $catalog ]; then
+       if [ -s $catalog ]; then
+               # create backup for extra safety
+               cp -- $catalog{,.bak}
+       else
+               # xmlcatalog fails for empty files
+               rm -- $catalog
+       fi
+fi
+
+restore_catalog() {
+       if [ -e $catalog.bak ]; then
+               mv -- $catalog{.bak,}
+       else
+               rm -f -- $catalog
+       fi
+}
+
+trap restore_catalog ERR
+
+# remove instead?
 $cmd --create --noout $catalog
-for i in $dir/*.spec
-do
-    # protect against no spec
-    test "$i" = $dir/'*.spec' ||
-       sed -e '/^#/d' -e "s,%D,$PREFIX," $i| 
-           while read type && read name && read url; do
+
+for i in $dir/*.spec; do
+       # protect against no spec
+       test "$i" = "$dir/*.spec" && break
+
+       sed -e '/^#/d' -e "s,%D,$PREFIX," "$i" | 
+       while read type && read name && read url; do
                $cmd --noout --add "$type" "$name" "$url" $catalog
-           done
+       done
 done

Reply via email to