Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions sphinx/util/osutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import unicodedata
from io import StringIO
from os import path
from pathlib import Path
from typing import TYPE_CHECKING

from sphinx.locale import __

if TYPE_CHECKING:
from pathlib import Path
from types import TracebackType
from typing import Any

Expand Down Expand Up @@ -107,12 +107,15 @@ def copyfile(

.. note:: :func:`copyfile` is a no-op if *source* and *dest* are identical.
"""
if not path.exists(source):
msg = f'{os.fsdecode(source)} does not exist'
# coerce to Path objects
source = Path(source)
dest = Path(dest)
if not source.exists():
msg = f'{source} does not exist'
raise FileNotFoundError(msg)

if (
not (dest_exists := path.exists(dest)) or
not (dest_exists := dest.exists()) or
# comparison must be done using shallow=False since
# two different files might have the same size
not filecmp.cmp(source, dest, shallow=False)
Expand All @@ -125,7 +128,7 @@ def copyfile(

msg = __('Aborted attempted copy from %s to %s '
'(the destination path has existing data).')
logger.warning(msg, os.fsdecode(source), os.fsdecode(dest),
logger.warning(msg, source, dest,
type='misc', subtype='copy_overwrite')
return

Expand Down