Skip to content

Commit

Permalink
avoid destroying error in try/finally of mktemp
Browse files Browse the repository at this point in the history
it's very common for this `rm` to fail on Windows
  • Loading branch information
vtjnash committed Jun 11, 2018
1 parent e7b5f9e commit 67c690f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,13 @@ function mktemp(fn::Function, parent=tempdir())
try
fn(tmp_path, tmp_io)
finally
close(tmp_io)
rm(tmp_path)
# TODO: should we call GC.gc() first on error, to make it much more likely that `rm` succeeds?
try
close(tmp_io)
rm(tmp_path)
catch ex
@error "mktemp cleanup" _group=:file exception=(ex, catch_backtrace())
end
end
end

Expand All @@ -563,7 +568,12 @@ function mktempdir(fn::Function, parent=tempdir())
try
fn(tmpdir)
finally
rm(tmpdir, recursive=true)
# TODO: should we call GC.gc() first on error, to make it much more likely that `rm` succeeds?
try
rm(tmpdir, recursive=true)
catch ex
@error "mktempdir cleanup" _group=:file exception=(ex, catch_backtrace())
end
end
end

Expand Down

0 comments on commit 67c690f

Please sign in to comment.