Hi DiapDealer,
IMO, the only sane way to do this is to build the original path from the ebook root (normalized) to the file's original location in the epub and use that as a lookup key linked to its new position inside Sigil's ebook structure.
Then for each file that has links that need updating, take its original position relative to root, add it to whatever href or url that is linked, then normalize it (QDir::cleanPath or similar functions) to generate a string to match against the the set of updates key value pairs generated when the epub was imported by walking the manifest.
This way works but we never ran into a case where the key itself was not properly normalized as most paths relative to the the ebook root were OEBPS/something without any "../" . So your solution of normalizing the key is correct and works as long as we normalize to ebook root, the value we look up to match how the key was designed.
So unless I am messed up, I think your approach is the same as mine, it just means we need to normpath both the key and the lookup value based on the original file location plus the decoded url as well.
The bug was we never ran into a case where the key itself had an ../ in the path (ie. other epubs followed the epub spec recommendation) but now we handle that and normalize the key itself given some manifest links now had "../" in them.
Take care,
KevinH
Quote:
Originally Posted by DiapDealer
As far as the OPF is concerned, part of the problem is that paths like "OEBPS/../cover.jpg" passed in the keylist parameter to xmlprocessor.performOPFSourceUpdates() are not matching the ../cover.jpg href in the OPF manifest ... so no updates are performed on those entries (even though the new/correct path is available in the valuelist parameter).
os.path.normpath-ing the keylist entries will allow the match to happen and the OPF file will be properly updated, but that does nothing for the NCX entries, or any of the links in the xhtml, or the xref:link parameter in the SVG cover code. I have a feeling there's a more universal change to be made that will handle the overall situation better that I'm missing.
|