| 
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_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 | + | 
690 | 717 | function __postinit__()  | 
691 |  | -    Base.atexit(temp_cleanup_purge_all)  | 
 | 718 | +    Base.atexit(temp_cleanup_atexit)  | 
692 | 719 | end  | 
693 | 720 | 
 
  | 
694 | 721 | const temp_prefix = "jl_"  | 
 | 
0 commit comments