public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* cygwin python os.stat gives wrong ctime
@ 2016-05-29 10:14 Mitch Deoudes
  2016-05-29 10:58 ` Eliot Moss
  2016-05-30  9:38 ` Corinna Vinschen
  0 siblings, 2 replies; 6+ messages in thread
From: Mitch Deoudes @ 2016-05-29 10:14 UTC (permalink / raw)
  To: cygwin

According to the python docs, os.stat() gives the following for st_ctime:

     "|st_ctime| - platform dependent; time of most recent metadata 
change on Unix, or the time of creation on Windows"

To reproduce:
     1) touch foo
     2) wait a minute
     3) touch foo
     4) use python's os.stat() on the file foo

cygwin's python 2.7.10 gives (me) the same number for mtime, ctime, and 
atime:

     posix.stat_result(st_mode=33276, st_ino=40532396646393057, 
st_dev=1079873317, st_nlink=1, st_uid=1001, st_gid=513, st_size=0, 
st_atime=1464482278, st_mtime=1464482278, st_ctime=1464482278)

However, cygwin's built-in stat command gives (correctly) the addtional 
"birth time", which is different:

     Access: 2016-05-28 20:37:58.748977000 -0400
     Modify: 2016-05-28 20:37:58.748977000 -0400
     Change: 2016-05-28 20:37:58.748977000 -0400
     Birth: 2016-05-28 20:36:34.514159100 -0400

The non-cygwin version of Windows python from python.org (v2.7.11) 
behaves correctly as per spec:

     nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0L, st_nlink=0, 
st_uid=0, st_gid=0, st_size=0L, st_atime=1464482278L, 
st_mtime=1464482278L, st_ctime=1464482194L)

Am I missing something, or is this a bug in cygwin's python?  You could 
argue that ctime is properly "change" and not "birth", but that's not 
what the python spec says it should be on Windows.

More importantly, is there some other way of getting the "birth" time 
from within cygwin's python?  I'm currently calling out to the cygwin 
shell using os.popen('stat "%W" <file>'), but that's not particularly 
efficient, and it doesn't give subsecond precision.

mitch

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: cygwin python os.stat gives wrong ctime
  2016-05-29 10:14 cygwin python os.stat gives wrong ctime Mitch Deoudes
@ 2016-05-29 10:58 ` Eliot Moss
  2016-05-30  8:09   ` Mitch Deoudes
  2016-05-30  9:38 ` Corinna Vinschen
  1 sibling, 1 reply; 6+ messages in thread
From: Eliot Moss @ 2016-05-29 10:58 UTC (permalink / raw)
  To: cygwin

On 5/28/2016 9:39 PM, Mitch Deoudes wrote:
> According to the python docs, os.stat() gives the following for st_ctime:
>
>     "|st_ctime| - platform dependent; time of most recent metadata change on Unix, or the time of
> creation on Windows"

cygwin emulates posix, so you should expect a posix-like result.
That is what you're getting.  I don't really see grounds for
complaint.  If you want a Windows python, Anaconda seems good ...

Regards -- Eliot Moss

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Re: cygwin python os.stat gives wrong ctime
  2016-05-29 10:58 ` Eliot Moss
@ 2016-05-30  8:09   ` Mitch Deoudes
  2016-05-30 17:00     ` Eliot Moss
  0 siblings, 1 reply; 6+ messages in thread
From: Mitch Deoudes @ 2016-05-30  8:09 UTC (permalink / raw)
  To: cygwin



On 5/28/2016 10:35 PM, Eliot Moss wrote:
> On 5/28/2016 9:39 PM, Mitch Deoudes wrote:
>> According to the python docs, os.stat() gives the following for 
>> st_ctime:
>>
>>     "|st_ctime| - platform dependent; time of most recent metadata 
>> change on Unix, or the time of
>> creation on Windows"
>
> cygwin emulates posix, so you should expect a posix-like result.

I understand your argument, and offer the following, which is from the 
same section of the python docs:

     "On other Unix systems (such as FreeBSD), the following attributes 
may be available (but may be only filled out if root tries to use them):

  * |st_birthtime| - time of file creation"

Suggesting that it's not "anti-POSIX" (unPOSIX?  aPOSIX?) to provide the 
information if it's available.

Anyway, I've found a more or less suitable workaround for now, batching 
up the queries and calling out to the shell - so I'll leave it at that.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: cygwin python os.stat gives wrong ctime
  2016-05-29 10:14 cygwin python os.stat gives wrong ctime Mitch Deoudes
  2016-05-29 10:58 ` Eliot Moss
@ 2016-05-30  9:38 ` Corinna Vinschen
  2016-05-31  9:17   ` Yaakov Selkowitz
  1 sibling, 1 reply; 6+ messages in thread
From: Corinna Vinschen @ 2016-05-30  9:38 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1886 bytes --]

On May 28 21:39, Mitch Deoudes wrote:
> According to the python docs, os.stat() gives the following for st_ctime:
> 
>     "|st_ctime| - platform dependent; time of most recent metadata change on
> Unix, or the time of creation on Windows"
> 
> To reproduce:
>     1) touch foo
>     2) wait a minute
>     3) touch foo
>     4) use python's os.stat() on the file foo
> 
> cygwin's python 2.7.10 gives (me) the same number for mtime, ctime, and
> atime:
> 
>     posix.stat_result(st_mode=33276, st_ino=40532396646393057,
> st_dev=1079873317, st_nlink=1, st_uid=1001, st_gid=513, st_size=0,
> st_atime=1464482278, st_mtime=1464482278, st_ctime=1464482278)
> 
> However, cygwin's built-in stat command gives (correctly) the addtional
> "birth time", which is different:
> 
>     Access: 2016-05-28 20:37:58.748977000 -0400
>     Modify: 2016-05-28 20:37:58.748977000 -0400
>     Change: 2016-05-28 20:37:58.748977000 -0400
>     Birth: 2016-05-28 20:36:34.514159100 -0400
> 
> The non-cygwin version of Windows python from python.org (v2.7.11) behaves
> correctly as per spec:
> 
>     nt.stat_result(st_mode=33206, st_ino=0L, st_dev=0L, st_nlink=0,
> st_uid=0, st_gid=0, st_size=0L, st_atime=1464482278L, st_mtime=1464482278L,
> st_ctime=1464482194L)
> 
> Am I missing something, or is this a bug in cygwin's python?  You could
> argue that ctime is properly "change" and not "birth", but that's not what
> the python spec says it should be on Windows.

Cygwin's ctime is Change time, not Birth time, that's why Cygwin's stat
structure comes with an additional st_birthtime as on the BSDs.

I have no idea if python has a compile time option to make st_birthtime
visible, though.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: cygwin python os.stat gives wrong ctime
  2016-05-30  8:09   ` Mitch Deoudes
@ 2016-05-30 17:00     ` Eliot Moss
  0 siblings, 0 replies; 6+ messages in thread
From: Eliot Moss @ 2016-05-30 17:00 UTC (permalink / raw)
  To: cygwin

On 5/29/2016 3:28 PM, Mitch Deoudes wrote:
>
>
> On 5/28/2016 10:35 PM, Eliot Moss wrote:
>> On 5/28/2016 9:39 PM, Mitch Deoudes wrote:
>>> According to the python docs, os.stat() gives the following for st_ctime:
>>>
>>>     "|st_ctime| - platform dependent; time of most recent metadata change on Unix, or the time of
>>> creation on Windows"
>>
>> cygwin emulates posix, so you should expect a posix-like result.
>
> I understand your argument, and offer the following, which is from the same section of the python docs:
>
>     "On other Unix systems (such as FreeBSD), the following attributes may be available (but may be
> only filled out if root tries to use them):
>
>  * |st_birthtime| - time of file creation"
>
> Suggesting that it's not "anti-POSIX" (unPOSIX?  aPOSIX?) to provide the information if it's available.
>
> Anyway, I've found a more or less suitable workaround for now, batching up the queries and calling
> out to the shell - so I'll leave it at that.

It appears, then, that the maintainer of cygwin's python could consider adjusting
for this information to be returned, since cygwin provides it and it would be useful
(at least sometimes).  The python spec does say "may" (not "shall" or "must"), so
it seems to me forgivable that it's not currently available.  I'd say it's up to
the maintainer to decide, and how to prioritize it.

Regards -- EM

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: cygwin python os.stat gives wrong ctime
  2016-05-30  9:38 ` Corinna Vinschen
@ 2016-05-31  9:17   ` Yaakov Selkowitz
  0 siblings, 0 replies; 6+ messages in thread
From: Yaakov Selkowitz @ 2016-05-31  9:17 UTC (permalink / raw)
  To: cygwin

On 2016-05-30 03:39, Corinna Vinschen wrote:
> On May 28 21:39, Mitch Deoudes wrote:
> Cygwin's ctime is Change time, not Birth time, that's why Cygwin's stat
> structure comes with an additional st_birthtime as on the BSDs.
>
> I have no idea if python has a compile time option to make st_birthtime
> visible, though.

It already is:

$ python
Python 2.7.10 (default, Jun  1 2015, 18:17:45)
[GCC 4.9.2] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> import os
 >>> st = os.stat('python.cygport')
 >>> print(st)
posix.stat_result(st_mode=33188, st_ino=281474978441936, 
st_dev=3300977488, st_nlink=1, st_uid=197608, st_gid=197121, 
st_size=3535, st_atime=1363164377, st_mtime=1464116088, st_ctime=1464116088)
 >>> print(st.st_birthtime)
1391923515.0

-- 
Yaakov

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-05-30 21:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-29 10:14 cygwin python os.stat gives wrong ctime Mitch Deoudes
2016-05-29 10:58 ` Eliot Moss
2016-05-30  8:09   ` Mitch Deoudes
2016-05-30 17:00     ` Eliot Moss
2016-05-30  9:38 ` Corinna Vinschen
2016-05-31  9:17   ` Yaakov Selkowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).