Skip to content

Commit

Permalink
More abspaths everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
staticfloat committed May 19, 2018
1 parent ab7786b commit 690f47b
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions base/sysinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -355,41 +355,42 @@ Windows platforms); no searching of `PATH` is performed.
function which(program_name::String)
# Build a list of program names that we're going to try
program_names = String[]
bpname = basename(program_name)
base_pname = basename(program_name)
if iswindows()
# If the file already has an extension, try that name first
if !isempty(splitext(bpname)[2])
push!(program_names, bpname)
if !isempty(splitext(base_pname)[2])
push!(program_names, base_pname)
end

# But also try appending .exe and .com`
for pe in (".exe", ".com")
push!(program_names, string(bpname, pe))
push!(program_names, string(base_pname, pe))
end
else
# On non-windows, we just always search for what we've been given
push!(program_names, bpname)
push!(program_names, base_pname)
end

path_dirs = String[]
program_dirname = dirname(program_name)
# If we've been given a path that has a directory name in it, then we
# check to see if that path exists. Otherwise, we search the PATH.
if isempty(program_dirname)
# If we have been given just a program name (not a relative or absolute
# path) then we should search `PATH` for it here:
pathsep = iswindows() ? ';' : ':'
path_dirs = split(get(ENV, "PATH", ""), pathsep)
path_dirs = abspath.(split(get(ENV, "PATH", ""), pathsep))

# On windows we always check the current directory as well
if iswindows()
pushfirst!(path_dirs, pwd())
end
else
# If we've been given a path that has a directory name in it, then we
# check to see if that path exists (with all the attendant `program_names`
# skullduggery windows requires). Otherwise, we search the PATH.
push!(path_dirs, program_dirname)
push!(path_dirs, abspath(program_dirname))
end

# Here we combine our directories with our program names, searching for the
# first match among all combinations.
for path_dir in path_dirs
for pname in program_names
program_path = joinpath(path_dir, pname)
Expand Down

0 comments on commit 690f47b

Please sign in to comment.