[issue7512] shutil.copystat may fail EOPNOTSUPP

Joerg Sonnenberger report at bugs.python.org
Thu Mar 18 00:05:14 CET 2010


Joerg Sonnenberger <joerg at NetBSD.org> added the comment:

A better approach might be to change the function to:

def copystat(src, dst):
  st = os.stat(src)
  st_dst = os.stat(dst)
  mode = stat.S_IMODE(st.st_mode)
  mode_dst = stat.S_IMODE(st_dst.st_mode)
  if hasattr(os, 'utime'):
    if st.st_atime != st_dst.st_atime or st.st_mtime != st_dst.st_mtime
      os.utime(dst, (st.st_atime, st.st_mtime))
  if hasattr(os, 'chmod'):
    if mode != mode_dst:
      os.chmod(dst, mode)
  if hasattr(os, 'chflags') and hasattr(st, 'st_flags'):
    if st.st_flags != st_dst.st_flags:
      os.chflags(dst, st.st_flags)

This avoids the system calls for the (common) case of not having to change anything at all. Given that the flags are normally not set, it also avoids the problem with NFS.

----------
nosy: +joerg

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7512>
_______________________________________


More information about the Python-bugs-list mailing list