Skip to content

Commit 5ebad46

Browse files
Crghilardigiordano
andauthored
modify check for existing files that properly splits name and extension (#1094)
* modify check for existing files that properly splits name and extension for files with multiple extension parts like .tar.gz * apply review suggestion Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com> * add a test for file extensions Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com>
1 parent a21822e commit 5ebad46

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/wizard/obtain_source.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,13 @@ function download_source(state::WizardState)
161161
source_path = joinpath(state.workspace, basename(url))
162162

163163
if isfile(source_path)
164-
name, ext = splitext(basename(source_path))
164+
# Try to match everything up to but not including ".tar.*" to strip multiple file extensions
165+
m = match(r"^.+(?=(\.tar\.([\s\S]+)))", basename(source_path))
166+
name, ext = if isnothing(m)
167+
splitext(basename(source_path))
168+
else
169+
m.match, m.captures[1]
170+
end
165171
n = 1
166172
while isfile(joinpath(state.workspace, "$(name)_$n$ext"))
167173
n += 1

test/wizard.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ end
206206
libfoo_tarball_hash,
207207
]
208208

209+
#test that two files downloaded with the same name are re-named appropriately
210+
m = match.(r"^.+(?=(\.tar\.([\s\S]+)))", basename.(getfield.(state.source_files,:path)))
211+
for cap in m
212+
@test cap.captures[1] BinaryBuilderBase.tar_extensions
213+
end
214+
209215
# Test download/install with a broken symlink that used to kill the wizard
210216
# https://github.com/JuliaPackaging/BinaryBuilder.jl/issues/183
211217
state = step2_state()

0 commit comments

Comments
 (0)