Empty destination paths are not preserved in `to_string()` for Files objects
leontristain opened this issue · comments
Steps to repro:
-
Download the NMM version of Skyrim Special Edition mod "Insects Begone" (https://www.nexusmods.com/skyrimspecialedition/mods/1190?tab=files). This version comes with a FOMOD installer.
-
Extract to a folder (let's say it's accessible at
src/insects-begone
) -
Observe the following behavior in python interpreter (using python 3.7.0, probably irrelevant):
>>> import pyfomod
>>> pyfomod.__version__
'0.8.1'
>>> root = pyfomod.parse('src/insects-begone')
>>> print(root.pages[1][1][0].files.to_string())
<files>
<folder source="Mesh Replacers\Webs" priority="2"/>
</files>
>>>
- The actual tag in the xml says:
<folder source="Mesh Replacers\Webs" destination="" priority="2"/>
I believe this is relevant as a matter of correctness because an empty string for destination
implies the root of the folder, while if destination
is not provided it means it should be the same value as the source. Let me know if my understanding is incorrect.
BTW, I fully understand that to_string() according to the docs is not generally recommended and that API isn't stable, I just encountered this because I'm using it anyway in order to parse out the priority information which is currently not supported by the Files object. There's no pressure, just thought to mention it and keep the issue logged. 😃
I believe this is relevant as a matter of correctness because an empty string for
destination
implies the root of the folder, while ifdestination
is not provided it means it should be the same value as the source. Let me know if my understanding is incorrect.
destination
defaults to an empty string when not present, that's why to_string()
omits it!
BTW, I fully understand that to_string() according to the docs is not generally recommended
I may have to rewrite the docs slightly, it's not that it's not recommended or somehow unusable, it just provides functionality that is generally not needed to the user (correct me if I'm wrong). write()
itself uses to_string()
to get the file contents.
Hi GandaG,
Sorry if this is beating a dead horse. It seems to me there's a case not handled by the 'default to an empty string' behavior, which is exactly what I was trying to call out.
According to the xml schema you have here: https://github.com/GandaG/fomod-schema/blob/master/ModuleConfig.xsd#L484, the destination
attribute says:
The path to which the file or folder should be installed. If omitted, the destination is the same as the source.
To me, this sounds like a tag that was originally written as:
<folder source="Mesh Replacers\Webs" destination="" priority="2"/>
... would end up installing the contents under <dest>/Mesh Replacers/Webs
if there's no distinction between an ommitted destination
attribute and an explicitly stated destination
attribute given an ''
as a value.
This is relevant because that Insects Begone fomod does intend to put the contents of Mesh Replacers/Webs
right at the root of the destination, instead of under <dest>/Mesh Replacers/Webs
, and I suspect other fomod installers might have done similar things.
Basically, the behavior with the tag omitted (according to your xml schema) and the behavior with the tag set to an empty string (according to existing FOMOD expected behaviors) are different.
In any case, if I'm wrong on this and seem totally crazy, feel free to ignore.
Thanks,
leontristain
It seems there's a doc error then (I believe that documentation is untouched from the original, it should benefit from a good cleaning), the missing destination defaults to an empty string (as it should).
Further testing at GandaG/fomod-docs#2 showed this as a bug (however stupid it is).