Skip to content

Commit

Permalink
internal cleanup: excise is_file_readable.
Browse files Browse the repository at this point in the history
This was an awful, ancient function. This is exactly what the
isreadable(path) function does, so there's no need for this. Also,
in most of the places we were calling it, skipping over files that
exist but are not readable is unhelpful – it would be better to
fail and let the user know that a file that was in the lookup path
and *should* be readable isn't. Arguably, we should even weaken the
test to just `ispath` and fail if the thing exists but is not a
regular file and is, say, a directory unexpectedly.
  • Loading branch information
StefanKarpinski committed Oct 28, 2013
1 parent e5e0d23 commit 398682a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 26 deletions.
6 changes: 1 addition & 5 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,7 @@ function parse_input_line(io::IO)
end

# try to include() a file, ignoring if not found
function try_include(f::String)
if is_file_readable(f)
include(f)
end
end
try_include(path::String) = isfile(path) && include(path)

function process_options(args::Array{Any,1})
global ARGS, bind_addr
Expand Down
11 changes: 3 additions & 8 deletions base/loading.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# require

function is_file_readable(path::String)
s = stat(bytestring(path))
return isfile(s) && isreadable(s)
end

function find_in_path(name::String)
isabspath(name) && return name
isfile(name) && return abspath(name)
Expand All @@ -17,11 +12,11 @@ function find_in_path(name::String)
end
for prefix in [Pkg.dir(), LOAD_PATH]
path = joinpath(prefix, name)
is_file_readable(path) && return abspath(path)
isfile(path) && return abspath(path)
path = joinpath(prefix, base, "src", name)
is_file_readable(path) && return abspath(path)
isfile(path) && return abspath(path)
path = joinpath(prefix, name, "src", name)
is_file_readable(path) && return abspath(path)
isfile(path) && return abspath(path)
end
return nothing
end
Expand Down
2 changes: 1 addition & 1 deletion base/sysimg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ precompile(println, (TTY,))
precompile(print, (TTY,Char))
precompile(==, (Bool,Bool))
precompile(try_include, (ASCIIString,))
precompile(is_file_readable, (ASCIIString,))
precompile(isfile, (ASCIIString,))
precompile(include_from_node1, (ASCIIString,))
precompile(source_path, (Nothing,))
precompile(task_local_storage, ())
Expand Down
17 changes: 5 additions & 12 deletions base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,11 @@ end
# source files, editing

function find_source_file(file)
if file[1]!='/' && !is_file_readable(file)
file2 = find_in_path(file)
if file2 != nothing
return file2
else
file2 = "$JULIA_HOME/../share/julia/base/$file"
if is_file_readable(file2)
return file2
end
end
end
return file
(isabspath(file) || isfile(file)) && return file
file2 = find_in_path(file)
file2 != nothing && return file2
file2 = "$JULIA_HOME/../share/julia/base/$file"
isfile(file2) ? file2 : nothing
end

function edit(file::String, line::Integer)
Expand Down

0 comments on commit 398682a

Please sign in to comment.