Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't use realpath in Sys.which #40233

Merged
merged 7 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/sysinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ function which(program_name::String)
program_path = joinpath(path_dir, pname)
# If we find something that matches our name and we can execute
if isfile(program_path) && isexecutable(program_path)
return realpath(program_path)
return program_path
end
end
end
Expand Down
20 changes: 11 additions & 9 deletions test/spawn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,8 @@ end
psep = if Sys.iswindows() ";" else ":" end
withenv("PATH" => "$(Sys.BINDIR)$(psep)$(ENV["PATH"])") do
julia_exe = joinpath(Sys.BINDIR, Base.julia_exename())
@test Sys.which("julia") == realpath(julia_exe)
@test Sys.which(julia_exe) == realpath(julia_exe)
@test Sys.which("julia") == abspath(julia_exe)
@test Sys.which(julia_exe) == abspath(julia_exe)
end

# Check that which behaves correctly when passed an empty string
Expand All @@ -598,8 +598,8 @@ mktempdir() do dir
touch(foo_path)
chmod(foo_path, 0o777)
if !Sys.iswindows()
@test Sys.which("foo") == realpath(foo_path)
@test Sys.which(foo_path) == realpath(foo_path)
@test Sys.which("foo") == abspath(foo_path)
@test Sys.which(foo_path) == abspath(foo_path)

chmod(foo_path, 0o666)
@test Sys.which("foo") === nothing
Expand Down Expand Up @@ -636,20 +636,20 @@ mktempdir() do dir
touch(foo2_path)
chmod(foo1_path, 0o777)
chmod(foo2_path, 0o777)
@test Sys.which("foo") == realpath(foo1_path)
@test Sys.which("foo") == abspath(foo1_path)

# chmod() doesn't change which() on Windows, so don't bother to test that
if !Sys.iswindows()
chmod(foo1_path, 0o666)
@test Sys.which("foo") == realpath(foo2_path)
@test Sys.which("foo") == abspath(foo2_path)
chmod(foo1_path, 0o777)
end

if Sys.iswindows()
# On windows, check that pwd() takes precedence, except when we provide a path
cd(joinpath(dir, "bin2")) do
@test Sys.which("foo") == realpath(foo2_path)
@test Sys.which(foo1_path) == realpath(foo1_path)
@test Sys.which("foo") == abspath(foo2_path)
@test Sys.which(foo1_path) == abspath(foo1_path)
end
end

Expand All @@ -662,7 +662,9 @@ mktempdir() do dir
touch(bar_path)
chmod(bar_path, 0o777)
cd(dir) do
@test Sys.which(joinpath("bin1", "bar")) == realpath(bar_path)
p = Sys.which(joinpath("bin1", "bar"))
@test p == abspath("bin1", basename(bar_path))
@test Base.samefile(p, bar_path)
end
end
end
Expand Down