diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2017-05-01 17:46:32 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2017-05-04 14:28:08 -0400 |
commit | 2ae5371f347603d34a7ccc33681e612db338d11e (patch) | |
tree | 2ecb5b05dcb1ffc2defb31c7f64d6720435f13e5 /src/toru/toru-path | |
parent | bb97cfc85d9b711b517985abbd9832bff9c4b37a (diff) |
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.
Diffstat (limited to 'src/toru/toru-path')
-rwxr-xr-x | src/toru/toru-path | 125 |
1 files changed, 65 insertions, 60 deletions
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 <http://www.gnu.org/licenses/>. . "$(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 "$@" |