[Python-checkins] python/dist/src/Lib os.py,1.59,1.60

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Tue, 03 Sep 2002 09:36:19 -0700


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv18799

Modified Files:
	os.py 
Log Message:
Fix for SF bug 601077 by Zack Weinberg.

The new execvpe code would sometimes do the wrong thing when a
non-executable file existed earlier in the path and an executable file
of the same name existed later in the path.  This patch restores the
proper behavior (which is to execute the second file).  When only a
non-executable file exists, the correct error is still reported.


Index: os.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/os.py,v
retrieving revision 1.59
retrieving revision 1.60
diff -C2 -d -r1.59 -r1.60
*** os.py	5 Aug 2002 16:13:24 -0000	1.59
--- os.py	3 Sep 2002 16:36:17 -0000	1.60
***************
*** 310,314 ****
  
  def execvpe(file, args, env):
!     """execv(file, args, env)
  
      Execute the executable file (which is searched for along $PATH)
--- 310,314 ----
  
  def execvpe(file, args, env):
!     """execvpe(file, args, env)
  
      Execute the executable file (which is searched for along $PATH)
***************
*** 340,351 ****
          envpath = defpath
      PATH = envpath.split(pathsep)
      for dir in PATH:
          fullname = path.join(dir, file)
          try:
              apply(func, (fullname,) + argrest)
!         except error, (errno, msg):
!             if errno != ENOENT and errno != ENOTDIR:
!                 raise
!     raise error, (errno, msg)
  
  # Change environ to automatically call putenv() if it exists
--- 340,358 ----
          envpath = defpath
      PATH = envpath.split(pathsep)
+     saved_exc = None
+     saved_tb = None
      for dir in PATH:
          fullname = path.join(dir, file)
          try:
              apply(func, (fullname,) + argrest)
!         except error, e:
!             tb = sys.exc_info()[2]
!             if (e.errno != ENOENT and e.errno != ENOTDIR
!                 and saved_exc is None):
!                 saved_exc = e
!                 saved_tb = tb
!     if saved_exc:
!         raise error, saved_exc, saved_tb
!     raise error, e, tb
  
  # Change environ to automatically call putenv() if it exists