Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The reference to the same file is interpreted as a duplicate #1112

Closed
shimizukawa opened this issue Jan 3, 2015 · 4 comments
Closed

The reference to the same file is interpreted as a duplicate #1112

shimizukawa opened this issue Jan 3, 2015 · 4 comments

Comments

@shimizukawa
Copy link
Member

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:

#!rest

: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).


@shimizukawa
Copy link
Member Author

From Georg Brandl on 2013-03-30 11:44:40+00:00

Closes #1112: Avoid duplicate download files when referenced from documents in
different ways (absolute/relative).

→ <<cset 181b075>>

@shimizukawa
Copy link
Member Author

From Georg Brandl on 2013-03-30 11:44:59+00:00

Thanks for the report!

@shimizukawa
Copy link
Member Author

From Tawez on 2013-04-02 12:37:00+00:00

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

I think this would be a better fix:

#!python

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))

tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 17, 2021
`:download:` role creates duplicated copies when the document contains
two or more the role for the same file, but in different form.  It
considers two paths are different when one contains relative path like
`path/to/../file.dat`.

Internally, `env.relfn2path()` does not normalize the given path in
relative form.  As a result, download role can't detect the same paths
are given.  This adds `os.path.normpath()` to `env.relfn2path()` to
normalize the path.
@tk0miya tk0miya added this to the 3.5.0 milestone Jan 17, 2021
tk0miya added a commit to tk0miya/sphinx that referenced this issue Jan 17, 2021
`:download:` role creates duplicated copies when the document contains
two or more the role for the same file, but in different form.  It
considers two paths are different when one contains relative path like
`path/to/../file.dat`.

Internally, `env.relfn2path()` does not normalize the given path in
relative form.  As a result, download role can't detect the same paths
are given.  This adds `os.path.normpath()` to `env.relfn2path()` to
normalize the path.
tk0miya added a commit that referenced this issue Jan 18, 2021
Fix #1112: download role creates duplicated copies
@bashtage
Copy link

This is a bad fix. Breaks Windows builds.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants