Skip to content

Commit

Permalink
Update Sys.isexecutable() to use new jl_fs_access() API call
Browse files Browse the repository at this point in the history
`jl_fs_access()` makes use of the `uv_fs_access()` call from LibUV,
which is newly-able to interrogate Win32 ACLs to determine whether a
file is truly executable or not on Windows.
  • Loading branch information
staticfloat committed Apr 28, 2020
1 parent 97232ab commit 21544e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
18 changes: 10 additions & 8 deletions base/sysinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -438,16 +438,18 @@ const WINDOWS_VISTA_VER = v"6.0"
Sys.isexecutable(path::String)
Return `true` if the given `path` has executable permissions.
!!! note
Prior to Julia 1.4, this did not correctly interrogate filesystem
ACLs on Windows, therefore it would return `true` for any extant
file. From Julia 1.4 on, it correctly determines whether the
file is marked as executable or not.
"""
function isexecutable(path::String)
if iswindows()
return isfile(path)
else
# We use `access()` and `X_OK` to determine if a given path is
# executable by the current user. `X_OK` comes from `unistd.h`.
X_OK = 0x01
ccall(:access, Cint, (Ptr{UInt8}, Cint), path, X_OK) == 0
end
# We use `access()` and `X_OK` to determine if a given path is
# executable by the current user. `X_OK` comes from `unistd.h`.
X_OK = 0x01
return ccall(:jl_fs_access, Cint, (Ptr{UInt8}, Cint), path, X_OK) == 0
end
isexecutable(path::AbstractString) = isexecutable(String(path))

Expand Down
8 changes: 8 additions & 0 deletions src/jl_uv.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,14 @@ JL_DLLEXPORT int jl_fs_chown(char *path, int uid, int gid)
return ret;
}

JL_DLLEXPORT int jl_fs_access(char *path, int mode)
{
uv_fs_t req;
int ret = uv_fs_access(unused_uv_loop_arg, &req, path, mode, NULL);
uv_fs_req_cleanup(&req);
return ret;
}

JL_DLLEXPORT int jl_fs_write(uv_os_fd_t handle, const char *data, size_t len,
int64_t offset) JL_NOTSAFEPOINT
{
Expand Down

0 comments on commit 21544e1

Please sign in to comment.