Skip to content

Commit 75cb006

Browse files
tempname: change the default of cleanup from false to true
1 parent 625fab3 commit 75cb006

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ New library functions
2222

2323
* The `splitpath` function now accepts any `AbstractString` whereas previously it only accepted paths of type `String` ([#33012]).
2424
* The `tempname` function now takes an optional `parent::AbstractString` argument to give it a directory in which to attempt to produce a temporary path name ([#33090]).
25-
* The `tempname` function now takes a `cleanup::Bool` keyword argument defaulting to `false`; when set to `true` the process will try to ensure that any file or directory at the path returned by `tempname` is deleted upon process exit ([#33090]).
25+
* The `tempname` function now takes a `cleanup::Bool` keyword argument defaulting to `true`, which causes the process to try to ensure that any file or directory at the path returned by `tempname` is deleted upon process exit ([#33090]).
2626

2727

2828
Standard library changes

base/file.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ function mktemp(parent::AbstractString=tempdir(); cleanup::Bool=true)
500500
return (filename, Base.open(filename, "r+"))
501501
end
502502

503-
function tempname(parent::AbstractString=tempdir(); cleanup::Bool=false)
503+
function tempname(parent::AbstractString=tempdir(); cleanup::Bool=true)
504504
isdir(parent) || throw(ArgumentError("$(repr(parent)) is not a directory"))
505505
seed::UInt32 = rand(UInt32)
506506
while true
@@ -519,7 +519,7 @@ end
519519
else # !windows
520520

521521
# Obtain a temporary filename.
522-
function tempname(parent::AbstractString=tempdir(); cleanup::Bool=false)
522+
function tempname(parent::AbstractString=tempdir(); cleanup::Bool=true)
523523
isdir(parent) || throw(ArgumentError("$(repr(parent)) is not a directory"))
524524
p = ccall(:tempnam, Cstring, (Cstring, Cstring), parent, temp_prefix)
525525
systemerror(:tempnam, p == C_NULL)
@@ -543,7 +543,7 @@ end # os-test
543543

544544

545545
"""
546-
tempname(parent=tempdir(); cleanup=false) -> String
546+
tempname(parent=tempdir(); cleanup=true) -> String
547547
548548
Generate a temporary file path. This function only returns a path; no file is
549549
created. The path is likely to be unique, but this cannot be guaranteed due to

test/file.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ child_eval(code::String) = eval(Meta.parse(readchomp(`$(Base.julia_cmd()) -E $co
8080
t = child_eval("t = mktempdir(); touch(joinpath(t, \"file.txt\")); t")
8181
@test !ispath(t)
8282
# tempname without cleanup
83-
t = child_eval("t = tempname(); touch(t); t")
83+
t = child_eval("t = tempname(cleanup=false); touch(t); t")
8484
@test isfile(t)
8585
rm(t, force=true)
8686
@test !ispath(t)
8787
# tempname with cleanup
88-
t = child_eval("t = tempname(cleanup=true); touch(t); t")
88+
t = child_eval("t = tempname(); touch(t); t")
8989
@test !ispath(t)
9090
end
9191

0 commit comments

Comments
 (0)