Skip to content

Sphinx does not overwrite outdated image files but does rebuild and overwrite rst documents that reference an image with a new mtime. #14312

@Robpol86

Description

@Robpol86

Describe the bug

When a Sphinx document references an image file, and if that image file's mtime is changed, Sphinx will rebuild the now-outdated document file, but it does not copy over the new image file. I expect both the out of date document to rebuild, but also the previously-copied image file to be overwritten by the new one. Example use cases are when you save a new image in the source directory with the same file name as an existing image. The output will still show the old image that's copied to _images.

How to Reproduce

Everything is run from a Docker container:

docker run -it --rm --entrypoint=bash python:3

Setup

mkdir docs && cd $_
pip install -U "sphinx>=5.3"
sphinx-quickstart --quiet --project Example --author Author
wget https://www.kernel.org/theme/images/logos/tux.png
echo ".. image:: tux.png" > index.rst
mkdir -p locales/en/LC_MESSAGES

Initial Build

touch -t 202601010000.00 index.rst tux.png
sphinx-build -NWv . _build/html

Reproduce

touch tux.png
sphinx-build -NWv . _build/html
stat index.rst tux.png _build/html/index.html _build/html/_images/tux.png

Stat output:

  File: index.rst
  Size: 19        	Blocks: 8          IO Block: 4096   regular file
Device: 0,62	Inode: 87362       Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2026-02-18 07:23:11.467451013 +0000
Modify: 2026-01-01 00:00:00.000000000 +0000
Change: 2026-02-18 07:23:07.834451011 +0000
 Birth: 2026-02-18 07:08:30.786248008 +0000
  File: tux.png
  Size: 7666      	Blocks: 16         IO Block: 4096   regular file
Device: 0,62	Inode: 87371       Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2026-02-18 07:23:29.258423007 +0000
Modify: 2026-02-18 07:23:24.722423005 +0000
Change: 2026-02-18 07:23:24.722423005 +0000
 Birth: 2026-02-18 07:08:59.554993007 +0000
  File: _build/html/index.html
  Size: 2478      	Blocks: 8          IO Block: 4096   regular file
Device: 0,62	Inode: 92886       Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2026-02-18 07:23:11.511451013 +0000
Modify: 2026-02-18 07:23:29.251423007 +0000
Change: 2026-02-18 07:23:29.251423007 +0000
 Birth: 2026-02-18 07:23:11.511451013 +0000
  File: _build/html/_images/tux.png
  Size: 7666      	Blocks: 16         IO Block: 4096   regular file
Device: 0,62	Inode: 92891       Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2026-02-18 07:23:29.258423007 +0000
Modify: 2026-01-01 00:00:00.000000000 +0000
Change: 2026-02-18 07:23:11.517451013 +0000
 Birth: 2026-02-18 07:23:11.517451013 +0000

Environment Information

Platform:              linux; (Linux-6.12.65-linuxkit-aarch64-with-glibc2.41)
Python version:        3.14.3 (main, Feb  4 2026, 20:09:05) [GCC 14.2.0])
Python implementation: CPython
Sphinx version:        9.1.0
Docutils version:      0.22.4
Jinja2 version:        3.1.6
Pygments version:      2.19.2

Sphinx extensions

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions