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

Raise an error when using include_dependency with non-existent file #52105

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,7 @@ function _include_dependency(mod::Module, _path::AbstractString; track_content=t
push!(_require_dependencies,
(mod, path, filesize(path), open(_crc32c, path, "r"), -1.0))
else
@assert ispath(path) "'$path': No such file or directory"
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good but assert is the wrong choice here. Just check and throw a meaningful error type

Copy link
Member

@stevengj stevengj Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@assert ispath(path) "'$path': No such file or directory"
(isfile(path) && uperm(path) & 0x04 == 0x04) ||
throw(ArgumentError("$(repr(path)) is not a readable file"))

(It has to be a readable file — not just a path, e.g. not a directory — for include_dependency, because Julia will compute a CRC hash of the contents IIRC. And repr is the right way to convert the path to a quoted string.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The perm check should be moved to the other branch, because incluce_dependencys are only tracked by mtime, or does that also require read permissions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mtime doesn't require read permissions, sorry. But I guess #51798 will affect this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#51798 is concerned with the other branch. If the file does not exist there, then the error is thrown through open().

push!(_require_dependencies,
(mod, path, UInt64(0), UInt32(0), mtime(path)))
end
Expand Down
Loading