The reference to the same file is interpreted as a duplicate

Tawez avatarTawez created an issue

Tested on Windows 7 64bit machine, Python 2.7.3, Sphinx 1.1.3

If there is reference in various ways to the same resource, it is interpreted as different file with duplicate name.

If there is a files structure as follows:

[source]/
    document/
        downloads/archive.zip
        index.rst

And we have the following code in index.rst:

:download:`downloads/archive.zip`
:download:`/document/downloads/archive.zip`
:download:`../document/downloads/archive.zip`

Then during the build of html output we will have three files (while only one is expected):

[build]/
    _downloads/
        archive.zip
        archive1.zip
        archive2.zip

The same issue is with figure directive.

In attachment there is a simple Sphinx project just to illustrate the issue.

IMO the problem is because all paths in Sphinx code are not normalized (os.path.normpath() function is missing).

Comments (3)

  1. Tawez
    • changed status to open

    Proposed solution works for downloads, but doesn't work for images.

    I think this would be a better fix:

    def relfn2path(self, filename, docname=None):
        # ...
        try:
            return path.normpath(rel_fn), path.normpath(path.join(self.srcdir, rel_fn))
        except UnicodeDecodeError:
            return path.normpath(rel_fn), path.normpath(path.join(self.srcdir, enc_rel_fn))
    
  2. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.