diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2016-07-07 11:46:42 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2016-07-07 12:04:03 +0900 |
commit | d99c6c11fc01eea13a62f0a600bc1187b0345e42 (patch) | |
tree | c7d332aa5c384151718055080a8f3240b9c06d56 /sphinx/util/osutil.py | |
parent | 8fdbdc3fa9acf27cb6f07c132c0faf8f8dd4bd51 (diff) | |
download | sphinx-git-d99c6c11fc01eea13a62f0a600bc1187b0345e42.tar.gz |
``sphinx.util.osutil.filecopy()`` skips copying if the file has not been changed (ref: #2510, #2753)
Diffstat (limited to 'sphinx/util/osutil.py')
-rw-r--r-- | sphinx/util/osutil.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py index 585dc6104..0de6d8472 100644 --- a/sphinx/util/osutil.py +++ b/sphinx/util/osutil.py @@ -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_-]') |