From d7ba620fd18384cca282b4fd241f73d5546ce16a Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Mon, 4 Nov 2024 19:24:19 -0800 Subject: [PATCH] Fix artifact directories not having traversal permissions It turns out that Windows requires the executable bit set if the `BYPASS_TRAVERSE_CHECKING` privilege is not attached to a user's account. It's simply more correct to ensure that our directories have this bit set, and unfortunately our `filemode()` function call is not complete on Windows and does not include this bit, so we manually add it in on Windows. --- src/Artifacts.jl | 9 ++++++++- test/artifacts.jl | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Artifacts.jl b/src/Artifacts.jl index 957d14aab9..25475ec44c 100644 --- a/src/Artifacts.jl +++ b/src/Artifacts.jl @@ -84,7 +84,14 @@ function _mv_temp_artifact_dir(temp_dir::String, new_path::String)::Nothing err = ccall(:jl_fs_rename, Int32, (Cstring, Cstring), temp_dir, new_path) if err ≥ 0 # rename worked - chmod(new_path, filemode(dirname(new_path))) + new_path_mode = filemode(dirname(new_path)) + if Sys.iswindows() + # If this is Windows, ensure the directory mode is executable, + # as `filemode()` is incomplete. Some day, that may not be the + # case, there exists a test that will fail if this is changes. + new_path_mode |= 0o001 + end + chmod(new_path, new_path_mode) set_readonly(new_path) return else diff --git a/test/artifacts.jl b/test/artifacts.jl index 605c3b26f8..fb9c6e1a66 100644 --- a/test/artifacts.jl +++ b/test/artifacts.jl @@ -823,4 +823,16 @@ end end end +if Sys.iswindows() + @testset "filemode(dir) non-executable on windows" begin + mktempdir() do dir + touch(joinpath(dir, "foo")) + @test !isempty(readdir(dir)) + # This technically should be true, the fact that it's not is + # a wrinkle of libuv, it would be nice to fix it and so if we + # do, this test will let us know. + @test filemode(dir) & 0o001 == 0 + end + end +end end # module