Skip to content

Commit 482e507

Browse files
Liozouvtjnash
andcommitted
More review comments
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
1 parent 253588b commit 482e507

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

base/file.jl

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,6 @@ end
327327
# Loaded DLLs cannot be deleted on Windows, even with posix delete mode but they can be renamed.
328328
# delayed_delete_dll(path) does so temporarily, until later cleanup by Pkg.gc().
329329
function delayed_delete_dll(path)
330-
drive = first(splitdrive(path))
331-
tmpdrive = first(splitdrive(tempdir()))
332330
# in-use DLL must be kept on the same drive
333331
temp_path = tempname(abspath(dirname(path)); cleanup=false, suffix=string("_", basename(path)))
334332
@debug "Could not delete DLL most likely because it is loaded, moving to a temporary path" path temp_path
@@ -687,8 +685,37 @@ end
687685
# deprecated internal function used by some packages
688686
temp_cleanup_purge(; force=false) = force ? temp_cleanup_purge_all() : @lock TEMP_CLEANUP_LOCK temp_cleanup_purge_prelocked(false)
689687

688+
function temp_cleanup_atexit(cleanup_dirs=keys(TEMP_CLEANUP))
689+
temp_cleanup_purge_all()
690+
if !isempty(cleanup_dirs)
691+
rmcmd = """
692+
eof(stdin)
693+
for path in eachline(stdin)
694+
try
695+
rm(path, force=true, recursive=true)
696+
catch ex
697+
@warn "Failed to clean up temporary path \$(repr(path))\n\$ex" _group=:file
698+
end
699+
end
700+
"""
701+
cmd = Cmd(`$(Base.julia_cmd()) --startup-file=no -e $rmcmd`; ignorestatus=true, detach=true)
702+
pw = Base.PipeEndpoint()
703+
rd, wr = Base.link_pipe(true, true)
704+
try
705+
Base.open_pipe!(pw, wr)
706+
catch
707+
Base.close_pipe_sync(wr)
708+
rethrow()
709+
end
710+
run(cmd, rd, devnull, stderr; wait=false)
711+
join(pw, cleanup_dirs, "\n")
712+
Base.dup(wr) # intentionally leak a reference, until the process exits
713+
close(pw)
714+
end
715+
end
716+
690717
function __postinit__()
691-
Base.atexit(temp_cleanup_purge_all)
718+
Base.atexit(temp_cleanup_atexit)
692719
end
693720

694721
const temp_prefix = "jl_"

test/tempdepot.jl

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,7 @@
99

1010
if Sys.iswindows() && !@isdefined(DEPOTS_TOREMOVE)
1111
const DEPOTS_TOREMOVE = String[]
12-
atexit() do # launch a process that will rm the depots
13-
rmcmd = """
14-
for _ in 1:3600 # wait up to 1h from atexit() until the julia testing process dies
15-
sleep(1)
16-
ccall(:uv_kill, Cint, (Cuint, Cint), $(getpid()), 0) == Base.UV_ESRCH && break
17-
end
18-
for path in $DEPOTS_TOREMOVE
19-
try
20-
rm(path, force=true, recursive=true)
21-
catch
22-
end
23-
end
24-
"""
25-
cmd = Cmd(`$(Base.julia_cmd()) --startup-file=no -e $rmcmd`; ignorestatus=true, detach=true)
26-
run(cmd; wait=false)
27-
end
12+
atexit(() -> Base.Filesystem.temp_cleanup_atexit(DEPOTS_TOREMOVE))
2813
end
2914

3015
function rmdepot(depot)

0 commit comments

Comments
 (0)