@@ -490,12 +490,14 @@ dumpVars() {
490490}
491491
492492
493−# Utility function: return the base name of the given path, with the
493+# Utility function: echo the base name of the given path, with the
494494# prefix `HASH-' removed, if present.
495495stripHash() {
496− strippedName=$(basename $1);
496+ local strippedName="$(basename "$1")";
497497 if echo "$strippedName" | grep -q '^[a-z0-9]\{32\}-'; then
498498 echo "$strippedName" | cut -c34-
499+ else
500+ echo "$strippedName"
499501 fi
500502}
501503
@@ -506,12 +508,10 @@ _defaultUnpack() {
506508
507509 if [ -d "$fn" ]; then
508510
509− stripHash "$fn"
510−
511511 # We can't preserve hardlinks because they may have been
512512 # introduced by store optimization, which might break things
513513 # in the build.
514− cp -pr --reflink=auto "$fn" $strippedName
514+ cp -pr --reflink=auto "$fn" "$(stripHash "$fn")"
515515
516516 else
517517