From efa16ae0c7812c8dca78c98388086b6e8b16c525 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Thu, 6 Aug 2009 21:22:12 +0200 Subject: [PATCH] #205: When copying files, don't copy full stat info, only modification times. --- CHANGES | 3 +++ sphinx/util/__init__.py | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 4260cffdb..2033e8b67 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,9 @@ Release 0.6.3 (in development) ============================== +* #205: When copying files, don't copy full stat info, only + modification times. + * #232: Support non-ASCII metadata in Qt help builder. * Properly format bullet lists nested in definition lists for LaTeX. diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index 40d4e323c..ec7f164fa 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -12,6 +12,7 @@ import os import re import sys +import stat import time import types import shutil @@ -399,11 +400,22 @@ def movefile(source, dest): os.rename(source, dest) +def copytimes(source, dest): + """Copy a file's modification times.""" + st = os.stat(source) + mode = stat.S_IMODE(st.st_mode) + if hasattr(os, 'utime'): + os.utime(dest, (st.st_atime, st.st_mtime)) + + def copyfile(source, dest): """Copy a file and its modification times, if possible.""" shutil.copyfile(source, dest) - try: shutil.copystat(source, dest) - except shutil.Error: pass + try: + # don't do full copystat because the source may be read-only + copytimes(source, dest) + except shutil.Error: + pass def copy_static_entry(source, target, builder, context={}):