diff options
author | Allan McRae <allan@archlinux.org> | 2015-03-15 15:56:20 +1000 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2015-03-26 14:43:37 +1000 |
commit | d2cb52de12d3b2f313d80156f474b1d731ad67cf (patch) | |
tree | 10a44f29fc2af5a4bec962f04bf2b519552373b6 /scripts | |
parent | f3fc9af2b74d4d1da9718a703c4fbd5d5a13fd59 (diff) | |
download | pacman-d2cb52de12d3b2f313d80156f474b1d731ad67cf.tar.xz |
repo-add: move database creation into its own function
Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/repo-add.sh.in | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in index f38482a2..2d9b2628 100644 --- a/scripts/repo-add.sh.in +++ b/scripts/repo-add.sh.in @@ -607,6 +607,27 @@ rotate_db() { fi } +create_db() { + TAR_OPT=$(verify_repo_extension "$REPO_DB_FILE") + # $LOCKFILE is already guaranteed to be absolute so this is safe + dirname=${LOCKFILE%/*} + filename=${REPO_DB_FILE##*/} + # this ensures we create it on the same filesystem, making moves atomic + tempname=$dirname/.tmp.$filename + + pushd "$tmpdir/tree" >/dev/null + if ( shopt -s nullglob; files=(*); (( ${#files[*]} )) ); then + bsdtar -c${TAR_OPT}f "$tempname" * + else + # we have no packages remaining? zip up some emptyness + warning "$(gettext "No packages remain, creating empty database.")" + bsdtar -c${TAR_OPT}f "$tempname" -T /dev/null + fi + popd >/dev/null + + create_signature "$tempname" +} + trap_exit() { # unhook all traps to avoid race conditions trap '' EXIT TERM HUP QUIT INT ERR @@ -726,26 +747,7 @@ done # if at least one operation was a success, re-zip database if (( success )); then msg "$(gettext "Creating updated database file '%s'")" "$REPO_DB_FILE" - - TAR_OPT=$(verify_repo_extension "$REPO_DB_FILE") - # $LOCKFILE is already guaranteed to be absolute so this is safe - dirname=${LOCKFILE%/*} - filename=${REPO_DB_FILE##*/} - # this ensures we create it on the same filesystem, making moves atomic - tempname=$dirname/.tmp.$filename - - pushd "$tmpdir/tree" >/dev/null - if ( shopt -s nullglob; files=(*); (( ${#files[*]} )) ); then - bsdtar -c${TAR_OPT}f "$tempname" * - else - # we have no packages remaining? zip up some emptyness - warning "$(gettext "No packages remain, creating empty database.")" - bsdtar -c${TAR_OPT}f "$tempname" -T /dev/null - fi - popd >/dev/null - - create_signature "$tempname" - + create_db rotate_db else msg "$(gettext "No packages modified, nothing to do.")" |