Created
October 30, 2012 18:07
-
-
Save russelldavis/3981940 to your computer and use it in GitHub Desktop.
Workaround for truncation when writing file timestamps in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def copy_mtime(src, dest): | |
# Don't use os.utime() or shutil.copystat() -- these both truncate the | |
# time due to python's float not having as much resolution as the | |
# filesystem -- see http://ciaranm.wordpress.com/2009/11/15/this-week-in-python-stupidity-os-stat-os-utime-and-sub-second-timestamps/ | |
# | |
# If the truncation during reading (from os.stat()) was the same as the | |
# truncation during writing, the problem would be transparent here (but | |
# would still affect other non-truncating code), however python takes the | |
# problem to a new level and truncates an extra decimal place during write. | |
# Either way, it's best to avoid the write truncation altogether. | |
subprocess.check_call(["touch", "-r", src, dest]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment