Skip to content

Commit

Permalink
tempname: change the default of cleanup from false to true
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski committed Aug 27, 2019
1 parent 8e29dc0 commit ff2fdb5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ function mktemp(parent::AbstractString=tempdir(); cleanup::Bool=true)
return (filename, Base.open(filename, "r+"))
end

function tempname(parent::AbstractString=tempdir(); cleanup::Bool=false)
function tempname(parent::AbstractString=tempdir(); cleanup::Bool=true)
seed::UInt32 = rand(UInt32)
while true
if (seed & typemax(UInt16)) == 0
Expand All @@ -518,7 +518,7 @@ end
else # !windows

# Obtain a temporary filename.
function tempname(parent::AbstractString=tempdir(); cleanup::Bool=false)
function tempname(parent::AbstractString=tempdir(); cleanup::Bool=true)
p = ccall(:tempnam, Cstring, (Cstring, Cstring), parent, temp_prefix)
systemerror(:tempnam, p == C_NULL)
s = unsafe_string(p)
Expand All @@ -541,7 +541,7 @@ end # os-test


"""
tempname(parent=tempdir(); cleanup=false) -> String
tempname(parent=tempdir(); cleanup=true) -> String
Generate a temporary file path. This function only returns a path; no file is
created. The path is likely to be unique, but this cannot be guaranteed due to
Expand Down
4 changes: 2 additions & 2 deletions test/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ child_eval(code::String) = eval(Meta.parse(readchomp(`$(Base.julia_cmd()) -E $co
t = child_eval("t = mktempdir(); touch(joinpath(t, \"file.txt\")); t")
@test !ispath(t)
# tempname without cleanup
t = child_eval("t = tempname(); touch(t); t")
t = child_eval("t = tempname(cleanup=false); touch(t); t")
@test isfile(t)
rm(t)
@test !ispath(t)
# tempname with cleanup
t = child_eval("t = tempname(cleanup=true); touch(t); t")
t = child_eval("t = tempname(); touch(t); t")
@test !ispath(t)
end

Expand Down

0 comments on commit ff2fdb5

Please sign in to comment.