[pacman-dev] [PATCH 2/7] repo-add: move database creation into its own function
Allan McRae
allan at archlinux.org
Sun Mar 15 10:43:24 UTC 2015
Signed-off-by: Allan McRae <allan at archlinux.org>
---
scripts/repo-add.sh.in | 42 ++++++++++++++++++++++--------------------
1 file changed, 22 insertions(+), 20 deletions(-)
diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index f38482a..2d9b262 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.")"
--
2.3.3
More information about the pacman-dev
mailing list