Skip to content

Commit 4b262c5

Browse files
giordanostaticfloat
authored andcommitted
[Prefix] Do not show warning if clashing files are the same
1 parent 5684f20 commit 4b262c5

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/Prefix.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,16 @@ function symlink_tree(src::AbstractString, dest::AbstractString)
213213
src_file = joinpath(root, f)
214214
dest_file = joinpath(dest, relpath(root, src), f)
215215
if isfile(dest_file)
216+
# Ugh, destination file already exists. If source and destination files
217+
# have the same size and SHA256 hash, just move on, otherwise issue a
218+
# warning.
219+
if filesize(src_file) == filesize(dest_file)
220+
src_file_hash = open(io -> bytes2hex(sha256(io)), src_file, "r")
221+
dest_file_hash = open(io -> bytes2hex(sha256(io)), dest_file, "r")
222+
if src_file_hash == dest_file_hash
223+
continue
224+
end
225+
end
216226
# Find source artifact that this pre-existent destination file belongs to
217227
dest_artifact_source = realpath(dest_file)
218228
while occursin("artifacts", dest_artifact_source) && basename(dirname(dest_artifact_source)) != "artifacts"

test/prefix.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,34 @@ end
159159
@test String(read(joinpath(dstdir, "sym_fileC"))) == "fileC\n"
160160
@test_throws Base.IOError realpath(joinpath(dstdir, "sym_fileB"))
161161
end
162+
163+
@testset "Warnings about clashing files" begin
164+
mktempdir() do tmpdir
165+
# Create fake source directory
166+
srcdir = joinpath(tmpdir, "src")
167+
mkdir(srcdir)
168+
# Write two files inside the source directory
169+
srcfile1 = joinpath(srcdir, "file1")
170+
text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n"
171+
write(srcfile1, text)
172+
srcfile2 = joinpath(srcdir, "file2")
173+
write(srcfile2, text ^ 2)
174+
175+
# Create the destination directory
176+
destdir = joinpath(tmpdir, "dest")
177+
mkdir(destdir)
178+
destfile1 = joinpath(destdir, "file1")
179+
# Same text as file1 in the source directory
180+
write(destfile1, text)
181+
destfile2 = joinpath(destdir, "file2")
182+
# Different text from file2 in the source directory
183+
write(destfile2, text)
184+
185+
# Set up a symlink tree inside of destdir: make sure only the warning about file2 is issued
186+
@test_logs (:warn, "Symlink file2 from artifact src already exists in artifact file2") BinaryBuilderBase.symlink_tree(srcdir, destdir)
187+
BinaryBuilderBase.unsymlink_tree(srcdir, destdir)
188+
end
189+
end
162190
end
163191

164192
@testset "Compression" begin

0 commit comments

Comments
 (0)