1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-22 15:58:50 -05:00

makepkg: refactor absolute filename detection

Move the absolute filename detection to a new function to reduce code
duplication.

This patch also fixes the --allsource option that did not include remote
source files if they reside in $startdir instead of $SRCDEST.

Signed-off-by: Cedric Staniewski <cedric@gmx.ca>
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Cedric Staniewski 2010-06-03 17:32:50 +02:00 committed by Dan McGee
parent 3739fe9913
commit 5cddcc901b

View File

@ -179,6 +179,31 @@ trap 'trap_exit "$(gettext "An unknown error has occurred. Exiting...")"' ERR
# 1) "filename::http://path/to/file" # 1) "filename::http://path/to/file"
# 2) "http://path/to/file" # 2) "http://path/to/file"
# Return the absolute filename of a source entry
#
# This function accepts a source entry or the already extracted filename of a
# source entry as input
get_filepath() {
local file="$(get_filename "$1")"
if [[ -f "$startdir/$file" ]]; then
file="$startdir/$file"
elif [[ -f "$SRCDEST/$file" ]]; then
file="$SRCDEST/$file"
else
return 1
fi
echo "$file"
}
# Print 'source not found' error message and exit makepkg
missing_source_file() {
error "$(gettext "Unable to find source file %s.")" "$(get_filename "$1")"
plain "$(gettext "Aborting...")"
exit 1 # $E_MISSING_FILE
}
# extract the filename from a source entry # extract the filename from a source entry
get_filename() { get_filename() {
# if a filename is specified, use it # if a filename is specified, use it
@ -458,20 +483,16 @@ download_sources() {
local netfile local netfile
for netfile in "${source[@]}"; do for netfile in "${source[@]}"; do
local file=$(get_filename "$netfile") local file
local url=$(get_url "$netfile") if file=$(get_filepath "$netfile"); then
if [[ -f $startdir/$file ]]; then msg2 "$(gettext "Found %s")" "${file##*/}"
msg2 "$(gettext "Found %s in build dir")" "$file" ln -sf "$file" "$srcdir/"
rm -f "$srcdir/$file"
ln -s "$startdir/$file" "$srcdir/"
continue
elif [[ -f $SRCDEST/$file ]]; then
msg2 "$(gettext "Using cached copy of %s")" "$file"
rm -f "$srcdir/$file"
ln -s "$SRCDEST/$file" "$srcdir/"
continue continue
fi fi
file=$(get_filename "$netfile")
local url=$(get_url "$netfile")
# if we get here, check to make sure it was a URL, else fail # if we get here, check to make sure it was a URL, else fail
if [[ $file = $url ]]; then if [[ $file = $url ]]; then
error "$(gettext "%s was not found in the build directory and is not a URL.")" "$file" error "$(gettext "%s was not found in the build directory and is not a URL.")" "$file"
@ -553,18 +574,7 @@ generate_checksums() {
local netfile local netfile
for netfile in "${source[@]}"; do for netfile in "${source[@]}"; do
local file="$(get_filename "$netfile")" local file="$(get_filepath "$netfile")" || missing_source_file "$netfile"
if [[ ! -f $file ]] ; then
if [[ ! -f $SRCDEST/$file ]] ; then
error "$(gettext "Unable to find source file %s to generate checksum.")" "$file"
plain "$(gettext "Aborting...")"
exit 1
else
file="$SRCDEST/$file"
fi
fi
local sum="$(openssl dgst -${integ} "$file")" local sum="$(openssl dgst -${integ} "$file")"
sum=${sum##* } sum=${sum##* }
(( ct )) && echo -n "$indent" (( ct )) && echo -n "$indent"
@ -600,14 +610,10 @@ check_checksums() {
file="$(get_filename "$file")" file="$(get_filename "$file")"
echo -n " $file ... " >&2 echo -n " $file ... " >&2
if [[ ! -f $file ]] ; then if ! file="$(get_filepath "$file")"; then
if [[ ! -f $SRCDEST/$file ]] ; then echo "$(gettext "NOT FOUND")" >&2
echo "$(gettext "NOT FOUND")" >&2 errors=1
errors=1 found=0
found=0
else
file="$SRCDEST/$file"
fi
fi fi
if (( $found )) ; then if (( $found )) ; then
@ -652,15 +658,6 @@ extract_sources() {
continue continue
fi fi
if [[ ! -f $file ]] ; then
if [[ ! -f $SRCDEST/$file ]] ; then
error "$(gettext "Unable to find source file %s for extraction.")" "$file"
plain "$(gettext "Aborting...")"
exit 1
else
file="$SRCDEST/$file"
fi
fi
# fix flyspray #6246 # fix flyspray #6246
local file_type=$(file -bizL "$file") local file_type=$(file -bizL "$file")
@ -1095,15 +1092,15 @@ create_srcpackage() {
msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT" msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT"
ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}" ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}"
local netfile local file
for netfile in "${source[@]}"; do for file in "${source[@]}"; do
local file=$(get_filename "$netfile") if [[ -f $file ]]; then
if [[ -f $netfile ]]; then
msg2 "$(gettext "Adding %s...")" "$netfile"
ln -s "${startdir}/$netfile" "${srclinks}/${pkgbase}"
elif (( SOURCEONLY == 2 )) && [[ -f $SRCDEST/$file ]]; then
msg2 "$(gettext "Adding %s...")" "$file" msg2 "$(gettext "Adding %s...")" "$file"
ln -s "$SRCDEST/$file" "${srclinks}/${pkgbase}/" ln -s "$file" "$srclinks/$pkgbase"
elif (( SOURCEONLY == 2 )); then
local absfile=$(get_filepath "$file") || missing_source_file "$file"
msg2 "$(gettext "Adding %s...")" "${absfile##*/}"
ln -s "$absfile" "$srclinks/$pkgbase"
fi fi
done done