FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 06-26-2012, 10:58 PM
Allan McRae
 
Default makepkg: reorder source handling functions

There is no actual code change here, but these related functions
were all over the place which makes this code difficult to adjust.

Signed-off-by: Allan McRae <allan@archlinux.org>
---
scripts/makepkg.sh.in | 240 +++++++++++++++++++++++++-------------------------
1 file changed, 120 insertions(+), 120 deletions(-)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 0d63352..4299816 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -208,13 +208,6 @@ get_filepath() {
printf "%s
" "$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
get_filename() {
# if a filename is specified, use it
@@ -229,6 +222,126 @@ get_url() {
printf "%s
" "${1#*::}"
}

+get_downloadclient() {
+ # $1 = URL with valid protocol prefix
+ local url=$1
+ local proto="${url%%://*}"
+
+ # loop through DOWNLOAD_AGENTS variable looking for protocol
+ local i
+ for i in "${DLAGENTS[@]}"; do
+ local handler="${i%%::*}"
+ if [[ $proto = "$handler" ]]; then
+ local agent="${i##*::}"
+ break
+ fi
+ done
+
+ # if we didn't find an agent, return an error
+ if [[ -z $agent ]]; then
+ error "$(gettext "There is no agent set up to handle %s URLs. Check %s.")" "$proto" "$MAKEPKG_CONF"
+ plain "$(gettext "Aborting...")"
+ exit 1 # $E_CONFIG_ERROR
+ fi
+
+ # ensure specified program is installed
+ local program="${agent%% *}"
+ if [[ ! -x $program ]]; then
+ local baseprog="${program##*/}"
+ error "$(gettext "The download program %s is not installed.")" "$baseprog"
+ plain "$(gettext "Aborting...")"
+ exit 1 # $E_MISSING_PROGRAM
+ fi
+
+ printf "%s
" "$agent"
+}
+
+download_file() {
+ # download command
+ local dlcmd=$1
+ # URL of the file
+ local url=$2
+ # destination file
+ local file=$3
+ # temporary download file, default to last component of the URL
+ local dlfile="${url##*/}"
+
+ # replace %o by the temporary dlfile if it exists
+ if [[ $dlcmd = *%o* ]]; then
+ dlcmd=${dlcmd//\%o/"$file.part"}
+ dlfile="$file.part"
+ fi
+ # add the URL, either in place of %u or at the end
+ if [[ $dlcmd = *%u* ]]; then
+ dlcmd=${dlcmd//\%u/"$url"}
+ else
+ dlcmd="$dlcmd "$url""
+ fi
+
+ local ret=0
+ eval "$dlcmd || ret=$?"
+ if (( ret )); then
+ [[ ! -s $dlfile ]] && rm -f -- "$dlfile"
+ return $ret
+ fi
+
+ # rename the temporary download file to the final destination
+ if [[ $dlfile != "$file" ]]; then
+ mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
+ fi
+}
+
+download_sources() {
+ msg "$(gettext "Retrieving Sources...")"
+
+ pushd "$SRCDEST" &>/dev/null
+
+ local netfile
+ for netfile in "${source[@]}"; do
+ local file=$(get_filepath "$netfile" || true)
+ if [[ -n "$file" ]]; then
+ msg2 "$(gettext "Found %s")" "${file##*/}"
+ rm -f "$srcdir/${file##*/}"
+ ln -s "$file" "$srcdir/"
+ continue
+ 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 [[ $file = "$url" ]]; then
+ error "$(gettext "%s was not found in the build directory and is not a URL.")" "$file"
+ exit 1 # $E_MISSING_FILE
+ fi
+
+ # find the client we should use for this URL
+ local dlclient
+ dlclient=$(get_downloadclient "$url") || exit $?
+
+ msg2 "$(gettext "Downloading %s...")" "$file"
+ # fix flyspray bug #3289
+ local ret=0
+ download_file "$dlclient" "$url" "$file" || ret=$?
+ if (( ret )); then
+ error "$(gettext "Failure while downloading %s")" "$file"
+ plain "$(gettext "Aborting...")"
+ exit 1
+ fi
+ rm -f "$srcdir/$file"
+ ln -s "$SRCDEST/$file" "$srcdir/"
+ done
+
+ popd &>/dev/null
+}
+
+# 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
+}
+
##
# usage : get_full_version( [$pkgname] )
# return : full version spec, including epoch (if necessary), pkgver, pkgrel
@@ -386,75 +499,6 @@ source_has_signatures() {
return 1
}

-get_downloadclient() {
- # $1 = URL with valid protocol prefix
- local url=$1
- local proto="${url%%://*}"
-
- # loop through DOWNLOAD_AGENTS variable looking for protocol
- local i
- for i in "${DLAGENTS[@]}"; do
- local handler="${i%%::*}"
- if [[ $proto = "$handler" ]]; then
- local agent="${i##*::}"
- break
- fi
- done
-
- # if we didn't find an agent, return an error
- if [[ -z $agent ]]; then
- error "$(gettext "There is no agent set up to handle %s URLs. Check %s.")" "$proto" "$MAKEPKG_CONF"
- plain "$(gettext "Aborting...")"
- exit 1 # $E_CONFIG_ERROR
- fi
-
- # ensure specified program is installed
- local program="${agent%% *}"
- if [[ ! -x $program ]]; then
- local baseprog="${program##*/}"
- error "$(gettext "The download program %s is not installed.")" "$baseprog"
- plain "$(gettext "Aborting...")"
- exit 1 # $E_MISSING_PROGRAM
- fi
-
- printf "%s
" "$agent"
-}
-
-download_file() {
- # download command
- local dlcmd=$1
- # URL of the file
- local url=$2
- # destination file
- local file=$3
- # temporary download file, default to last component of the URL
- local dlfile="${url##*/}"
-
- # replace %o by the temporary dlfile if it exists
- if [[ $dlcmd = *%o* ]]; then
- dlcmd=${dlcmd//\%o/"$file.part"}
- dlfile="$file.part"
- fi
- # add the URL, either in place of %u or at the end
- if [[ $dlcmd = *%u* ]]; then
- dlcmd=${dlcmd//\%u/"$url"}
- else
- dlcmd="$dlcmd "$url""
- fi
-
- local ret=0
- eval "$dlcmd || ret=$?"
- if (( ret )); then
- [[ ! -s $dlfile ]] && rm -f -- "$dlfile"
- return $ret
- fi
-
- # rename the temporary download file to the final destination
- if [[ $dlfile != "$file" ]]; then
- mv -f "$SRCDEST/$dlfile" "$SRCDEST/$file"
- fi
-}
-
run_pacman() {
local cmd
if [[ ! $1 = -@(T|Qq) ]]; then
@@ -571,50 +615,6 @@ remove_deps() {
fi
}

-download_sources() {
- msg "$(gettext "Retrieving Sources...")"
-
- pushd "$SRCDEST" &>/dev/null
-
- local netfile
- for netfile in "${source[@]}"; do
- local file=$(get_filepath "$netfile" || true)
- if [[ -n "$file" ]]; then
- msg2 "$(gettext "Found %s")" "${file##*/}"
- rm -f "$srcdir/${file##*/}"
- ln -s "$file" "$srcdir/"
- continue
- 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 [[ $file = "$url" ]]; then
- error "$(gettext "%s was not found in the build directory and is not a URL.")" "$file"
- exit 1 # $E_MISSING_FILE
- fi
-
- # find the client we should use for this URL
- local dlclient
- dlclient=$(get_downloadclient "$url") || exit $?
-
- msg2 "$(gettext "Downloading %s...")" "$file"
- # fix flyspray bug #3289
- local ret=0
- download_file "$dlclient" "$url" "$file" || ret=$?
- if (( ret )); then
- error "$(gettext "Failure while downloading %s")" "$file"
- plain "$(gettext "Aborting...")"
- exit 1
- fi
- rm -f "$srcdir/$file"
- ln -s "$SRCDEST/$file" "$srcdir/"
- done
-
- popd &>/dev/null
-}
-
get_integlist() {
local integ
local integlist=()
--
1.7.11.1
 

Thread Tools




All times are GMT. The time now is 09:41 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org