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

tempdir: error on non-directory result #33593

Merged
merged 3 commits into from
Feb 13, 2024
Merged
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
29 changes: 24 additions & 5 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,26 @@ function tempdir()
rc = ccall(:uv_os_tmpdir, Cint, (Ptr{UInt8}, Ptr{Csize_t}), buf, sz)
if rc == 0
resize!(buf, sz[])
return String(buf)
break
elseif rc == Base.UV_ENOBUFS
resize!(buf, sz[] - 1) # space for null-terminator implied by StringVector
else
uv_error("tempdir()", rc)
end
end
tempdir = String(buf)
try
s = stat(tempdir)
if !ispath(s)
@warn "tempdir path does not exist" tempdir
elseif !isdir(s)
@warn "tempdir path is not a directory" tempdir
end
catch ex
ex isa IOError || ex isa SystemError || rethrow()
@warn "accessing tempdir path failed" _exception=ex
end
return tempdir
end

"""
Expand All @@ -504,13 +517,19 @@ function prepare_for_deletion(path::AbstractString)
return
end

try chmod(path, filemode(path) | 0o333)
catch; end
try
chmod(path, filemode(path) | 0o333)
catch ex
ex isa IOError || ex isa SystemError || rethrow()
end
for (root, dirs, files) in walkdir(path; onerror=x->())
for dir in dirs
dpath = joinpath(root, dir)
try chmod(dpath, filemode(dpath) | 0o333)
catch; end
try
chmod(dpath, filemode(dpath) | 0o333)
catch ex
ex isa IOError || ex isa SystemError || rethrow()
end
end
end
end
Expand Down