repo-add: use pushd/popd

Rather than explicit cd calls, we can use the directory stack to our
advantage. This also removes the need to store and restore $startdir, so
kill the variable entirely.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-01-11 15:15:07 -06:00
parent a9cbd15260
commit 7ce90bb135

View file

@ -32,7 +32,6 @@ DELTA=0
REPO_DB_FILE= REPO_DB_FILE=
LOCKFILE= LOCKFILE=
CLEAN_LOCK=0 CLEAN_LOCK=0
startdir="$PWD"
# ensure we have a sane umask set # ensure we have a sane umask set
umask 0022 umask 0022
@ -73,7 +72,7 @@ specified on the command line from the given repo database. Multiple\n\
packages to remove can be specified on the command line.\n\n")" packages to remove can be specified on the command line.\n\n")"
printf "$(gettext "\ printf "$(gettext "\
Use the -q/--quiet flag to minimize output to basic messages, warnings,\n\ Use the -q/--quiet flag to minimize output to basic messages, warnings,\n\
and errors\n\n")" and errors.\n\n")"
printf "$(gettext "\ printf "$(gettext "\
Use the -d/--delta flag to automatically generate and add a delta file\n\ Use the -d/--delta flag to automatically generate and add a delta file\n\
between the old entry and the new one, if the old package file is found\n\ between the old entry and the new one, if the old package file is found\n\
@ -228,8 +227,7 @@ db_write_entry()
return 1 return 1
fi fi
cd "$tmpdir" pushd "$tmpdir" >/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
@ -247,7 +245,7 @@ db_write_entry()
# create package directory # create package directory
mkdir "$pkgname-$pkgver" mkdir "$pkgname-$pkgver"
cd "$pkgname-$pkgver" pushd "$pkgname-$pkgver" >/dev/null
# restore an eventual deltas file # restore an eventual deltas file
[[ -f ../$pkgname.deltas ]] && mv "../$pkgname.deltas" deltas [[ -f ../$pkgname.deltas ]] && mv "../$pkgname.deltas" deltas
@ -289,7 +287,8 @@ db_write_entry()
write_list_entry "PROVIDES" "$_provides" "depends" write_list_entry "PROVIDES" "$_provides" "depends"
write_list_entry "OPTDEPENDS" "$_optdepends" "depends" write_list_entry "OPTDEPENDS" "$_optdepends" "depends"
cd "$startdir" popd >/dev/null
popd >/dev/null
# create a delta file # create a delta file
if [ -n "$oldfilename" -a -f "$oldfile" ]; then if [ -n "$oldfilename" -a -f "$oldfile" ]; then
@ -431,7 +430,6 @@ trap_exit()
clean_up() { clean_up() {
local exit_code=$? local exit_code=$?
cd "$startdir"
[[ -d $tmpdir ]] && rm -rf "$tmpdir" [[ -d $tmpdir ]] && rm -rf "$tmpdir"
(( CLEAN_LOCK )) && [[ -f $LOCKFILE ]] && rm -f "$LOCKFILE" (( CLEAN_LOCK )) && [[ -f $LOCKFILE ]] && rm -f "$LOCKFILE"
@ -503,7 +501,7 @@ if (( success )); then
filename=$(basename "$REPO_DB_FILE") filename=$(basename "$REPO_DB_FILE")
cd "$tmpdir" pushd "$tmpdir" >/dev/null
if [[ -n $(ls) ]]; then if [[ -n $(ls) ]]; then
bsdtar -c${TAR_OPT}f "$filename" * bsdtar -c${TAR_OPT}f "$filename" *
else else
@ -511,7 +509,7 @@ if (( success )); then
warning "$(gettext "No packages remain, creating empty database.")" warning "$(gettext "No packages remain, creating empty database.")"
bsdtar -c${TAR_OPT}f "$filename" -T /dev/null bsdtar -c${TAR_OPT}f "$filename" -T /dev/null
fi fi
cd "$startdir" popd >/dev/null
[[ -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 $tmpdir/$filename ]] && mv "$tmpdir/$filename" "$REPO_DB_FILE" [[ -f $tmpdir/$filename ]] && mv "$tmpdir/$filename" "$REPO_DB_FILE"