diff --git a/src/Prefix.jl b/src/Prefix.jl index cc386b97..f327e05a 100644 --- a/src/Prefix.jl +++ b/src/Prefix.jl @@ -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" diff --git a/test/prefix.jl b/test/prefix.jl index bf99f951..9d23b233 100644 --- a/test/prefix.jl +++ b/test/prefix.jl @@ -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