repo-add cleanup.

* change ln -s to ln -sf in the Makefile to prevent a failure when the link
already exists.
* make test_repo_db_file simpler and more natural, move the complexity out
of it.
* remove one $cmd = repo-remove check that wasn't needed

Signed-off-by: Xavier Chantry <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Xavier Chantry 2008-06-17 00:09:45 +02:00 committed by Dan McGee
parent b15fb504a1
commit 11695bd0d7
2 changed files with 15 additions and 15 deletions

View File

@ -58,6 +58,6 @@ pacman-optimize: $(srcdir)/pacman-optimize.sh.in
rankmirrors: $(srcdir)/rankmirrors.py.in rankmirrors: $(srcdir)/rankmirrors.py.in
repo-add: $(srcdir)/repo-add.sh.in repo-add: $(srcdir)/repo-add.sh.in
repo-remove: $(srcdir)/repo-add.sh.in repo-remove: $(srcdir)/repo-add.sh.in
ln -s repo-add repo-remove ln -sf repo-add repo-remove
# vim:set ts=2 sw=2 noet: # vim:set ts=2 sw=2 noet:

View File

@ -84,17 +84,12 @@ There is NO WARRANTY, to the extent permitted by law.\n")"
} }
# test if a file is a repository DB # test if a file is a repository DB
# arg1 - command name (repo-add, repo-remove)
test_repo_db_file () { test_repo_db_file () {
if [ -f "$REPO_DB_FILE" ]; then
if bsdtar -tf "$REPO_DB_FILE" | grep -q "/desc"; then if bsdtar -tf "$REPO_DB_FILE" | grep -q "/desc"; then
return 0 # YES return 0 # YES
fi else
elif [ "$1" == "repo-add" ]; then
return 0 # YES - No database file is also allowed if we are adding
fi
return 1 # NO return 1 # NO
fi
} }
# write a list entry # write a list entry
@ -344,12 +339,16 @@ for arg in "$@"; do
elif [ -z "$REPO_DB_FILE" ]; then elif [ -z "$REPO_DB_FILE" ]; then
# store absolute path to repo DB # store absolute path to repo DB
REPO_DB_FILE=$($realpath "$arg") REPO_DB_FILE=$($realpath "$arg")
if [ -f "$REPO_DB_FILE" ]; then
if ! test_repo_db_file $cmd; then if ! test_repo_db_file $cmd; then
error "$(gettext "Repository file '%s' is not a proper pacman database.")" "$REPO_DB_FILE" error "$(gettext "Repository file '%s' is not a proper pacman database.")" "$REPO_DB_FILE"
exit 1 exit 1
elif [ -f "$REPO_DB_FILE" ]; then fi
msg "$(gettext "Extracting database to a temporary location...")" msg "$(gettext "Extracting database to a temporary location...")"
bsdtar -xf "$REPO_DB_FILE" -C "$gstmpdir" bsdtar -xf "$REPO_DB_FILE" -C "$gstmpdir"
elif [ "$cmd" == "repo-remove" ]; then
error "$(gettext "Repository file '%s' was not found.")" "$REPO_DB_FILE"
exit 1
fi fi
else else
if [ "$cmd" == "repo-add" ]; then if [ "$cmd" == "repo-add" ]; then
@ -394,7 +393,8 @@ if [ $success -eq 1 ]; then
esac esac
bsdtar -c${TAR_OPT}f "$REPO_DB_FILE" * bsdtar -c${TAR_OPT}f "$REPO_DB_FILE" *
elif [ "$cmd" == "repo-remove" ]; then else
# we should only end up with an empty db after a remove of the last package in the database
error "$(gettext "All packages have been removed from the database. Deleting '%s'.")" "$REPO_DB_FILE" error "$(gettext "All packages have been removed from the database. Deleting '%s'.")" "$REPO_DB_FILE"
rm "$REPO_DB_FILE" rm "$REPO_DB_FILE"
fi fi