Skip to content

st_mtime differs after shutil.copy2 #54357

Closed

Description

@shaurz
mannequin
BPO 10148
Nosy @loewis, @vstinner, @merwok, @peterjc

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2012-03-13.13:02:05.294>
created_at = <Date 2010-10-19.23:14:29.756>
labels = ['type-bug', 'library']
title = 'st_mtime differs after shutil.copy2'
updated_at = <Date 2012-05-06.04:58:44.461>
user = 'https://bugs.python.org/shaurz'

bugs.python.org fields:

activity = <Date 2012-05-06.04:58:44.461>
actor = 'python-dev'
assignee = 'none'
closed = True
closed_date = <Date 2012-03-13.13:02:05.294>
closer = 'vstinner'
components = ['Library (Lib)']
creation = <Date 2010-10-19.23:14:29.756>
creator = 'shaurz'
dependencies = []
files = []
hgrepos = []
issue_num = 10148
keywords = []
message_count = 7.0
messages = ['119176', '119181', '127306', '134619', '155604', '160048', '160055']
nosy_count = 7.0
nosy_names = ['loewis', 'vstinner', 'eric.araujo', 'Arfrever', 'maubp', 'shaurz', 'python-dev']
pr_nums = []
priority = 'normal'
resolution = 'duplicate'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue10148'
versions = ['Python 3.1']

Activity

  1. shaurz commented on Oct 19, 2010

    shaurzmannequin
    MannequinAuthor

    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

  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    type-bugAn unexpected behavior, bug, or error
    on Oct 19, 2010
  3. loewis commented on Oct 20, 2010

    loewismannequin
    Mannequin

    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".

  4. peterjc commented on Jan 28, 2011

    peterjcmannequin
    Mannequin

    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).

  5. Arfrever commented on Apr 27, 2011

    Arfrevermannequin
    Mannequin

    Python >=3.3 contains os.futimens() and os.utimensat() functions.

    I have filed issue bpo-11941, which suggests to add support for nanosecond resolution in result of os.stat().

  6. vstinner commented on Mar 13, 2012

    @vstinner
    Member

    This issue is a duplicate of bpo-14127.

  7. python-dev commented on May 6, 2012

    python-devmannequin
    Mannequin

    New changeset 709850f1ec67 by Larry Hastings in branch 'default':
    Update Misc/NEWS for issues bpo-14127 and bpo-14705. (And, technically, bpo-10148.)
    http://hg.python.org/cpython/rev/709850f1ec67

  8. python-dev commented on May 6, 2012

    python-devmannequin
    Mannequin

    New changeset 05274ab06182 by Larry Hastings in branch 'default':
    Update Misc/NEWS for issues bpo-14127 and bpo-14705. (And, technically, bpo-10148.)
    http://hg.python.org/cpython/rev/05274ab06182

  9. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions