diff --git a/buildrepo.in b/buildrepo.in
index 5b4133d94ddad1527e95bfaaa3f0638007b2fd99..2be50e1f7838201cc9b53f00c12d420382b34602 100755
--- a/buildrepo.in
+++ b/buildrepo.in
@@ -28,6 +28,14 @@ listpackages() {
 	done
 }
 
+all_exist() {
+	while [ $# -gt 0 ]; do
+		[ -e "$1" ] || return 1
+		shift 1
+	done
+	return 0
+}
+	
 build() {
 	local repo="$1" i indexupdate needbuild
 
@@ -47,15 +55,18 @@ build() {
 			continue
 		fi
 
+		indexupdate="$indexupdate $i"
+
 		# try link or copy the files if they are in the ports dir
 		pkgs=$(abuild listpkg)
-		if cp -p -l $pkgs "$repodir/$repo"/ 2>/dev/null \
-			|| cp -p $pkgs "$repodir/$repo"/ 2>/dev/null; then
+		if all_exist $pkgs; then
 			echo ">>> Copying " $pkgs
+			cp -p -l $pkgs "$repodir/$repo"/ 2>/dev/null \
+				|| cp -p $pkgs "$repodir/$repo"/ \
+				|| needbuild="$needbuild $i"
 		else
 			needbuild="$needbuild $i"
 		fi
-		indexupdate="$indexupdate $i"
 	done
 
 	# build the postponed packages if any