|
327 | 327 | # Loaded DLLs cannot be deleted on Windows, even with posix delete mode but they can be renamed. |
328 | 328 | # delayed_delete_dll(path) does so temporarily, until later cleanup by Pkg.gc(). |
329 | 329 | function delayed_delete_dll(path) |
330 | | - drive = first(splitdrive(path)) |
331 | | - tmpdrive = first(splitdrive(tempdir())) |
332 | 330 | # in-use DLL must be kept on the same drive |
333 | 331 | temp_path = tempname(abspath(dirname(path)); cleanup=false, suffix=string("_", basename(path))) |
334 | 332 | @debug "Could not delete DLL most likely because it is loaded, moving to a temporary path" path temp_path |
|
687 | 685 | # deprecated internal function used by some packages |
688 | 686 | temp_cleanup_purge(; force=false) = force ? temp_cleanup_purge_all() : @lock TEMP_CLEANUP_LOCK temp_cleanup_purge_prelocked(false) |
689 | 687 |
|
| 688 | +function temp_cleanup_postprocess(cleanup_dirs) |
| 689 | + if !isempty(cleanup_dirs) |
| 690 | + rmcmd = """ |
| 691 | + eof(stdin) |
| 692 | + for path in eachline(stdin) |
| 693 | + try |
| 694 | + rm(path, force=true, recursive=true) |
| 695 | + catch ex |
| 696 | + @warn "Failed to clean up temporary path \$(repr(path))\n\$ex" _group=:file |
| 697 | + end |
| 698 | + end |
| 699 | + """ |
| 700 | + cmd = Cmd(`$(Base.julia_cmd()) --startup-file=no -e $rmcmd`; ignorestatus=true, detach=true) |
| 701 | + pw = Base.PipeEndpoint() |
| 702 | + rd, wr = Base.link_pipe(true, true) |
| 703 | + try |
| 704 | + Base.open_pipe!(pw, wr) |
| 705 | + catch |
| 706 | + Base.close_pipe_sync(wr) |
| 707 | + rethrow() |
| 708 | + end |
| 709 | + run(cmd, rd, devnull, stderr; wait=false) |
| 710 | + join(pw, cleanup_dirs, "\n") |
| 711 | + Base.dup(wr) # intentionally leak a reference, until the process exits |
| 712 | + close(pw) |
| 713 | + end |
| 714 | +end |
| 715 | + |
| 716 | +function temp_cleanup_atexit() |
| 717 | + temp_cleanup_purge_all() |
| 718 | + temp_cleanup_postprocess(keys(TEMP_CLEANUP)) |
| 719 | +end |
| 720 | + |
690 | 721 | function __postinit__() |
691 | | - Base.atexit(temp_cleanup_purge_all) |
| 722 | + Base.atexit(temp_cleanup_atexit) |
692 | 723 | end |
693 | 724 |
|
694 | 725 | const temp_prefix = "jl_" |
|
0 commit comments