From 183939da54831b11f389d9863a0e5b41aaf1ddc5 Mon Sep 17 00:00:00 2001 From: Jeff Huffman Date: Sat, 21 Jan 2023 05:33:20 -0500 Subject: [PATCH] improve error when srcs is used with directories with the same post-hash name --- pkgs/stdenv/generic/setup.sh | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index b1b982ecdffc..cbf2a2ceb8de 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -992,13 +992,22 @@ stripHash() { unpackCmdHooks+=(_defaultUnpack) _defaultUnpack() { local fn="$1" + local destination if [ -d "$fn" ]; then + destination="$(stripHash "$fn")" + + if [ -e "$destination" ]; then + echo "Cannot copy $fn to $destination: destination already exists!" + echo "Did you specify two \"srcs\" with the same \"name\"?" + return 1 + fi + # We can't preserve hardlinks because they may have been # introduced by store optimization, which might break things # in the build. - cp -pr --reflink=auto -- "$fn" "$(stripHash "$fn")" + cp -pr --reflink=auto -- "$fn" "$destination" else