def check(f): # msec resolution, +- rounding error expected = int(os.stat(f).st_mtime * 1000) assert abs(int(rposix_stat.stat(f).st_mtime * 1000) - expected) < 2 assert abs( int(rposix_stat.stat(unicode(f)).st_mtime * 1000) - expected) < 2
def test_stat3_ino_dev(self): st = rposix_stat.stat('C:\\') assert st.st_dev == st.st_ino == 0 st = rposix_stat.stat3('C:\\') assert st.st_dev != 0 and st.st_ino != 0 st2 = rposix_stat.lstat3('C:\\') assert (st2.st_dev, st2.st_ino) == (st.st_dev, st.st_ino)
def get_stat_or_lstat(self, follow_symlinks): # 'follow_symlinks' ignored if not self.stat_cached: path = self.space.unicode0_w(self.fget_path(self.space)) self.d_stat = rposix_stat.stat(path) self.stat_cached = True return self.d_stat
def test_stat3_ino_dev(self): st = rposix_stat.stat('C:\\') assert st.st_dev == st.st_ino == 0 st = rposix_stat.stat3('C:\\') assert st.st_dev != 0 and st.st_ino != 0 assert st.st_file_attributes & 0x16 # FILE_ATTRIBUTE_DIRECTORY assert st.st_reparse_tag == 0 st2 = rposix_stat.lstat3('C:\\') assert (st2.st_dev, st2.st_ino) == (st.st_dev, st.st_ino)
def test_stat_large_number(self): fname = udir.join('test_stat_large_number.txt') fname.ensure() t1 = 5000000000.0 try: os.utime(str(fname), (t1, t1)) except OverflowError: py.test.skip("This platform doesn't support setting stat times " "to large values") assert rposix_stat.stat(str(fname)).st_mtime == t1
def test_stat_large_number(self): fname = udir.join('test_stat_large_number.txt') fname.ensure() t1 = 5000000000.0 try: os.utime(str(fname), (t1, t1)) except OverflowError: py.test.skip("This platform doesn't support setting stat times " "to large values") assert rposix_stat.stat(str(fname)).st_mtime == t1
def get_stat(self): """Get the stat() of the direntry. This is implemented in such a way that it won't do both a stat() and a lstat(). """ if (self.flags & FLAG_STAT) == 0: # We don't have the 'd_stat'. If the known_type says the # direntry is not a DT_LNK, then try to get and cache the # 'd_lstat' instead. Then, or if we already have a # 'd_lstat' from before, *and* if the 'd_lstat' is not a # S_ISLNK, we can reuse it unchanged for 'd_stat'. # # Note how, in the common case where the known_type says # it is a DT_REG or DT_DIR, then we call and cache lstat() # and that's it. Also note that in a d_type-less OS or on # a filesystem that always answer DT_UNKNOWN, this method # will instead only call at most stat(), but not cache it # as 'd_lstat'. known_type = self.flags & 255 if (known_type != rposix_scandir.DT_UNKNOWN and known_type != rposix_scandir.DT_LNK): self.get_lstat() # fill the 'd_lstat' cache have_lstat = True else: have_lstat = (self.flags & FLAG_LSTAT) != 0 if have_lstat: # We have the lstat() but not the stat(). They are # the same, unless the 'd_lstat' is a S_IFLNK. must_call_stat = stat.S_ISLNK(self.d_lstat.st_mode) else: must_call_stat = True if must_call_stat: # Must call stat(). Try to use fstatat() if possible dirfd = self.scandir_iterator.dirfd if dirfd != -1 and rposix.HAVE_FSTATAT: st = rposix_stat.fstatat(self.name, dirfd, follow_symlinks=True) else: path = self.space.fsencode_w(self.fget_path( self.space)) st = rposix_stat.stat(path) else: st = self.d_lstat self.d_stat = st self.flags |= FLAG_STAT return self.d_stat
def f(): return rposix_stat.stat(self.path).st_mtime
def f(): return rposix_stat.stat(self.path).st_mtime
def check(f): # msec resolution, +- rounding error expected = int(os.stat(f).st_mtime * 1000) assert abs(int(rposix_stat.stat(f).st_mtime * 1000) - expected) < 2 assert abs(int(rposix_stat.stat(unicode(f)).st_mtime * 1000) - expected) < 2