This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: st_mtime differs after shutil.copy2
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.1
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, eric.araujo, loewis, maubp, python-dev, shaurz, vstinner
Priority: normal Keywords:

Created on 2010-10-19 23:14 by shaurz, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (7)
msg119176 - (view) Author: Luke McCarthy (shaurz) Date: 2010-10-19 23:14
When copying a file with shutil.copy2() between two ext4 filesystems on 64-bit Linux, the mtime of the destination file is different after the copy. It appears as if the resolution is slightly different, so the mtime is truncated slightly. For example:

source file mtime:      1287367331.8433506
destination file mtime: 1287367331.84335
msg119181 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2010-10-20 00:32
This is a system limitation. The underlying file system supports nanosecond resolution for the file stamps, and stat(2) also supports reporting them. However, utimes(2) only supports microsecond resolution when setting them.

Linux supports utimensat(2) since 2.6.22 (July 2007), however, Python doesn't use it. It would be possible to come up with a patch to transparently use it where available. Are you interested in writing such a patch?

As a consequential issue: For Python, a long time ago, it was decided that time stamps in system interfaces are floating point numbers. As a consequence, nanoseconds cannot be accurately represented for today's dates (IIUC). I doubt there is anything we could do about this; this is likely "won't fix".
msg127306 - (view) Author: Peter (maubp) Date: 2011-01-28 14:50
I'm also seeing this on 32bit Windows XP using Python 3.1.2, and Python 3.2rc1 on a local NTFS filesystem.

e.g. from os.stat(filename).st_mtime after using shutil.copy2(...)

1293634856.1402586 source
1293634856.1402581 copied

I've been using shutil.copy2 then expecting st_mtime will be equal (or at least that the copy file will be newer than the original). As you can see in this case, the copy is sometimes a fraction older.

The same issue occurs using shutil.copy then shutils.copystat (probably not a surprise).
msg134619 - (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) * (Python triager) Date: 2011-04-27 21:03
Python >=3.3 contains os.futimens() and os.utimensat() functions.

I have filed issue #11941, which suggests to add support for nanosecond resolution in result of os.stat().
msg155604 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-03-13 13:02
This issue is a duplicate of #14127.
msg160048 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-05-06 00:40
New changeset 709850f1ec67 by Larry Hastings in branch 'default':
Update Misc/NEWS for issues #14127 and #14705.  (And, technically, #10148.)
http://hg.python.org/cpython/rev/709850f1ec67
msg160055 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-05-06 04:58
New changeset 05274ab06182 by Larry Hastings in branch 'default':
Update Misc/NEWS for issues #14127 and #14705.  (And, technically, #10148.)
http://hg.python.org/cpython/rev/05274ab06182
History
Date User Action Args
2022-04-11 14:57:07adminsetgithub: 54357
2012-05-06 04:58:44python-devsetmessages: + msg160055
2012-05-06 00:40:16python-devsetnosy: + python-dev
messages: + msg160048
2012-03-13 13:02:05vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg155604

resolution: duplicate
2011-04-27 21:03:58Arfreversetmessages: + msg134619
2011-04-27 08:36:49eric.araujosetnosy: + eric.araujo
2011-01-28 15:14:49Arfreversetnosy: + Arfrever
2011-01-28 14:50:21maubpsetnosy: + maubp
messages: + msg127306
2010-10-20 00:32:33loewissetnosy: + loewis
messages: + msg119181
2010-10-19 23:14:29shaurzcreate