repo-add : remove realpath usage

Rework slightly db_write_entry so that $pkgfile is no longer referenced
from the temporary dir. This means $pkgfile can be a relative path and does
not need to be converted with realpath anymore.

Signed-off-by: Xavier Chantry <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Xavier Chantry 2009-02-18 17:15:39 +01:00 committed by Dan McGee
parent c590ac0997
commit c8a41b7d6d

View file

@ -97,8 +97,8 @@ write_list_entry() {
# arg1 - path to delta # arg1 - path to delta
db_write_delta() db_write_delta()
{ {
# blank out all variables and set deltafile to absolute path # blank out all variables
local deltafile=$($realpath "$1") local deltafile="$1"
local filename=$(basename "$deltafile") local filename=$(basename "$deltafile")
local deltavars pkgname fromver tover arch csize md5sum local deltavars pkgname fromver tover arch csize md5sum
@ -128,12 +128,12 @@ db_write_delta()
# arg1 - path to package # arg1 - path to package
db_write_entry() db_write_entry()
{ {
# blank out all variables and set pkgfile to an absolute path # blank out all variables
local pkgfile=$($realpath "$1") local pkgfile="$1"
local pkgname pkgver pkgdesc url builddate packager csize size \ local pkgname pkgver pkgdesc url builddate packager csize size \
group depend backup license replaces provides conflict force \ group depend backup license replaces provides conflict force \
_groups _depends _backups _licenses _replaces _provides _conflicts \ _groups _depends _backups _licenses _replaces _provides _conflicts \
startdir optdepend _optdepends startdir optdepend _optdepends md5sum
local OLDIFS="$IFS" local OLDIFS="$IFS"
# IFS (field separator) is only the newline character # IFS (field separator) is only the newline character
@ -162,22 +162,22 @@ db_write_entry()
IFS=$OLDIFS IFS=$OLDIFS
# get compressed size of package # get md5sum and compressed size of package
md5sum="$(openssl dgst -md5 "$pkgfile" | awk '{print $NF}')"
csize=$(@SIZECMD@ "$pkgfile") csize=$(@SIZECMD@ "$pkgfile")
startdir=$(pwd)
pushd "$gstmpdir" 2>&1 >/dev/null
# ensure $pkgname and $pkgver variables were found # ensure $pkgname and $pkgver variables were found
if [ -z "$pkgname" -o -z "$pkgver" ]; then if [ -z "$pkgname" -o -z "$pkgver" ]; then
error "$(gettext "Invalid package file '%s'.")" "$pkgfile" error "$(gettext "Invalid package file '%s'.")" "$pkgfile"
popd 2>&1 >/dev/null
return 1 return 1
fi fi
# remove an existing entry if it exists, ignore failures # remove an existing entry if it exists, ignore failures
db_remove_entry "$pkgname" db_remove_entry "$pkgname"
startdir=$(pwd)
pushd "$gstmpdir" 2>&1 >/dev/null
# create package directory # create package directory
mkdir "$pkgname-$pkgver" mkdir "$pkgname-$pkgver"
cd "$pkgname-$pkgver" cd "$pkgname-$pkgver"
@ -194,7 +194,7 @@ db_write_entry()
# compute checksums # compute checksums
msg2 "$(gettext "Computing md5 checksums...")" msg2 "$(gettext "Computing md5 checksums...")"
echo -e "%MD5SUM%\n$(openssl dgst -md5 "$pkgfile" | awk '{print $NF}')\n" >>desc echo -e "%MD5SUM%\n$md5sum\n" >>desc
[ -n "$url" ] && echo -e "%URL%\n$url\n" >>desc [ -n "$url" ] && echo -e "%URL%\n$url\n" >>desc
write_list_entry "LICENSE" "$_licenses" "desc" write_list_entry "LICENSE" "$_licenses" "desc"
@ -212,6 +212,7 @@ db_write_entry()
write_list_entry "OPTDEPENDS" "$_optdepends" "depends" write_list_entry "OPTDEPENDS" "$_optdepends" "depends"
# create deltas entry if there are delta files # create deltas entry if there are delta files
# Xav : why should deltas be in $startdir?
for delta in $startdir/$pkgname-*-*_to_*-*-$arch.delta; do for delta in $startdir/$pkgname-*-*_to_*-*-$arch.delta; do
# This for loop also pulls in all files that start with the current package # This for loop also pulls in all files that start with the current package
# name and are followed by a -whatever. For instance, running this loop for # name and are followed by a -whatever. For instance, running this loop for
@ -237,11 +238,15 @@ db_write_entry()
# add the final newline # add the final newline
[ -f "deltas" ] && echo -e "" >>deltas [ -f "deltas" ] && echo -e "" >>deltas
# preserve the modification time
touch -r "$pkgfile" desc depends
[ -f "deltas" ] && touch -r "$pkgfile" deltas
popd 2>&1 >/dev/null popd 2>&1 >/dev/null
# preserve the modification time
# Xav : what for?
pkgdir="$gstmpdir/$pkgname-$pkgver"
touch -r "$pkgfile" "$pkgdir/desc" "$pkgdir/depends"
[ -f "$pkgdir/deltas" ] && touch -r "$pkgfile" "$pkgdir/deltas"
return 0
} # end db_write_entry } # end db_write_entry
# remove existing entries from the DB # remove existing entries from the DB
@ -288,16 +293,6 @@ if [ $# -lt 2 ]; then
exit 1 exit 1
fi fi
# check for and store the name of a realpath-like program
if [ $(type -t realpath) ]; then
realpath='realpath'
elif [ $(type -t readlink) ]; then
realpath='readlink -f'
else
error "$(gettext "Either realpath or readlink are required by repo-add.")"
exit 1 # $E_MISSING_PROGRAM
fi
# main routine # main routine
gstmpdir=$(mktemp -d /tmp/repo-tools.XXXXXXXXXX) || (\ gstmpdir=$(mktemp -d /tmp/repo-tools.XXXXXXXXXX) || (\
error "$(gettext "Cannot create temp directory for database building.")"; \ error "$(gettext "Cannot create temp directory for database building.")"; \