Merge pull request #2754 from tk0miya/2753_smartcopy

``sphinx.util.osutil.filecopy()`` skips copying if the file has not been changed (ref: #2510, #2753)
This commit is contained in:
Takeshi KOMIYA 2016-07-07 23:38:27 +09:00 committed by GitHub
commit 8a4b01a2b7
2 changed files with 13 additions and 7 deletions

View File

@ -23,6 +23,8 @@ Incompatible changes
``index.rst.txt``).
* ``sphinx.util.copy_static_entry()`` is now deprecated.
Use ``sphinx.util.fileutil.copy_asset()`` instead.
* ``sphinx.util.osutil.filecopy()`` skips copying if the file has not been changed
(ref: #2510, #2753)
Features added

View File

@ -17,6 +17,7 @@ import time
import errno
import locale
import shutil
import filecmp
from os import path
import contextlib
@ -141,13 +142,16 @@ def copytimes(source, dest):
def copyfile(source, dest):
"""Copy a file and its modification times, if possible."""
shutil.copyfile(source, dest)
try:
# don't do full copystat because the source may be read-only
copytimes(source, dest)
except OSError:
pass
"""Copy a file and its modification times, if possible.
Note: ``copyfile`` skips copying if the file has not been changed"""
if not path.exists(dest) or not filecmp.cmp(source, dest):
shutil.copyfile(source, dest)
try:
# don't do full copystat because the source may be read-only
copytimes(source, dest)
except OSError:
pass
no_fn_re = re.compile(r'[^a-zA-Z0-9_-]')