Strange os.stat behavior

Philip Bloom pbloom at crystald.com
Wed Sep 29 22:38:29 EDT 2010


I'm on python 2.6.1:

 

Ran into some os.stat behavior that knocked me for a loop.  I was using
os.stat to retrieve file st_ctime and st_mtime from a remote server
through a unc path, and doing this I encountered that os.stat was
returning me st_ctime and st_mtime values  that were months off,
reporting values that not only were months in the past, but also
relatively wrong (Reporting a greater difference between Modified and
Created than there should be).  Below, run through localtime and
formatted a little for easier reading.).  C++ stat, Win32API, and
Windows own directory report all match with the same seen time (and are
correct).  Has anyone seen something like this before?   It's quite
scary to me that os.stat is returning a different value that it's
getting from somewhere and doesn't match with either the Windows API or
the C++ stat library.  I read over the release notes for 2.6.x and
didn't see any mention of os.stat relevant bugs or fixes.  I'm curious
what it could possibly be doing differently than the others (I thought
it used the windows api under the hood for Windows nt derived systems).

 

Ex:

\\mpkarc01\Build_stats\tras\MayaExportKernel_p.config\mabahazy~RWCWRK_70
01470.stats\9-27-2010_log.txt 1279755701.87 1285810489.65

Created:  time.struct_time(tm_year=2010, tm_mon=7, tm_mday=21,
tm_hour=16, tm_min=41, tm_sec=41, tm_wday=2, tm_yday=202, tm_isdst=1)

Modified:  time.struct_time(tm_year=2010, tm_mon=7, tm_mday=25,
tm_hour=0, tm_min=59, tm_sec=45, tm_wday=6, tm_yday=206, tm_isdst=1),
raw: 1280044785

Accessed:  time.struct_time(tm_year=2010, tm_mon=9, tm_mday=29,
tm_hour=17, tm_min=25, tm_sec=31, tm_wday=2, tm_yday=272, tm_isdst=1)

Raw Time.Time(): time.struct_time(tm_year=2010, tm_mon=9, tm_mday=29,
tm_hour=18, tm_min=34, tm_sec=49, tm_wday=2, tm_yday=272, tm_isdst=1),
raw: 1285810489.65

Win32API Ctime: 09/27/10 20:18:11 

Win32API MTime: 09/28/10 01:18:37

Win32API ATime: 09/29/10 00:24:46 

 

Relevant code segment:

import win32api

import win32con

import win32file

import time

import os

...

 
statinfo = os.stat(os.path.join(root, name))

                            print os.path.join(root, name) + " " +
str(statinfo.st_ctime) + " " + str(time.time())

                            print "Modified: ",
time.localtime(int(statinfo.st_mtime)),int(statinfo.st_mtime)

                            print "Created: ",
time.localtime(int(statinfo.st_ctime))

                            print "Accessed: ",
time.localtime(int(statinfo.st_atime))

                            print time.localtime(),time.time()

                            fh = win32file.CreateFile(os.path.join(root,
name), win32file.GENERIC_READ | win32file.GENERIC_WRITE, 0, None,
win32file.OPEN_EXISTING,0, 0)

                            sts, creationTime, accessTime, writeTime =
win32file.GetFileTime(fh)

                            print creationTime, accessTime, writeTime

                            win32file.CloseHandle(fh)

 

 

Platform of executing code: Windows XP, 64 bit.


______________________________________________________________________
This email has been scanned by the MessageLabs
______________________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100929/eade29cc/attachment.html>


More information about the Python-list mailing list