Skip to content

Fix prevent dangling symlink from crashing the build#43

Merged
shenxianpeng merged 5 commits into
mainfrom
fix/dangling-symlink-crash
Apr 26, 2026
Merged

Fix prevent dangling symlink from crashing the build#43
shenxianpeng merged 5 commits into
mainfrom
fix/dangling-symlink-crash

Conversation

@shenxianpeng
Copy link
Copy Markdown
Member

@shenxianpeng shenxianpeng commented Apr 26, 2026

A dangling symlink in the docs directory would crash mkdocs build with an unhandled FileNotFoundError during file copy. os.walk lists the symlink as a regular file, but when shutil.copyfile (or os.path.getmtime) follows the symlink to a missing target, the uncaught OSError aborts the entire build.

Fix:

  • is_modified(): catch OSError when calling getmtime on the source — return False so the file is skipped silently.
  • copy_file(): catch OSError around copy and log a warning, then skip the file gracefully instead of crashing.

Closes: mkdocs/mkdocs#4048

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactor / code cleanup
  • CI / build / dependency update
  • Other (describe below)

Checklist

  • New tests added for new behavior (if applicable)
  • Documentation updated (if applicable)
  • Release notes docs/about/release-notes.md updated (if applicable)

@github-actions github-actions Bot added the bug Something isn't working label Apr 26, 2026
Comment thread docs/about/release-notes.md Outdated
@shenxianpeng shenxianpeng changed the title fix: prevent dangling symlink from crashing the build Fix prevent dangling symlink from crashing the build Apr 26, 2026
@shenxianpeng shenxianpeng force-pushed the fix/dangling-symlink-crash branch from 9921afd to 8e00488 Compare April 26, 2026 21:17
A dangling symlink in the docs directory would crash `mkdocs build` with an
unhandled FileNotFoundError during file copy. `os.walk` lists the symlink as
a regular file, but when `shutil.copyfile` (or `os.path.getmtime`) follows
the symlink to a missing target, the uncaught OSError aborts the entire build.

Fix:
- `is_modified()`: catch OSError when calling getmtime on the source — return
  False so the file is skipped silently.
- `copy_file()`: catch OSError around copy and log a warning, then skip the
  file gracefully instead of crashing.

Closes: mkdocs/mkdocs#4048
Co-authored-by: Xianpeng Shen <xianpeng.shen@gmail.com>
@shenxianpeng shenxianpeng force-pushed the fix/dangling-symlink-crash branch from 8e00488 to f786f49 Compare April 26, 2026 21:20
PR #3785 added early broken-symlink detection in utils.copy_file() that
logged a warning and returned early. PR #4048 added an except OSError
handler in files.py expecting the exception to propagate. Because the
early return short-circuited before shutil.copyfile, the OSError handler
was never reached, and the mkdocs.utils warning leaked to lastResort.

Fix: raise FileNotFoundError in utils.copy_file() instead of logging,
allowing the existing except OSError handler in files.py to catch it
and log with the mkdocs.structure.files logger as expected.
@shenxianpeng shenxianpeng merged commit 9949074 into main Apr 26, 2026
23 checks passed
@shenxianpeng shenxianpeng deleted the fix/dangling-symlink-crash branch April 26, 2026 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG - Dangling symlink crashes build

1 participant