Skip to content

Commit 67ed9cb

Browse files
download/unpack: some code cleanup (#2641)
* download/unpack: some code cleanup * move list_tarball_files into test/utils (only used for tests) * platform engines: minor tweaks
1 parent e476cd0 commit 67ed9cb

File tree

6 files changed

+20
-28
lines changed

6 files changed

+20
-28
lines changed

src/Operations.jl

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -498,15 +498,7 @@ function install_archive(
498498
url_success || continue
499499
dir = joinpath(tempdir(), randstring(12))
500500
push!(tmp_objects, dir) # for cleanup
501-
# Might fail to extract an archive (Pkg#190)
502-
try
503-
unpack(path, dir; verbose=false)
504-
catch e
505-
e isa InterruptException && rethrow()
506-
@warn "failed to extract archive downloaded from $(url)"
507-
url_success = false
508-
end
509-
url_success || continue
501+
unpack(path, dir; verbose=false)
510502
if top
511503
unpacked = dir
512504
else

src/PlatformEngines.jl

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import ...Pkg: Pkg, TOML, pkg_server, depots1, can_fancyprint, stderr_f
99
using ..MiniProgressBars
1010
using Base.BinaryPlatforms, p7zip_jll
1111

12-
export probe_platform_engines!, verify, unpack, package, download_verify_unpack
12+
export verify, unpack, package, download_verify_unpack
1313

1414
const EXE7Z_LOCK = ReentrantLock()
1515
const EXE7Z = Ref{String}()
@@ -40,14 +40,13 @@ function find7z()
4040
error("7z binary not found")
4141
end
4242

43-
function probe_platform_engines!(;verbose::Bool = false)
44-
# don't do anything
45-
end
46-
4743
is_secure_url(url::AbstractString) =
4844
occursin(r"^(https://|\w+://(127\.0\.0\.1|localhost)(:\d+)?($|/))"i, url)
4945

50-
function get_server_dir(url::AbstractString, server=pkg_server())
46+
function get_server_dir(
47+
url :: AbstractString,
48+
server :: Union{AbstractString, Nothing} = pkg_server(),
49+
)
5150
server === nothing && return
5251
url == server || startswith(url, "$server/") || return
5352
m = match(r"^\w+://([^\\/]+)(?:$|/)", server)
@@ -374,14 +373,6 @@ function unpack(
374373
Tar.extract(`$(exe7z()) x $tarball_path -so`, dest, copy_symlinks = copy_symlinks())
375374
end
376375

377-
function list_tarball_files(tarball_path::AbstractString)
378-
names = String[]
379-
Tar.list(`$(exe7z()) x $tarball_path -so`) do hdr
380-
push!(names, hdr.path)
381-
end
382-
return names
383-
end
384-
385376
"""
386377
package(src_dir::AbstractString, tarball_path::AbstractString)
387378

src/Types.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ using TOML
1414
import ..Pkg, ..Registry
1515
import ..Pkg: GitTools, depots, depots1, logdir, set_readonly, safe_realpath, pkg_server, stdlib_dir, stdlib_path, isurl, stderr_f
1616
import Base.BinaryPlatforms: Platform
17-
import ..PlatformEngines: download, download_verify_unpack
1817
using ..Pkg.Versions
1918

2019
import Base: SHA1

test/artifacts.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ end
301301
hash = create_artifact(p -> touch(joinpath(p, "foo")))
302302
tarball_path = joinpath(art_dir, "foo.tar.gz")
303303
archive_artifact(hash, tarball_path)
304-
@test "foo" in PlatformEngines.list_tarball_files(tarball_path)
304+
@test "foo" in list_tarball_files(tarball_path)
305305

306306
# Test archiving something that doesn't exist fails
307307
remove_artifact(hash)

test/platformengines.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module PlatformEngineTests
22
import ..Pkg # ensure we are using the correct Pkg
33

44
using Test, Pkg.PlatformEngines, Pkg.BinaryPlatforms, SHA
5-
5+
using ..Utils: list_tarball_files
66

77
@testset "Packaging" begin
88
# Gotta set this guy up beforehand
@@ -36,7 +36,7 @@ using Test, Pkg.PlatformEngines, Pkg.BinaryPlatforms, SHA
3636
@test isfile(tarball_path)
3737

3838
# Test that we can inspect the contents of the tarball
39-
contents = PlatformEngines.list_tarball_files(tarball_path)
39+
contents = list_tarball_files(tarball_path)
4040
@test "bin/bar.sh" in contents
4141
@test "lib/baz.so" in contents
4242
@test "etc/qux.conf" in contents

test/utils.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
module Utils
44

55
import ..Pkg
6+
using Tar
67
using TOML
78
using UUIDs
89

910
export temp_pkg_dir, cd_tempdir, isinstalled, write_build, with_current_env,
1011
with_temp_env, with_pkg_env, git_init_and_commit, copy_test_package,
11-
git_init_package, add_this_pkg, TEST_SIG, TEST_PKG, isolate, LOADED_DEPOT
12+
git_init_package, add_this_pkg, TEST_SIG, TEST_PKG, isolate, LOADED_DEPOT,
13+
list_tarball_files
1214

1315
const LOADED_DEPOT = joinpath(@__DIR__, "loaded_depot")
1416

@@ -279,4 +281,12 @@ function add_this_pkg(; platform=Base.BinaryPlatforms.HostPlatform())
279281
Pkg.develop(spec; platform)
280282
end
281283

284+
function list_tarball_files(tarball_path::AbstractString)
285+
names = String[]
286+
Tar.list(`$(Pkg.PlatformEngines.exe7z()) x $tarball_path -so`) do hdr
287+
push!(names, hdr.path)
288+
end
289+
return names
290+
end
291+
282292
end

0 commit comments

Comments
 (0)