Skip to content

Commit 03e686a

Browse files
authored
Better cleanup of temporary files in install_archive. (#1409)
1 parent 482b630 commit 03e686a

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Operations.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,13 @@ function install_archive(
464464
hash::SHA1,
465465
version_path::String
466466
)::Bool
467+
tmp_objects = String[]
468+
url_success = false
467469
for url in urls
468470
archive_url = get_archive_url_for_version(url, hash)
469471
archive_url !== nothing || continue
470472
path = tempname() * randstring(6) * ".tar.gz"
473+
push!(tmp_objects, path) # for cleanup
471474
url_success = true
472475
try
473476
PlatformEngines.download(archive_url, path; verbose=false)
@@ -477,6 +480,7 @@ function install_archive(
477480
end
478481
url_success || continue
479482
dir = joinpath(tempdir(), randstring(12))
483+
push!(tmp_objects, dir) # for cleanup
480484
# Might fail to extract an archive (Pkg#190)
481485
try
482486
unpack(path, dir; verbose=false)
@@ -504,11 +508,11 @@ function install_archive(
504508
# Move content to version path
505509
!isdir(version_path) && mkpath(version_path)
506510
mv(unpacked, version_path; force=true)
507-
Base.rm(path; force = true)
508-
Base.rm(dir; force = true)
509-
return true
511+
break # successful install
510512
end
511-
return false
513+
# Clean up and exit
514+
foreach(x -> Base.rm(x; force=true, recursive=true), tmp_objects)
515+
return url_success
512516
end
513517

514518
const refspecs = ["+refs/*:refs/remotes/cache/*"]

0 commit comments

Comments
 (0)