summaryrefslogtreecommitdiffstats
path: root/Lib/shutil.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-01-23 08:45:33 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-01-23 08:45:33 (GMT)
commite9a63600b3a781f1ca744eaaa380fb4b05d43115 (patch)
tree30fe6e7781e58b8299239a842e4c566865e5494e /Lib/shutil.py
parent605a95ae4403223fd6f62bcd313ce2ca72a9dbdb (diff)
parent8bea200b98356c931aed6ae3ddfe2e1f5400ab71 (diff)
downloadcpython-e9a63600b3a781f1ca744eaaa380fb4b05d43115.zip
cpython-e9a63600b3a781f1ca744eaaa380fb4b05d43115.tar.gz
cpython-e9a63600b3a781f1ca744eaaa380fb4b05d43115.tar.bz2
Issue #16957: shutil.which() no longer searches a bare file name in the
current directory on Unix and no longer searches a relative file path with a directory part in PATH directories. Patch by Thomas Kluyver.
Diffstat (limited to 'Lib/shutil.py')
-rw-r--r--Lib/shutil.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/Lib/shutil.py b/Lib/shutil.py
index 31969ff..0cc74f6 100644
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -1076,10 +1076,13 @@ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
return (os.path.exists(fn) and os.access(fn, mode)
and not os.path.isdir(fn))
- # Short circuit. If we're given a full path which matches the mode
- # and it exists, we're done here.
- if _access_check(cmd, mode):
- return cmd
+ # If we're given a path with a directory part, look it up directly rather
+ # than referring to PATH directories. This includes checking relative to the
+ # current directory, e.g. ./script
+ if os.path.dirname(cmd):
+ if _access_check(cmd, mode):
+ return cmd
+ return None
path = (path or os.environ.get("PATH", os.defpath)).split(os.pathsep)