
On 5/15/25 10:42, Kirill Shchetiniuk via Devel wrote:
Hello everyone,
Sometime ago I sent a patch changing the XML schema to add GTK support for libvirt. As the type for one path argument, I used the <text/> type, simply copying the similar approach from another place in the XML schema definition. I was told that it's not the best way to use the <text/> type for paths and that absFilePath, a defined basic type for paths, should be used instead.
After this, I decided to fix this in a place where I had seen the same approach, too. After further investigation, I found a lot more places where the <text/> type is used for paths. Moreover, I found out that we have at least 4 type definitions for paths (files and directories). Some of these types accept simply everything, others paths starting with "/" or even Windows-style disk names.
Preface: libxml2 error reporting is horrible. At least wrt schema validation. It gives a binary result effectively: XML is valid, XML is not valid (and good luck figuring out why).
<define name="filePath"> <data type="string"> <param name="pattern">.+</param> </data> </define>
<define name="dirPath"> <data type="string"> <param name="pattern">.+</param> </data> </define>
These two ^^ should be merged into one IMO. Users will never get an error (from libxml2): "filePath expected, found dirPath" or vice versa.
<define name="absFilePath"> <data type="string"> <param name="pattern">(/|[a-zA-Z]:\\).+</param> </data> </define>
<define name="absDirPath"> <data type="string"> <param name="pattern">/.*</param> </data> </define>
This one is a bit tricky, because one accepts Windows style of paths (C:\someDir) the other doesn't. Initially, both were the same and the former was changed in v6.10.0-rc1~25 so we do want to accept Windows style of paths too. But then again, I don't see any value in having two separate rules.
According to this, I have the following questions:
1. Do we allow users to use relative paths, or MUST all paths be absolute?
I think we must keep relative paths, because we once allowed them.
2. Do we have to accept Windows-style paths everywhere?
3. Do we need to have different types for directories? For example, in some places, the filePath type is used for directory parameters.
And as a last question, do we want to unify the basic types related to paths to maintain the schemas more consistent?
What you could do is to define "relativePath" data type that would accept ".+" and then "absolutePath" that would be effectively the same as "absFilePath". Michal