Skip to content

Fix image files not re-copied during incremental rebuilds#14319

Open
worksbyfriday wants to merge 1 commit intosphinx-doc:masterfrom
worksbyfriday:fix-image-copy-force
Open

Fix image files not re-copied during incremental rebuilds#14319
worksbyfriday wants to merge 1 commit intosphinx-doc:masterfrom
worksbyfriday:fix-image-copy-force

Conversation

@worksbyfriday
Copy link

Summary

Fixes #14312 — image files referenced by documents are not overwritten during incremental rebuilds when the image's modification time changes.

Root cause

copyfile(force=True) checks filecmp.cmp(source, dest, shallow=False) before considering the force flag. When source and destination have identical content (e.g. touch updated the mtime but not the bytes), the function short-circuits and skips the copy entirely — even though force=True was passed.

During incremental builds, copy_image_files() calls copyfile(..., force=True) for each image. The intent of force=True is to always overwrite, but the filecmp.cmp gate prevented this.

Fix

When force=True, skip the filecmp.cmp content comparison and always copy the file (updating both content and modification times). This makes force=True behave as documented: "Overwrite the destination file even if it exists."

Test

Added test_copyfile_force_overwrites_identical_content to verify that:

  • Without force, identical-content files are not re-copied (preserving the optimization)
  • With force=True, identical-content files are re-copied (mtime is updated)

🤖 Generated with Claude Code

When `force=True`, `copyfile` now overwrites the destination file even
if its content is identical to the source.  Previously, the
`filecmp.cmp(shallow=False)` check caused the copy to be skipped when
file contents matched, meaning modification times were never updated.

This fixes the issue where image files referenced by documents were not
re-copied during incremental rebuilds when only the image's mtime
changed (e.g. replacing an image with a new version of the same size).

Fixes sphinx-doc#14312

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants