diff --git a/abuild.in b/abuild.in
index ff18c6bddbd73a7528e0f7845c2909d12f7ef9b6..11811bafa17df8ef436efa9c604f27e467e58bfa 100755
--- a/abuild.in
+++ b/abuild.in
@@ -155,7 +155,7 @@ sanitycheck() {
 }
 
 md5check() {
-	local dummy f
+	local dummy f endreturnval originalparams origin file
 	if [ -z "$source" ]; then
 		return 0
 	fi
@@ -167,7 +167,26 @@ md5check() {
 	fi
 	fetch || return 1
 	msg "Checking md5sums..."
-	cd "$srcdir" && echo "$md5sums" | md5sum -c 
+	IFS=$'\n'
+	endreturnval=0
+	originalparams=$@
+	set -- $source
+	for src in $md5sums; do
+		origin=$1; shift
+		echo "$src" | md5sum -c
+		if [ $? -ne 0 ]; then
+			is_remote $origin || continue
+			echo "Because the remote file above failed the md5sum check it will be deleted."
+			echo "Rebuilding will cause it to re-download which in some cases may fix the problem."
+			file=`echo "$src" | sed 's/.*[ \t\n]\(.*\)/\1/'`
+			echo "Deleting: $file"
+			rm $file
+			endreturnval=1
+		fi
+	done
+	unset IFS
+	set -- $originalparams
+	return $endreturnval
 }
 
 # verify upstream sources