diff --git a/bin/mkpackage.pike b/bin/mkpackage.pike
index 004fd50cd86b0ee98102d593e8ebe91816e24a9a..d6bd7bb11b3d7ed1e9468037bf855092947df348 100644
--- a/bin/mkpackage.pike
+++ b/bin/mkpackage.pike
@@ -182,6 +182,9 @@ class Package
 		    // Figure out the contents.
 		    "CONTENTS=`tar tf \"$TARFILE\" | sed -ne '/^"+
 		    replace(basename(install_filename), ".", "\\.")+"/,$p'`\n"
+		    // The same file may appear multiple times
+		    // in a tar archive if it has been replaced.
+		    "CONTENTS=`echo $CONTENTS|sort|uniq`\n"
 		    // Check if we're going to use a special tar for e.g. --add.
 		    "[ x\"$TAR\" = x ] && TAR=tar\n"
 		    "[ x\"$CPIO\" = x ] && CPIO=cpio\n"