From 4da9bf112b07c94a7fd65a729ce62610ade8e5aa Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 15 Jan 2011 01:12:09 +0100 Subject: Move repo manipulation code into common functions repo-add and repo-remove is now indirectly called by arch_repo_add/remove. This simplifies future extensions like incremental file list creations. See FS#11302 --- db-functions | 28 ++++++++++++++++++++++++++++ db-move | 9 ++------- db-remove | 7 +------ db-repo-add | 3 +-- db-repo-remove | 7 +------ db-update | 6 +----- 6 files changed, 34 insertions(+), 26 deletions(-) diff --git a/db-functions b/db-functions index 8ac9e63..7d431fc 100644 --- a/db-functions +++ b/db-functions @@ -450,3 +450,31 @@ set_repo_permission() { error "You don't have permission to change ${dbfile}" 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[@]} >/dev/null \ + || error "repo-add ${repo}${DBEXT} ${pkgs[@]}" + popd >/dev/null + set_repo_permission "${repo}" "${arch}" +} + +arch_repo_remove() { + local repo=$1 + local arch=$2 + local pkgs=(${@:3}) + local dbfile="${FTP_BASE}/${repo}/os/${arch}/${repo}${DBEXT}" + + if [ ! -f "${dbfile}" ]; then + error "No database found at '${dbfile}'" + return 1 + fi + /usr/bin/repo-remove -q "${dbfile}" ${pkgs[@]} >/dev/null \ + || error "repo-remove ${dbfile} ${pkgs[@]}" + set_repo_permission "${repo}" "${arch}" +} diff --git a/db-move b/db-move index cdc261c..ae21781 100755 --- a/db-move +++ b/db-move @@ -106,13 +106,8 @@ done for tarch in ${ARCHES[@]}; do if [ -n "${add_pkgs[${tarch}]}" ]; then - /usr/bin/repo-add -q "${ftppath_to}/${tarch}/${repo_to}${DBEXT}" ${add_pkgs[${tarch}]} >/dev/null \ - || error "repo-add ${tarch}/${repo_to}${DBEXT} ${add_pkgs[${tarch}]}" - set_repo_permission "${repo_to}" "${tarch}" - - /usr/bin/repo-remove -q "${ftppath_from}/${tarch}/${repo_from}${DBEXT}" ${remove_pkgs[${tarch}]} >/dev/null \ - || error "repo-remove ${tarch}/${repo_from}${DBEXT} ${remove_pkgs[${tarch}]}" - set_repo_permission "${repo_from}" "${tarch}" + arch_repo_add "${repo_to}" "${tarch}" ${add_pkgs[${tarch}]} + arch_repo_remove "${repo_from}" "${tarch}" ${remove_pkgs[${tarch}]} fi done diff --git a/db-remove b/db-remove index b246ce3..cc65eb9 100755 --- a/db-remove +++ b/db-remove @@ -41,11 +41,6 @@ else fi for tarch in ${tarches[@]}; do - if [ ! -f "$ftppath/$tarch/$repo$DBEXT" ]; then - die "No database found at '$ftppath/$tarch', nothing more to do" - fi - - /usr/bin/repo-remove -q "$ftppath/$tarch/$repo$DBEXT" ${pkgnames[@]} >/dev/null - set_repo_permission "${repo}" "${tarch}" + arch_repo_remove "${repo}" "${tarch}" ${pkgnames[@]} repo_unlock $repo $tarch done diff --git a/db-repo-add b/db-repo-add index b6dd8b8..53cfc84 100755 --- a/db-repo-add +++ b/db-repo-add @@ -34,7 +34,6 @@ for tarch in ${tarches[@]}; do if [ ! -f "${pkgfile}" ]; then die "Package file ${pkgfile} not found" fi - /usr/bin/repo-add -q "$ftppath/$tarch/$repo$DBEXT" ${pkgfile} >/dev/null - set_repo_permission "${repo}" "${tarch}" + arch_repo_add "${repo}" "${tarch}" ${pkgfile} repo_unlock $repo $tarch done diff --git a/db-repo-remove b/db-repo-remove index 6fa0e05..b01910f 100755 --- a/db-repo-remove +++ b/db-repo-remove @@ -31,11 +31,6 @@ done msg "Removing $pkgname from [$repo]..." for tarch in ${tarches[@]}; do - if [ ! -f "$ftppath/$tarch/$repo$DBEXT" ]; then - die "No database found at '$ftppath/$tarch', nothing more to do" - fi - - /usr/bin/repo-remove -q "$ftppath/$tarch/$repo$DBEXT" ${pkgname} >/dev/null - set_repo_permission "${repo}" "${tarch}" + arch_repo_remove "${repo}" "${tarch}" ${pkgname} repo_unlock $repo $tarch done diff --git a/db-update b/db-update index 3a49f0a..5bdce5e 100755 --- a/db-update +++ b/db-update @@ -67,11 +67,7 @@ for repo in ${repos[@]}; do add_pkgs[${#add_pkgs[*]}]=${pkgfile} done if [ ${#add_pkgs[@]} -ge 1 ]; then - pushd "$FTP_BASE/$repo/os/${pkgarch}" >/dev/null - /usr/bin/repo-add -q "$repo$DBEXT" ${add_pkgs[@]} >/dev/null \ - || die "repo-add $repo$DBEXT ${add_pkgs[@]}" - popd >/dev/null - set_repo_permission "${repo}" "${pkgarch}" + arch_repo_add "${repo}" "${pkgarch}" ${add_pkgs[@]} fi done done -- cgit v1.2.3-2-g168b