Skip to content

Commit 3f13000

Browse files
committed
Don't rely on xmlstarlet transparently decompressing files
This feature was removed by default in libxml2 2.15.0 and decompression must now be explicitly done. Fortunately, gzip offers a mode where it will decompress when possible or just pass the data through if uncompressed, so all file types that are or might be compressed now call gzip to read the data before passing it to xmlstarlet.
1 parent d346e53 commit 3f13000

2 files changed

Lines changed: 12 additions & 27 deletions

File tree

autodescribe

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -733,25 +733,12 @@ comment_stl () {
733733
}
734734

735735
# File type: svg (Scalable Vector Graphics image)
736-
# requires: xmlstarlet
737-
comment_svg () {
738-
COMMENT=$(xmlstarlet sel -t -v "/*[local-name()='svg']/*[local-name()='title']" < "$1" 2> /dev/null)
739-
if [ -z "$COMMENT" ] ; then
740-
# Try for title in metadata
741-
COMMENT=$(xmlstarlet sel -t -v "/*[local-name()='svg']/*[local-name()='metadata']/*[local-name()='RDF']/*[local-name()='Work']/*[local-name()='title']" < "$1" 2> /dev/null)
742-
fi
743-
}
744-
745-
# File type: svgz (Compressed Scalable Vector Graphics image)
746736
# requires: gzip, xmlstarlet
747-
# TODO: xmlstarlet can optionally transparently decompress, but that feature is
748-
# likely to be removed some time after 2025 so we shouldn't rely on it here (or
749-
# for certain other file types).
750-
comment_svgz () {
751-
COMMENT=$(gzip -dc < "$1" | xmlstarlet sel -t -v "/*[local-name()='svg']/*[local-name()='title']" 2> /dev/null)
737+
comment_svg () {
738+
COMMENT=$(gzip -dcf < "$1" | xmlstarlet sel -t -v "/*[local-name()='svg']/*[local-name()='title']" 2> /dev/null)
752739
if [ -z "$COMMENT" ] ; then
753740
# Try for title in metadata
754-
COMMENT=$(gzip -dc < "$1" | xmlstarlet sel -t -v "/*[local-name()='svg']/*[local-name()='metadata']/*[local-name()='RDF']/*[local-name()='Work']/*[local-name()='title']" 2> /dev/null)
741+
COMMENT=$(gzip -dcf < "$1" | xmlstarlet sel -t -v "/*[local-name()='svg']/*[local-name()='metadata']/*[local-name()='RDF']/*[local-name()='Work']/*[local-name()='title']" 2> /dev/null)
755742
fi
756743
}
757744

@@ -1084,9 +1071,9 @@ comment_gif () {
10841071
}
10851072

10861073
# File type: gnumeric (Gnumeric spreadsheet)
1087-
# requires: xmlstarlet
1074+
# requires: gzip, xmlstarlet
10881075
comment_gnumeric () {
1089-
COMMENT=$(xmlstarlet sel -N gnm=http://www.gnumeric.org/v10.dtd -N office=urn:oasis:names:tc:opendocument:xmlns:office:1.0 -N dc=http://purl.org/dc/elements/1.1/ -t -v '/gnm:Workbook/office:document-meta/office:meta/dc:title' < "$1")
1076+
COMMENT=$(gzip -dcf < "$1" | xmlstarlet sel -N gnm=http://www.gnumeric.org/v10.dtd -N office=urn:oasis:names:tc:opendocument:xmlns:office:1.0 -N dc=http://purl.org/dc/elements/1.1/ -t -v '/gnm:Workbook/office:document-meta/office:meta/dc:title')
10901077
}
10911078

10921079
# File type: gpx (GPX GPS track)
@@ -1695,9 +1682,7 @@ for f in "$@" ; do
16951682
;;
16961683
*.stl) TYPE=stl
16971684
;;
1698-
*.svg) TYPE=svg
1699-
;;
1700-
*.svgz) TYPE=svgz
1685+
*.svg | *.svgz) TYPE=svg
17011686
;;
17021687
*.tar) TYPE=tar
17031688
;;

automtime

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,9 @@ mtime_bgcode () {
327327
}
328328

329329
# File type: gnumeric (Gnumeric spreadsheet)
330-
# requires: xmlstarlet
330+
# requires: gzip, xmlstarlet
331331
mtime_gnumeric () {
332-
RAWTIME=$(xmlstarlet sel -N gnm=http://www.gnumeric.org/v10.dtd -N office=urn:oasis:names:tc:opendocument:xmlns:office:1.0 -N dc=http://purl.org/dc/elements/1.1/ -t -v '/gnm:Workbook/office:document-meta/office:meta/dc:date' < "$1")
332+
RAWTIME=$(gzip -dcf < "$1" | xmlstarlet sel -N gnm=http://www.gnumeric.org/v10.dtd -N office=urn:oasis:names:tc:opendocument:xmlns:office:1.0 -N dc=http://purl.org/dc/elements/1.1/ -t -v '/gnm:Workbook/office:document-meta/office:meta/dc:date')
333333
# $RAWTIME is like 2022-04-04T17:07:51Z
334334
TIME="$(normalize_iso_time "$RAWTIME")"
335335
}
@@ -525,9 +525,9 @@ mtime_kra () {
525525
}
526526

527527
# File type: kmy (KMyMoney file)
528-
# requires: xmlstarlet
528+
# requires: gzip, xmlstarlet
529529
mtime_kmy () {
530-
RAWTIME=$(xmlstarlet sel -t -v /KMYMONEY-FILE/FILEINFO/LAST_MODIFIED_DATE/@date < "$1" )
530+
RAWTIME=$(gzip -dcf < "$1" | xmlstarlet sel -t -v /KMYMONEY-FILE/FILEINFO/LAST_MODIFIED_DATE/@date)
531531
# $RAWTIME is like 2022-01-01
532532
TIME="$RAWTIME"
533533
}
@@ -839,9 +839,9 @@ mtime_stardict () {
839839
}
840840

841841
# File type: svg (Scalable Vector Graphics image)
842-
# requires: xmlstarlet
842+
# requires: gzip, xmlstarlet
843843
mtime_svg () {
844-
RAWTIME=$(xmlstarlet sel -t -v "/*[local-name()='svg']/*[local-name()='metadata']/*[local-name()='RDF']/*[local-name()='Work']/*[local-name()='date']" < "$1" 2>/dev/null)
844+
RAWTIME=$(gzip -dcf < "$1" | xmlstarlet sel -t -v "/*[local-name()='svg']/*[local-name()='metadata']/*[local-name()='RDF']/*[local-name()='Work']/*[local-name()='date']" 2>/dev/null)
845845
# $RAWTIME can be just about anything, but DublinCore recommends ISO 8601-1.
846846
# Anything else is too ambiguous, so ignore them.
847847
if echo "$RAWTIME" | grep '^[012][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9]' >/dev/null; then

0 commit comments

Comments
 (0)