tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: python2.6 copystat and NFS, and mercurial

On Wed, Mar 17, 2010 at 03:09:58AM +0000, David Holland wrote:
> Back in September I suggested this:
>  : Maybe have os.chflags suppress the error if errno == EOPNOTSUPP and
>  : the flags argument is 0?
> Thoughts anyone?

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 != 
                        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)

should do the trick. E.g. only issue update syscalls if they would
actually change something. Should also reduce the number of system


Home | Main Index | Thread Index | Old Index