Skip to content

Commit

Permalink
tempdir: error on non-directory result (#33593)
Browse files Browse the repository at this point in the history
Potential more graceful handling of
#33382. I thought about
creating the directory if it doesn't exist, but that seems aa bit
questionable. Probably better to let the user know about the situation
in a clear way so they can mitigate it. An even better improvement would
be if we could tell them which environment variable to look at. I tried
setting `TEMP` in the environment on macOS but it didn't seem to have
any effect on the result.

---------

Co-authored-by: Jameson Nash <[email protected]>
Co-authored-by: Dilum Aluthge <[email protected]>
  • Loading branch information
3 people authored Feb 13, 2024
1 parent 81c6526 commit 56e193e
Showing 1 changed file with 24 additions and 5 deletions.
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

0 comments on commit 56e193e

Please sign in to comment.