1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-23 00:08:50 -05:00

repo-add: fix db creation one last time

We fubar-ed this pretty good.

1. The whole old/new move shuffle was totally busted if you used a
relative path to your database, as we would just build the database in
place.
2. Our prior temp directory layout had the database files extracted
directly into it. When we tried to create a xxx.db.tar.gz file in this
same directory, due to the fact that we were no longer using a shell
wildcard, we tried to include the db in ourself, which is a big failure.
Fix all this by extracting to tree/ so we can have a clean top-level
temp directory.
3. Fix the inclusion of the './' directory entry; ensure the regex
prunes both leading paths of '.' as well as './'.

Where is that test suite again?

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-06-28 19:53:12 -05:00
parent c2e6a01a28
commit 84974ed04c

View File

@ -100,7 +100,7 @@ format_entry() {
find_pkgentry() { find_pkgentry() {
local pkgname=$1 local pkgname=$1
local pkgentry local pkgentry
for pkgentry in $tmpdir/$pkgname*; do for pkgentry in $tmpdir/tree/$pkgname*; do
name=${pkgentry##*/} name=${pkgentry##*/}
if [[ ${name%-*-*} = $pkgname ]]; then if [[ ${name%-*-*} = $pkgname ]]; then
echo $pkgentry echo $pkgentry
@ -285,7 +285,7 @@ db_write_entry() {
return 1 return 1
fi fi
pushd "$tmpdir" >/dev/null pushd "$tmpdir/tree" >/dev/null
if [[ -d $pkgname-$pkgver ]]; then if [[ -d $pkgname-$pkgver ]]; then
warning "$(gettext "An entry for '%s' already existed")" "$pkgname-$pkgver" warning "$(gettext "An entry for '%s' already existed")" "$pkgname-$pkgver"
else else
@ -350,7 +350,7 @@ db_write_entry() {
# create files file if wanted # create files file if wanted
if (( WITHFILES )); then if (( WITHFILES )); then
msg2 "$(gettext "Creating '%s' db entry...")" 'files' msg2 "$(gettext "Creating '%s' db entry...")" 'files'
local files_path="$tmpdir/$pkgname-$pkgver/files" local files_path="$tmpdir/tree/$pkgname-$pkgver/files"
echo "%FILES%" >$files_path echo "%FILES%" >$files_path
bsdtar --exclude='^.*' -tf "$pkgfile" >>$files_path bsdtar --exclude='^.*' -tf "$pkgfile" >>$files_path
fi fi
@ -381,7 +381,7 @@ db_remove_entry() {
while [[ -n $pkgentry ]]; do while [[ -n $pkgentry ]]; do
notfound=0 notfound=0
if [[ -f $pkgentry/deltas ]]; then if [[ -f $pkgentry/deltas ]]; then
mv "$pkgentry/deltas" "$tmpdir/$pkgname.deltas" mv "$pkgentry/deltas" "$tmpdir/tree/$pkgname.deltas"
fi fi
msg2 "$(gettext "Removing existing entry '%s'...")" \ msg2 "$(gettext "Removing existing entry '%s'...")" \
"${pkgentry##*/}" "${pkgentry##*/}"
@ -443,7 +443,7 @@ check_repo_db() {
fi fi
verify_signature "$REPO_DB_FILE" verify_signature "$REPO_DB_FILE"
msg "$(gettext "Extracting database to a temporary location...")" msg "$(gettext "Extracting database to a temporary location...")"
bsdtar -xf "$REPO_DB_FILE" -C "$tmpdir" bsdtar -xf "$REPO_DB_FILE" -C "$tmpdir/tree"
else else
case "$cmd" in case "$cmd" in
repo-remove) repo-remove)
@ -509,7 +509,7 @@ remove() {
msg "$(gettext "Searching for package '%s'...")" "$pkgname" msg "$(gettext "Searching for package '%s'...")" "$pkgname"
if db_remove_entry "$pkgname"; then if db_remove_entry "$pkgname"; then
rm -f "$tmpdir/$pkgname.deltas" rm -f "$tmpdir/tree/$pkgname.deltas"
return 0 return 0
else else
error "$(gettext "Package matching '%s' not found.")" "$pkgname" error "$(gettext "Package matching '%s' not found.")" "$pkgname"
@ -561,6 +561,7 @@ fi
tmpdir=$(mktemp -d /tmp/repo-tools.XXXXXXXXXX) || (\ tmpdir=$(mktemp -d /tmp/repo-tools.XXXXXXXXXX) || (\
error "$(gettext "Cannot create temp directory for database building.")"; \ error "$(gettext "Cannot create temp directory for database building.")"; \
exit 1) exit 1)
mkdir $tmpdir/tree
trap 'clean_up' EXIT trap 'clean_up' EXIT
trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT
@ -628,12 +629,13 @@ if (( success )); then
TAR_OPT=$(verify_repo_extension "$REPO_DB_FILE") TAR_OPT=$(verify_repo_extension "$REPO_DB_FILE")
filename=${REPO_DB_FILE##*/} filename=${REPO_DB_FILE##*/}
pushd "$tmpdir" >/dev/null pushd "$tmpdir/tree" >/dev/null
# strip the './' off filenames; this also allows us to tar an empty dir # strip the './' off filenames; this also allows us to tar an empty dir
bsdtar -s %^./%% -c${TAR_OPT}f "$REPO_DB_FILE" ./ bsdtar -s '%^./\?%%' -c${TAR_OPT}f "$tmpdir/$filename" ./
create_signature "$filename"
popd >/dev/null popd >/dev/null
create_signature "$tmpdir/$filename"
[[ -f $REPO_DB_FILE ]] && mv -f "$REPO_DB_FILE" "${REPO_DB_FILE}.old" [[ -f $REPO_DB_FILE ]] && mv -f "$REPO_DB_FILE" "${REPO_DB_FILE}.old"
[[ -f $REPO_DB_FILE.sig ]] && rm -f "$REPO_DB_FILE.sig" [[ -f $REPO_DB_FILE.sig ]] && rm -f "$REPO_DB_FILE.sig"
[[ -f $tmpdir/$filename ]] && mv "$tmpdir/$filename" "$REPO_DB_FILE" [[ -f $tmpdir/$filename ]] && mv "$tmpdir/$filename" "$REPO_DB_FILE"