repo-add: move database creation into its own function
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
parent
f3fc9af2b7
commit
d2cb52de12
1 changed files with 22 additions and 20 deletions
|
@ -607,6 +607,27 @@ rotate_db() {
|
||||||
fi
|
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() {
|
trap_exit() {
|
||||||
# unhook all traps to avoid race conditions
|
# unhook all traps to avoid race conditions
|
||||||
trap '' EXIT TERM HUP QUIT INT ERR
|
trap '' EXIT TERM HUP QUIT INT ERR
|
||||||
|
@ -726,26 +747,7 @@ done
|
||||||
# if at least one operation was a success, re-zip database
|
# if at least one operation was a success, re-zip database
|
||||||
if (( success )); then
|
if (( success )); then
|
||||||
msg "$(gettext "Creating updated database file '%s'")" "$REPO_DB_FILE"
|
msg "$(gettext "Creating updated database file '%s'")" "$REPO_DB_FILE"
|
||||||
|
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"
|
|
||||||
|
|
||||||
rotate_db
|
rotate_db
|
||||||
else
|
else
|
||||||
msg "$(gettext "No packages modified, nothing to do.")"
|
msg "$(gettext "No packages modified, nothing to do.")"
|
||||||
|
|
Loading…
Add table
Reference in a new issue