From 2ae5371f347603d34a7ccc33681e612db338d11e Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 1 May 2017 17:46:32 -0400 Subject: Have everything use a main() function, where it isn't too tricky to convert "Ignore space change" is essential to making sense of this patch. --- src/toru/toru-info | 38 +++++++++------- src/toru/toru-path | 125 +++++++++++++++++++++++++++------------------------- src/toru/toru-where | 11 +++-- 3 files changed, 94 insertions(+), 80 deletions(-) (limited to 'src/toru') diff --git a/src/toru/toru-info b/src/toru/toru-info index 31015e4..69799f1 100755 --- a/src/toru/toru-info +++ b/src/toru/toru-info @@ -22,23 +22,27 @@ . "$(librelib messages)" . "$(librelib conf)" -for _pkg in "$@"; do - _pkgbuild="$(toru-where "$_pkg")" +main() { + for _pkg in "$@"; do + _pkgbuild="$(toru-where "$_pkg")" - if [ -f "$_pkgbuild/PKGBUILD" ]; then - if ! load_PKGBUILD "$_pkgbuild/PKGBUILD" 2>/dev/null; then - warning "Errors on %s" "$_pkg" - continue - fi + if [ -f "$_pkgbuild/PKGBUILD" ]; then + if ! load_PKGBUILD "$_pkgbuild/PKGBUILD" 2>/dev/null; then + warning "Errors on %s" "$_pkg" + continue + fi + + deps=("${depends[@]}" "${makedepends[@]}" "${checkdepends[@]}") + repo="$(basename -- "$(dirname -- "$_pkgbuild")")" - deps=("${depends[@]}" "${makedepends[@]}" "${checkdepends[@]}") - repo="$(basename -- "$(dirname -- "$_pkgbuild")")" + msg "%s/%s %s-%s" "$repo" "$_pkg" "$pkgver" "$pkgrel" + msg2 '%s' "$pkgdesc" + msg2 '%s' "$url" + msg2 'Depends: %s' "${deps[*]}" + else + warning "%s doesn't exist" "$_pkg" + fi + done +} - msg "%s/%s %s-%s" "$repo" "$_pkg" "$pkgver" "$pkgrel" - msg2 '%s' "$pkgdesc" - msg2 '%s' "$url" - msg2 'Depends: %s' "${deps[*]}" - else - warning "%s doesn't exist" "$_pkg" - fi -done +main "$@" diff --git a/src/toru/toru-path b/src/toru/toru-path index 56bea42..fac4e5a 100755 --- a/src/toru/toru-path +++ b/src/toru/toru-path @@ -21,71 +21,76 @@ # along with this program. If not, see . . "$(librelib messages)" -setup_traps +. "$(librelib conf)" -# TODO: better option parsing -TORUPATH=${T:-${TORUPATH}} -VERBOSE=${V:-false} -FORCE=${F:-false} +main() { + setup_traps -. "$(librelib conf)" -load_files libretools -check_vars libretools TORUPATH REPOS || exit 1 -load_files abs -check_vars abs ABSROOT || exit 1 - -if [ ! -w "$TORUPATH" ]; then - error "Toru's path isn't writable. Please check $TORUPATH" - exit 1 -fi - -lastsyncfile=${TORUPATH}/lastsync.paths -pathfile=${TORUPATH}/paths.tch - -if [ ! -e "${pathfile}" ]; then - tcamgr create "${pathfile}" -fi - -# TODO: ability to use flags to pass in other directories to fullrepos - -# This loops over ${REPOS[@]} backward. This is because early entries -# in REPOS have higher precidence, but the way this is implemented, -# the later entries have precedence, so we need to flip the order. -fullrepos=() -for (( i = ${#REPOS[@]}-1 ; i >= 0 ; i-- )); do - $VERBOSE && msg "Processing [%s]" "${REPOS[$i]}" - - if [ -d "${ABSROOT}/${REPOS[$i]}" ]; then - fullrepos+=("${ABSROOT}/${REPOS[$i]}") + # TODO: better option parsing + TORUPATH=${T:-${TORUPATH}} + VERBOSE=${V:-false} + FORCE=${F:-false} + + load_files libretools + check_vars libretools TORUPATH REPOS || exit 1 + load_files abs + check_vars abs ABSROOT || exit 1 + + if [ ! -w "$TORUPATH" ]; then + error "Toru's path isn't writable. Please check $TORUPATH" + exit 1 + fi + + lastsyncfile=${TORUPATH}/lastsync.paths + pathfile=${TORUPATH}/paths.tch + + if [ ! -e "${pathfile}" ]; then + tcamgr create "${pathfile}" fi -done - -# Find PKGBUILDs in ${fullrepos[@]} -find_args=("${fullrepos[@]}" -mindepth 2 -maxdepth 3 -type f -name PKGBUILD) -if ! $FORCE && [[ -e $lastsyncfile ]]; then - # if lastfilesync exists, only look at things that have - # changed since then (unless $FORCE is on) - find_args+=(-newer "${lastsyncfile}") -fi -IFS=$'\n' -pkgbuilds=($(find "${find_args[@]}")) - -# Add information from each of the PKGBUILDs to the toru cache. -msg "Updating path cache" -msg2 "%d PKGBUILDs to update" ${#pkgbuilds[@]} -for _pkgbuild in "${pkgbuilds[@]}"; do - # plain "$_pkgbuild" - if ! load_PKGBUILD "${_pkgbuild}" >/dev/null 2>&1; then - error "%q contains errors, skipping" "${_pkgbuild}" - continue + + # TODO: ability to use flags to pass in other directories to fullrepos + + # This loops over ${REPOS[@]} backward. This is because early entries + # in REPOS have higher precidence, but the way this is implemented, + # the later entries have precedence, so we need to flip the order. + fullrepos=() + for (( i = ${#REPOS[@]}-1 ; i >= 0 ; i-- )); do + $VERBOSE && msg "Processing [%s]" "${REPOS[$i]}" + + if [ -d "${ABSROOT}/${REPOS[$i]}" ]; then + fullrepos+=("${ABSROOT}/${REPOS[$i]}") + fi + done + + # Find PKGBUILDs in ${fullrepos[@]} + find_args=("${fullrepos[@]}" -mindepth 2 -maxdepth 3 -type f -name PKGBUILD) + if ! $FORCE && [[ -e $lastsyncfile ]]; then + # if lastfilesync exists, only look at things that have + # changed since then (unless $FORCE is on) + find_args+=(-newer "${lastsyncfile}") fi + IFS=$'\n' + pkgbuilds=($(find "${find_args[@]}")) + + # Add information from each of the PKGBUILDs to the toru cache. + msg "Updating path cache" + msg2 "%d PKGBUILDs to update" ${#pkgbuilds[@]} + for _pkgbuild in "${pkgbuilds[@]}"; do + # plain "$_pkgbuild" + if ! load_PKGBUILD "${_pkgbuild}" >/dev/null 2>&1; then + error "%q contains errors, skipping" "${_pkgbuild}" + continue + fi - fullpath="$(dirname -- "${_pkgbuild}")" + fullpath="$(dirname -- "${_pkgbuild}")" - for _pkg in "${pkgbase}" "${pkgname[@]}" "${provides[@]}"; do - $VERBOSE && msg2 '%s -> %s' "${_pkg}" "${fullpath}" - tcamgr put "${pathfile}" "${_pkg%%[<>=]*}" "${fullpath}" + for _pkg in "${pkgbase}" "${pkgname[@]}" "${provides[@]}"; do + $VERBOSE && msg2 '%s -> %s' "${_pkg}" "${fullpath}" + tcamgr put "${pathfile}" "${_pkg%%[<>=]*}" "${fullpath}" + done done -done -date +%s > "${lastsyncfile}" + date +%s > "${lastsyncfile}" +} + +main "$@" diff --git a/src/toru/toru-where b/src/toru/toru-where index 14a40eb..ba7fb0a 100755 --- a/src/toru/toru-where +++ b/src/toru/toru-where @@ -19,7 +19,12 @@ # along with this program. If not, see . . "$(librelib conf)" -load_files libretools -check_vars libretools TORUPATH || exit 1 -tcamgr get "${TORUPATH}/paths.tch" "$1" 2>/dev/null || echo "" +main() { + load_files libretools + check_vars libretools TORUPATH || exit 1 + + tcamgr get "${TORUPATH}/paths.tch" "$1" 2>/dev/null || echo "" +} + +main "$@" -- cgit v1.2.2