Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Prefix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@ function symlink_tree(src::AbstractString, dest::AbstractString)
src_file = joinpath(root, f)
dest_file = joinpath(dest, relpath(root, src), f)
if isfile(dest_file)
# Ugh, destination file already exists. If source and destination files
# have the same size and SHA256 hash, just move on, otherwise issue a
# warning.
if filesize(src_file) == filesize(dest_file)
src_file_hash = open(io -> bytes2hex(sha256(io)), src_file, "r")
dest_file_hash = open(io -> bytes2hex(sha256(io)), dest_file, "r")
if src_file_hash == dest_file_hash
continue
end
end
# Find source artifact that this pre-existent destination file belongs to
dest_artifact_source = realpath(dest_file)
while occursin("artifacts", dest_artifact_source) && basename(dirname(dest_artifact_source)) != "artifacts"
Expand Down
28 changes: 28 additions & 0 deletions test/prefix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,34 @@ end
@test String(read(joinpath(dstdir, "sym_fileC"))) == "fileC\n"
@test_throws Base.IOError realpath(joinpath(dstdir, "sym_fileB"))
end

@testset "Warnings about clashing files" begin
mktempdir() do tmpdir
# Create fake source directory
srcdir = joinpath(tmpdir, "src")
mkdir(srcdir)
# Write two files inside the source directory
srcfile1 = joinpath(srcdir, "file1")
text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n"
write(srcfile1, text)
srcfile2 = joinpath(srcdir, "file2")
write(srcfile2, text ^ 2)

# Create the destination directory
destdir = joinpath(tmpdir, "dest")
mkdir(destdir)
destfile1 = joinpath(destdir, "file1")
# Same text as file1 in the source directory
write(destfile1, text)
destfile2 = joinpath(destdir, "file2")
# Different text from file2 in the source directory
write(destfile2, text)

# Set up a symlink tree inside of destdir: make sure only the warning about file2 is issued
@test_logs (:warn, "Symlink file2 from artifact src already exists in artifact file2") BinaryBuilderBase.symlink_tree(srcdir, destdir)
BinaryBuilderBase.unsymlink_tree(srcdir, destdir)
end
end
end

@testset "Compression" begin
Expand Down