Stream: helpdesk (published)

Topic: ✔ Why `mktemp()` is not "cleaning" the file?


view this post on Zulip Davi Sales Barreira (Apr 09 2024 at 21:58):

I'm using mktemp() to create a file in Julia. Now, from what I understood, by setting the cleanup=true flag, the file would be deleted once I did close(io). In other words:

using Librsvg_jll
(path, io) = mktemp(cleanup=true)
write(io, img)
close(io)

io = open(path, "r")
content = read(io, String)
println(content)
close(io)

This should returns an error saying that the file doesn't exists. But it actually returns the content written in write(io, img). I'm using a Jupyter notebook to run this code... What am I missing here?

view this post on Zulip jar (Apr 09 2024 at 22:12):

Double check the mktemp docstring :-)

view this post on Zulip Davi Sales Barreira (Apr 09 2024 at 23:20):

mktemp(parent=tempdir(); cleanup=true) -> (path, io)
Return (path, io), where path is the path of a new temporary file in parent and io is an open file object for this path.

The cleanup option controls whether the temporary file is automatically deleted when the process exits.

I thought that close(io) would mean that the process is exiting. Am I wrong?

view this post on Zulip jar (Apr 09 2024 at 23:36):

No it means the julia process

view this post on Zulip Davi Sales Barreira (Apr 09 2024 at 23:37):

On this note, is there any "security" issue if I manually do rm(path)?

view this post on Zulip jar (Apr 09 2024 at 23:54):

I don't think so, but you can use a do block and the file will be removed automatically

mktemp() do path, io
  ...
end

view this post on Zulip Notification Bot (Apr 10 2024 at 19:51):

Davi Sales Barreira has marked this topic as resolved.


Last updated: Nov 22 2024 at 04:41 UTC