Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2015-01-23 15:58:04 +1000
committerAllan McRae <allan@archlinux.org>2015-03-26 14:43:37 +1000
commitf3fc9af2b74d4d1da9718a703c4fbd5d5a13fd59 (patch)
treed3480fbd9cfd4d49eb8b0b2453fe267e59f3e8fa /scripts
parente7e0c137623253c6f1bad0c89e36586713eee526 (diff)
repo-add: move database rotation into its own function
Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/repo-add.sh.in67
1 files changed, 37 insertions, 30 deletions
diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index bf374443..f38482a2 100644
--- a/scripts/repo-add.sh.in
+++ b/scripts/repo-add.sh.in
@@ -571,6 +571,42 @@ remove() {
fi
}
+rotate_db() {
+ filename=${REPO_DB_FILE##*/}
+ tempname=$dirname/.tmp.$filename
+
+ # hardlink or move the previous version of the database and signature to .old
+ # extension as a backup measure
+ if [[ -f $REPO_DB_FILE ]]; then
+ ln -f "$REPO_DB_FILE" "$REPO_DB_FILE.old" 2>/dev/null || \
+ mv -f "$REPO_DB_FILE" "$REPO_DB_FILE.old"
+
+ if [[ -f $REPO_DB_FILE.sig ]]; then
+ ln -f "$REPO_DB_FILE.sig" "$REPO_DB_FILE.old.sig" 2>/dev/null || \
+ mv -f "$REPO_DB_FILE.sig" "$REPO_DB_FILE.old.sig"
+ else
+ rm -f "$REPO_DB_FILE.old.sig"
+ fi
+ fi
+
+ # rotate the newly-created database and signature into place
+ mv "$tempname" "$REPO_DB_FILE"
+ if [[ -f $tempname.sig ]]; then
+ mv "$tempname.sig" "$REPO_DB_FILE.sig"
+ fi
+
+ dblink=${REPO_DB_FILE%.tar*}
+ rm -f "$dblink" "$dblink.sig"
+ ln -s "$filename" "$dblink" 2>/dev/null || \
+ ln "$filename" "$dblink" 2>/dev/null || \
+ cp "$REPO_DB_FILE" "$dblink"
+ if [[ -f "$REPO_DB_FILE.sig" ]]; then
+ ln -s "$filename.sig" "$dblink.sig" 2>/dev/null || \
+ ln "$filename.sig" "$dblink.sig" 2>/dev/null || \
+ cp "$REPO_DB_FILE.sig" "$dblink.sig"
+ fi
+}
+
trap_exit() {
# unhook all traps to avoid race conditions
trap '' EXIT TERM HUP QUIT INT ERR
@@ -710,36 +746,7 @@ if (( success )); then
create_signature "$tempname"
- # hardlink or move the previous version of the database and signature to .old
- # extension as a backup measure
- if [[ -f $REPO_DB_FILE ]]; then
- ln -f "$REPO_DB_FILE" "$REPO_DB_FILE.old" 2>/dev/null || \
- mv -f "$REPO_DB_FILE" "$REPO_DB_FILE.old"
-
- if [[ -f $REPO_DB_FILE.sig ]]; then
- ln -f "$REPO_DB_FILE.sig" "$REPO_DB_FILE.old.sig" 2>/dev/null || \
- mv -f "$REPO_DB_FILE.sig" "$REPO_DB_FILE.old.sig"
- else
- rm -f "$REPO_DB_FILE.old.sig"
- fi
- fi
-
- # rotate the newly-created database and signature into place
- mv "$tempname" "$REPO_DB_FILE"
- if [[ -f $tempname.sig ]]; then
- mv "$tempname.sig" "$REPO_DB_FILE.sig"
- fi
-
- dblink=${REPO_DB_FILE%.tar*}
- rm -f "$dblink" "$dblink.sig"
- ln -s "$filename" "$dblink" 2>/dev/null || \
- ln "$filename" "$dblink" 2>/dev/null || \
- cp "$REPO_DB_FILE" "$dblink"
- if [[ -f "$REPO_DB_FILE.sig" ]]; then
- ln -s "$filename.sig" "$dblink.sig" 2>/dev/null || \
- ln "$filename.sig" "$dblink.sig" 2>/dev/null || \
- cp "$REPO_DB_FILE.sig" "$dblink.sig"
- fi
+ rotate_db
else
msg "$(gettext "No packages modified, nothing to do.")"
exit 1