From 46798e856bcfa70791e19e7729322ad2f425d157 Mon Sep 17 00:00:00 2001 From: Nicolas Reynolds Date: Tue, 1 Nov 2011 17:16:48 -0300 Subject: PKGBUILD path caching * Toru is overly complex * Moved path caching to toru-path. Run it without arguments to update the PKGBUILD paths cache * Updated fullpkg to check this new paths cache --- fullpkg | 20 +++++----------- toru | 42 ++++----------------------------- toru-path | 31 ++++++++++++++++++++++++ toru-utils | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+), 52 deletions(-) create mode 100755 toru-path create mode 100755 toru-utils diff --git a/fullpkg b/fullpkg index f242039..6b940f3 100755 --- a/fullpkg +++ b/fullpkg @@ -44,17 +44,8 @@ usage() { # Look in all caches but pick the first one # TODO move to a toru flag (-p?) where_is() { - local _repo - local _path - for _repo in ${REPOS[@]}; do - _path=$(grep "^${1}:" "${TORUPATH}/${_repo}.paths.cache" 2>/dev/null| \ - cut -d: -f2 2>/dev/null) - - [ -n "${_path}" ] && break - done - - echo ${_path} - + grep -m1 "^${1}:" "${TORUPATH}/paths" 2>/dev/null| \ + cut -d: -f2 2>/dev/null } # Removes a package from the buildorder @@ -147,6 +138,8 @@ find_deps() { for _dep in ${deps[@]}; do + msg2 "Checking ${_dep}" + local found=false local pkgdir=$(where_is ${_dep}) @@ -160,9 +153,8 @@ find_deps() { # probable circular deps [ $? -eq 20 ] && return 20 popd > /dev/null - fi - - if ! (( found )); then + else + error "Not found" echo "dep_not_found:$_dep" >>$build_dir/log fi diff --git a/toru b/toru index d622510..55e4119 100755 --- a/toru +++ b/toru @@ -12,43 +12,7 @@ # * Possibility to hook up ABS dirs besides ABSROOT (low priority) # * Tell updates and non available binary packages (working on this) -source /etc/abs.conf -source /etc/libretools.conf - -if [ ! -w "$TORUPATH" ]; then - error "Toru's path isn't writable. Please check $TORUPATH" - exit 1 -fi - -# TODO move to common functions -# usage : in_array( $needle, $haystack ) -function in_array { - [[ $2 ]] || return 1 # Not found - - local needle=$1; shift - local item - - for item in "$@"; do - [[ ${item#@} = $needle ]] && return 0 # Found - done - - return 1 # Not Found -} - -# Stores the lastsync date -lastsync() { - local lastsyncfile - - lastsyncfile=$1 - - [ -e ${lastsyncfile} -a ! -w ${lastsyncfile} ] && { - error "The sync date can't be saved. ${lastsyncfile} isn't writable." - return 1 - } - - date +%s > ${lastsyncfile} - touch ${lastsyncfile} -} +source $(dirname $0)/toru-utils # Saves contents on a named cache # $1 cache name (repo) @@ -267,7 +231,9 @@ update() { # See above FIXME # print_package_array "${updates[@]}" > ${TMPDIR}/updates - store_cache ${_repo}.updates ${TMPDIR}/updates + if [ -r ${TMPDIR}/updates ]; then + store_cache ${_repo}.updates ${TMPDIR}/updates + fi else $quiet || msg "Reading updates from cache..." diff --git a/toru-path b/toru-path new file mode 100755 index 0000000..82378a4 --- /dev/null +++ b/toru-path @@ -0,0 +1,31 @@ +#!/bin/bash + +source $(dirname $0)/toru-utils + +LASTSYNCFILE=${TORUPATH}/lastsync.paths + +# TODO pass other paths via flags +pkgbuilds=($(get_pkgbuilds ${ABSROOT})) +paths=() +# TODO create a --ignore flag +ignore=($@) + +msg "Updating path cache" +msg2 "${#pkgbuilds[@]} PKGBUILDs to update" +for _pkgbuild in ${pkgbuilds[@]}; do + $DEBUG && plain "$_pkgbuild" + source ${_pkgbuild} || { + error "${_pkgbuild} contains errors, skipping" + continue + } + + fullpath=$(dirname $(readlink -f ${_pkgbuild})) + + for _pkg in ${pkgname[@]}; do + paths+=(${_pkg}:${fullpath}) + done +done + +echo ${paths[@]} | tr ' ' "\n" | sort >> ${TORUPATH}/paths + +lastsync ${LASTSYNCFILE} diff --git a/toru-utils b/toru-utils new file mode 100755 index 0000000..e930273 --- /dev/null +++ b/toru-utils @@ -0,0 +1,80 @@ +#!/bin/bash +#!/bin/bash + + +source /etc/abs.conf +source /etc/libretools.conf + +if [ ! -w "$TORUPATH" ]; then + error "Toru's path isn't writable. Please check $TORUPATH" + exit 1 +fi + +LASTSYNCFILE=${TORUPATH}/lastsync +FORCE=false +QUIET=false +DEBUG=false + +# usage : in_array( $needle, $haystack ) +function in_array { + [[ $2 ]] || return 1 # Not found + + local needle=$1; shift + local item + + for item in "$@"; do + [[ ${item#@} = $needle ]] && return 0 # Found + done + + return 1 # Not Found +} + +# Stores the lastsync date +lastsync() { + local lastsyncfile + + lastsyncfile=$1 + + [ -e ${lastsyncfile} -a ! -w ${lastsyncfile} ] && { + error "The sync date can't be saved. ${lastsyncfile} isn't writable." + return 1 + } + + date +%s > ${lastsyncfile} + touch ${lastsyncfile} +} + + +# repo paths +get_pkgbuilds() { + pkgbuilds=() + + if [[ $FORCE = true || ! -e ${LASTSYNCFILE} ]]; then + + $QUIET || warning "Forcing upgrade" +# Get all PKGBUILDs + pkgbuilds=($(find $@ -mindepth 2 -maxdepth 3 -type f -name 'PKGBUILD')) + + else + +# Only find newer than lastsyncfile and read everything else from cache + pkgbuilds=($(find $@ -mindepth 2 -maxdepth 3 -type f -name 'PKGBUILD' -newer ${LASTSYNCFILE})) + + fi + +# Return all PKGBUILDs found + echo ${pkgbuilds[@]} +} + +# End inmediately but print a useful message +trap_exit() { + error "$@" + + exit 1 +} + +# Trap signals from makepkg +set -E +trap 'trap_exit "(prfullpkg:${level}) TERM signal caught. Exiting..."' TERM HUP QUIT +trap 'trap_exit "(prfullpkg:${level}) Aborted by user! Exiting..."' INT +trap 'trap_exit "(prfullpkg:${level}) An unknown error has occurred. Exiting..."' ERR -- cgit v1.1-4-g5e80