call site 8 for path.local.lstat
path/local/testing/test_local.py - line 253
248
249
250
251
252
253
254
255
256
257
258
259
260
261
   def test_make_numbered_dir(self):
       root = self.tmpdir
       root.ensure('base.not_an_int', dir=1)
       for i in range(10):
           numdir = local.make_numbered_dir(prefix='base.', rootdir=root,
->                                          keep=2, lock_timeout=0)
           assert numdir.check()
           assert numdir.basename == 'base.%d' %i
           if i>=1:
               assert numdir.new(ext=str(i-1)).check()
           if i>=2:
               assert numdir.new(ext=str(i-2)).check()
           if i>=3:
               assert not numdir.new(ext=str(i-3)).check()
path/local/local.py - line 654
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
   def make_numbered_dir(cls, prefix='session-', rootdir=None, keep=3,
                         lock_timeout = 172800):   # two days
       """ return unique directory with a number greater than the current
               maximum one.  The number is assumed to start directly after prefix.
               if keep is true directories with a number less than (maxnum-keep)
               will be removed.
           """
       if rootdir is None:
           rootdir = cls.get_temproot()
   
       def parse_num(path):
           """ parse the number out of a path (if it matches the prefix) """
           bn = path.basename
           if bn.startswith(prefix):
               try:
                   return int(bn[len(prefix):])
               except ValueError:
                   pass
   
       # compute the maximum number currently in use with the
       # prefix
       lastmax = None
       while True:
           maxnum = -1
           for path in rootdir.listdir():
               num = parse_num(path)
               if num is not None:
                   maxnum = max(maxnum, num)
   
           # make the new directory
           try:
               udir = rootdir.mkdir(prefix + str(maxnum+1))
           except py.error.EEXIST:
               # race condition: another thread/process created the dir
               # in the meantime.  Try counting again
               if lastmax == maxnum:
                   raise
               lastmax = maxnum
               continue
           break
   
       # put a .lock file in the new directory that will be removed at
       # process exit
       lockfile = udir.join('.lock')
       mypid = os.getpid()
       if hasattr(lockfile, 'mksymlinkto'):
           lockfile.mksymlinkto(str(mypid))
       else:
           lockfile.write(str(mypid))
       def try_remove_lockfile():
           # in a fork() situation, only the last process should
           # remove the .lock, otherwise the other processes run the
           # risk of seeing their temporary dir disappear.  For now
           # we remove the .lock in the parent only (i.e. we assume
           # that the children finish before the parent).
           if os.getpid() != mypid:
               return
           try:
               lockfile.remove()
           except py.error.Error:
               pass
       atexit.register(try_remove_lockfile)
   
       # prune old directories
       if keep:
           for path in rootdir.listdir():
               num = parse_num(path)
               if num is not None and num <= (maxnum - keep):
                   lf = path.join('.lock')
                   try:
                       t1 = lf.lstat().mtime
->                     t2 = lockfile.lstat().mtime
                       if abs(t2-t1) < lock_timeout:
                           continue   # skip directories still locked
                   except py.error.Error:
                       pass   # assume that it means that there is no 'lf'
                   try:
                       path.remove(rec=1)
                   except py.error.Error:
                       pass
           
       # make link...
       try:
           username = os.environ['USER']           #linux, et al
       except KeyError:
           try:
               username = os.environ['USERNAME']   #windows
           except KeyError:
               username = 'current'
   
       src  = str(udir)
       dest = src[:src.rfind('-')] + '-' + username
       try:
           os.unlink(dest)
       except OSError:
           pass
       try:
           os.symlink(src, dest)
       except (OSError, AttributeError): # AttributeError on win32
           pass
   
       return udir