snap xmllint (and thus xmlstarlet) fails to read files
sydb opened this issue · 0 comments
Is this a bug, or something I am doing wrong? Or both?
The xmllint
command (of libxml2 fame) will not open any local files. The xmlstarlet
command also will usually not open files, I presume because it is relying on libxml2 to open and parse them, but I do not know that.
Here is a shell console listing to demonstrate the problem.
$ #
$ # version of system and xmllint itself
$ #
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.1 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.1 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
$ which xmllint
/snap/bin/xmllint
$ xmllint --version
/snap/libxml2/69/bin/xmllint: using libxml version 20909-GITv2.9.9
compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 FTP HTTP DTDValid HTML Legacy C14N Catalog XPath XPointer XInclude Iconv ISO8859X Unicode Regexps Automata Expr Schemas Schematron Modules Debug Zlib Lzma
$ #
$ # input document
$ #
$ cat /tmp/tiny_duck.xml
<?xml version="1.0" encoding="UTF-8"?>
<duck>
<sound>quack</sound>
</duck>
$ #
$ # try it (it fails)
$ #
$ xmllint --format /tmp/tiny_duck.xml
I/O error : Permission denied
I/O error : Permission denied
warning: failed to load external entity "/tmp/tiny_duck.xml"
$ #
$ # Could it actually be a permissions problem?
$ # No, I just `cat`ted that file. But double-check,
$ # anyway.
$ #
$ ls -l /tmp/tiny_duck.xml
-rw-rw-r-- 1 syd syd 78 Jan 6 08:27 /tmp/tiny_duck.xml
$ whoami
syd
$ #
$ # try a different command that reads and parses XML on same file
$ #
$ which xmlwf
/usr/bin/xmlwf
$ xmlwf -v
xmlwf using expat_2.2.9
sizeof(XML_Char)=1, sizeof(XML_LChar)=1, XML_DTD, XML_CONTEXT_BYTES=1024, XML_NS
$ xmlwf -s -m -d /tmp/ERASE.ME/ /tmp/tiny_duck.xml
$ cat /tmp/ERASE.ME/tiny_duck.xml
<document>
<starttag name="duck" uri="/tmp/tiny_duck.xml" byte="39" nbytes="6" line="2" col="0"/>
<chars str=" " uri="/tmp/tiny_duck.xml" byte="45" nbytes="1" line="2" col="6"/>
<chars str=" " uri="/tmp/tiny_duck.xml" byte="46" nbytes="2" line="3" col="0"/>
<starttag name="sound" uri="/tmp/tiny_duck.xml" byte="48" nbytes="7" line="3" col="2"/>
<chars str="quack" uri="/tmp/tiny_duck.xml" byte="55" nbytes="5" line="3" col="9"/>
<endtag name="sound" uri="/tmp/tiny_duck.xml" byte="60" nbytes="8" line="3" col="14"/>
<chars str=" " uri="/tmp/tiny_duck.xml" byte="68" nbytes="1" line="3" col="22"/>
<endtag name="duck" uri="/tmp/tiny_duck.xml" byte="69" nbytes="7" line="4" col="0"/>
</document>
$
I was advised by m-hampl on launchpad that this might be because input file is on /tmp/. However, I only used a file on /tmp/ as a demonstration for this report. I actually ran into the problem with files in my ~/Documents/ directory.
I have since switched from using the snap version of libxml2 to the standard package via sudo apt install libxml2 libxml2-utils
, and both xmllint
and xmlstarlet
now work in this environment.