[arch-projects] [dbscripts] [PATCH 03/11] Use += instead of jumping through hoops.

Luke Shumaker lukeshu at sbcglobal.net
Sun May 17 23:44:11 UTC 2015


From: Luke Shumaker <LukeShu at sbcglobal.net>

The += operator was introduced in Bash 3.1, and was already used in some
places in dbscripts, but not everywhere.

For normal strings, this isn't a big deal, but appending to an array
without using += is nasty.
---
 cron-jobs/sourceballs | 6 +++---
 db-functions          | 2 +-
 db-move               | 2 +-
 db-remove             | 2 +-
 db-update             | 2 +-
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/cron-jobs/sourceballs b/cron-jobs/sourceballs
index 0c2f9f9..a1030e9 100755
--- a/cron-jobs/sourceballs
+++ b/cron-jobs/sourceballs
@@ -82,7 +82,7 @@ for repo in "${PKGREPOS[@]}"; do
 			arch_svn export -q "${SVNREPO}/${pkgbase}/repos/${repo}-${pkgarch}" \
 				"${WORKDIR}/pkgbuilds/${repo}-${pkgarch}/${pkgbase}" >/dev/null 2>&1
 			if [ $? -ge 1 ]; then
-				failedpkgs[${#failedpkgs[*]}]="${pkgbase}-${pkgver}${SRCEXT}"
+				failedpkgs+=("${pkgbase}-${pkgver}${SRCEXT}")
 				continue
 			fi
 
@@ -93,9 +93,9 @@ for repo in "${PKGREPOS[@]}"; do
 				mv_acl "${pkgbase}-${pkgver}${SRCEXT}" "${FTP_BASE}/${SRCPOOL}/${pkgbase}-${pkgver}${SRCEXT}"
 				# Avoid creating the same source package for every arch
 				echo "${pkgbase}-${pkgver}${SRCEXT}" >> "${WORKDIR}/available-src-pkgs"
-				newpkgs[${#newpkgs[*]}]="${pkgbase}-${pkgver}${SRCEXT}"
+				newpkgs+=("${pkgbase}-${pkgver}${SRCEXT}")
 			else
-				failedpkgs[${#failedpkgs[*]}]="${pkgbase}-${pkgver}${SRCEXT}"
+				failedpkgs+=("${pkgbase}-${pkgver}${SRCEXT}")
 				cat "${WORKDIR}/${pkgbase}.log" >> "${WORKDIR}/makepkg-fail.log"
 			fi
 			popd >/dev/null
diff --git a/db-functions b/db-functions
index 2953d41..8523cff 100644
--- a/db-functions
+++ b/db-functions
@@ -202,7 +202,7 @@ repo_lock () {
 			warning "Repo [%s] (%s) is already locked by %s." "${1}" "${2}" "$_owner"
 			msg2 "Retrying in %d seconds..." "$LOCK_DELAY"
 		else
-			LOCKS[${#LOCKS[*]}]="$1.$2"
+			LOCKS+=("$1.$2")
 			set_umask
 			return 0
 		fi
diff --git a/db-move b/db-move
index cd67953..b589bca 100755
--- a/db-move
+++ b/db-move
@@ -91,7 +91,7 @@ for pkgbase in "${args[@]:2}"; do
 				arch_svn mv -q -r HEAD "${svnrepo_from}/$file@" "${svnrepo_to}/"
 			done
 			arch_svn rm --force -q "${svnrepo_from}"
-			tag_list="$tag_list, $pkgarch"
+			tag_list+=", $pkgarch"
 
 			for pkgname in "${pkgnames[@]}"; do
 				for tarch in "${tarches[@]}"; do
diff --git a/db-remove b/db-remove
index 3bb67b0..59f2db0 100755
--- a/db-remove
+++ b/db-remove
@@ -42,7 +42,7 @@ for pkgbase in "${pkgbases[@]}"; do
 		warning "%s not found in %s" "$pkgbase" "$svnrepo"
 		warning "Removing only %s from the repo" "$pkgbase"
 		warning "If it was a split package you have to remove the others yourself!"
-		remove_pkgs[${#remove_pkgs[*]}]=$pkgbase
+		remove_pkgs+=("$pkgbase")
 	fi
 done
 
diff --git a/db-update b/db-update
index 33dc551..7f59ce7 100755
--- a/db-update
+++ b/db-update
@@ -84,7 +84,7 @@ for repo in "${repos[@]}"; do
 			if [ -f "$FTP_BASE/${PKGPOOL}/${pkgfile}.sig" ]; then
 				ln -s "../../../${PKGPOOL}/${pkgfile}.sig" "$FTP_BASE/$repo/os/${pkgarch}"
 			fi
-			add_pkgs[${#add_pkgs[*]}]=${pkgfile}
+			add_pkgs+=("${pkgfile}")
 		done
 		if [ ${#add_pkgs[@]} -ge 1 ]; then
 			arch_repo_add "${repo}" "${pkgarch}" "${add_pkgs[@]}"
-- 
2.4.1


More information about the arch-projects mailing list