[arch-projects] [dbscripts] [PATCH] db-functions: unify the repo-add/repo-remove caller
Use less duplicated logic, opening the way to more elegantly change the interface for the repo-add/repo-remove scripts which are themselves symlinked together and mostly have the same interface. Signed-off-by: Eli Schwartz <eschwartz@archlinux.org> --- db-functions | 34 ++++++++++++---------------------- db-move | 4 ++-- db-remove | 2 +- db-repo-add | 2 +- db-repo-remove | 2 +- db-update | 2 +- 6 files changed, 18 insertions(+), 28 deletions(-) diff --git a/db-functions b/db-functions index 8b71cae..653f130 100644 --- a/db-functions +++ b/db-functions @@ -442,34 +442,24 @@ set_repo_permission() { fi } -arch_repo_add() { - local repo=$1 - local arch=$2 - local pkgs=(${@:3}) - - # package files might be relative to repo dir - pushd "${FTP_BASE}/${repo}/os/${arch}" >/dev/null - /usr/bin/repo-add -q "${repo}${DBEXT}" ${pkgs[@]} \ - || error "repo-add ${repo}${DBEXT} ${pkgs[@]}" - popd >/dev/null - set_repo_permission "${repo}" "${arch}" - - REPO_MODIFIED=1 -} - -arch_repo_remove() { - local repo=$1 - local arch=$2 - local pkgs=(${@:3}) +arch_repo_modify() { + local action=$1 + local repo=$2 + local arch=$3 + local pkgs=("${@:4}") local dbfile="${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT}" - if [[ ! -f ${dbfile} ]]; then + if [[ ${action} = remove && ! -f ${dbfile} ]]; then error "No database found at '%s'" "$dbfile" return 1 fi - /usr/bin/repo-remove -q "${dbfile}" ${pkgs[@]} \ - || error "repo-remove ${dbfile} ${pkgs[@]}" + + # package files for repo-add might be relative to repo dir + pushd "${dbfile%/*}" >/dev/null + /usr/bin/repo-${action} -q "${dbfile}" ${pkgs[@]} \ + || error "repo-${action} ${dbfile} ${pkgs[@]}" set_repo_permission "${repo}" "${arch}" + popd >/dev/null REPO_MODIFIED=1 } diff --git a/db-move b/db-move index fb7ebac..e9c9fa7 100755 --- a/db-move +++ b/db-move @@ -114,8 +114,8 @@ done for tarch in ${ARCHES[@]}; do if [[ -n ${add_pkgs[${tarch}]} ]]; then - arch_repo_add "${repo_to}" "${tarch}" ${add_pkgs[${tarch}]} - arch_repo_remove "${repo_from}" "${tarch}" ${remove_pkgs[${tarch}]} + arch_repo_modify add "${repo_to}" "${tarch}" ${add_pkgs[${tarch}]} + arch_repo_modify remove "${repo_from}" "${tarch}" ${remove_pkgs[${tarch}]} fi done diff --git a/db-remove b/db-remove index 70502bc..08a95f9 100755 --- a/db-remove +++ b/db-remove @@ -47,6 +47,6 @@ for pkgbase in ${pkgbases[@]}; do done for tarch in ${tarches[@]}; do - arch_repo_remove "${repo}" "${tarch}" ${remove_pkgs[@]} + arch_repo_modify remove "${repo}" "${tarch}" ${remove_pkgs[@]} repo_unlock $repo $tarch done diff --git a/db-repo-add b/db-repo-add index d7be302..4b16f7e 100755 --- a/db-repo-add +++ b/db-repo-add @@ -36,6 +36,6 @@ for tarch in ${tarches[@]}; do msg "Adding %s to [%s]..." "$pkgfile" "$repo" fi done - arch_repo_add "${repo}" "${tarch}" ${pkgfiles[@]} + arch_repo_modify add "${repo}" "${tarch}" ${pkgfiles[@]} repo_unlock $repo $tarch done diff --git a/db-repo-remove b/db-repo-remove index 32d167e..3077786 100755 --- a/db-repo-remove +++ b/db-repo-remove @@ -32,6 +32,6 @@ for tarch in ${tarches[@]}; do for pkgname in ${pkgnames[@]}; do msg "Removing %s from [%s]..." "$pkgname" "$repo" done - arch_repo_remove "${repo}" "${tarch}" ${pkgnames[@]} + arch_repo_modify remove "${repo}" "${tarch}" ${pkgnames[@]} repo_unlock $repo $tarch done diff --git a/db-update b/db-update index 4e17184..e8ae08d 100755 --- a/db-update +++ b/db-update @@ -94,7 +94,7 @@ for repo in ${repos[@]}; do add_pkgs+=("${pkgfile}") done if (( ${#add_pkgs[@]} >= 1 )); then - arch_repo_add "${repo}" "${pkgarch}" ${add_pkgs[@]} + arch_repo_modify add "${repo}" "${pkgarch}" ${add_pkgs[@]} fi done done -- 2.16.2
On Mon, 26 Feb 2018 17:59:09 -0500, Eli Schwartz via arch-projects wrote:
Use less duplicated logic, opening the way to more elegantly change the interface for the repo-add/repo-remove scripts which are themselves symlinked together and mostly have the same interface.
Signed-off-by: Eli Schwartz <eschwartz@archlinux.org> --- db-functions | 34 ++++++++++++---------------------- db-move | 4 ++-- db-remove | 2 +- db-repo-add | 2 +- db-repo-remove | 2 +- db-update | 2 +- 6 files changed, 18 insertions(+), 28 deletions(-)
+1 from me. I'm not re-submitting my last patchset right now because it would conflict with this, and that's just pointless noise until someone's is applied. -- Happy hacking, ~ Luke Shumaker
participants (2)
-
Eli Schwartz
-
Luke Shumaker