From dd8004ccbf58b546f48205d2878d9101bbfcaadc Mon Sep 17 00:00:00 2001 From: davidovski Date: Mon, 6 Jun 2022 18:39:20 +0100 Subject: fixed sort to be faster --- src/get.sh | 17 ++++++++++------- src/query.sh | 8 +++++++- src/sync.sh | 15 +++++++++------ src/validate.sh | 2 +- src/xi.sh | 7 +++++-- 5 files changed, 32 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/get.sh b/src/get.sh index 4296569..4a15bd7 100755 --- a/src/get.sh +++ b/src/get.sh @@ -8,7 +8,7 @@ list_deps() { [ -f $tree_file ] && for dep in $(cat "$tree_file"); do echo $dep - done | sort -u + done } # list all dependencies and sub dependencies of a package @@ -30,18 +30,21 @@ resolve_deps () { local package=$1 #only add if not already added - if ! echo ${deps} | grep -q "\b$package\b"; then + case " $deps " in + *" $package "*);; + *) deps="$deps $package" i=$((i+1)) - fi + ;; + esac for dep in $(list_deps $package); do # if not already checked - if echo $@ | grep -qv "\b$dep\b"; then - set -- $@ $dep - fi + case " $@ $deps " in + *" $dep "*) ;; + *) set -- $@ $dep;; + esac done - shift ${QUIET} || hbar -T "${CHECKMARK} resolving dependencies" $i $((i + $#)) diff --git a/src/query.sh b/src/query.sh index 5f863a6..f47ea60 100644 --- a/src/query.sh +++ b/src/query.sh @@ -35,16 +35,22 @@ files () { file_info () { for file in $@; do [ ! -f ${SYSROOT}$file ] && file=$(realpath $file 2>/dev/null) + local found=false for pkg in $(installed); do for list in ${INSTALLED_DIR}/$pkg/files; do [ -f $list ] && { - grep -q "^/usr${file}$" $list || grep -q "^${file}$" $list && { ${QUIET} && echo $pkg || printf "${LIGHT_BLUE}%s${BLUE} belongs to ${LIGHT_BLUE}%s${RESET}\n" $file $pkg + found=true } } done done + $found || { + printf "${RED}$file does not belong to any package!\n" > /dev/stderr + return 1 + } + done } diff --git a/src/sync.sh b/src/sync.sh index 263d555..2df7b64 100755 --- a/src/sync.sh +++ b/src/sync.sh @@ -90,29 +90,31 @@ popularity_contest () { } index_deps () { + local l=$1 set -- ${SOURCES} local total=$# local completed=0 for src in ${SOURCES}; do - ${QUIET} || hbar -T "${LARGE_CIRCLE} indexing dependencies..." $completed $total + ${QUIET} || hbar -l $l -T "${LARGE_CIRCLE} indexing dependencies..." $completed $total dep_graph $src completed=$((completed+1)) done - ${QUIET} || hbar ${HBAR_COMPLETE} -T "${CHECKMARK} indexed dependencies" $completed $total + ${QUIET} || hbar -l $l ${HBAR_COMPLETE} -T "${CHECKMARK} indexed dependencies" $completed $total } index_repo () { + local l=$1 set -- ${SOURCES} local total=$# local completed=0 for src in ${SOURCES}; do - ${QUIET} || hbar -T "${LARGE_CIRCLE} syncing sources..." $completed $total + ${QUIET} || hbar -l $l -T "${LARGE_CIRCLE} syncing sources..." $completed $total list_source $src completed=$((completed+1)) done - ${QUIET} || hbar ${HBAR_COMPLETE} -T "${CHECKMARK} synced sources" $completed $total + ${QUIET} || hbar -l $1 ${HBAR_COMPLETE} -T "${CHECKMARK} synced sources" $completed $total } sync () { @@ -129,9 +131,10 @@ sync () { mkdir -p ${PACKAGES_DIR} # index packages and dependencies - index_repo ${QUIET} || hbar - index_deps + ${QUIET} || hbar + index_repo 1 & + index_deps 0 & # wait for all jobs to complete wait diff --git a/src/validate.sh b/src/validate.sh index 6b64616..46f6629 100644 --- a/src/validate.sh +++ b/src/validate.sh @@ -70,7 +70,7 @@ validate_files () { ${VERBOSE} && printf "${GREEN}%s is present\n" $file else ret=$((ret+1)) - ${QUIET} || printf "${RED}%s is missing\n" $file + ${QUIET} && printf "%s\n" $file || printf "${RED}%s is missing\n" $file fi done ${QUIET} || printf "${RESET}" diff --git a/src/xi.sh b/src/xi.sh index 8dd848c..000eba5 100755 --- a/src/xi.sh +++ b/src/xi.sh @@ -148,7 +148,7 @@ else shift checkroot - [ "$#" = "0" ] && set -- $(list_installed) + [ "$#" = "0" ] && set -- $(installed) toinstall=${CACHE_DIR}/toinstall @@ -233,7 +233,10 @@ else shift [ -z "$*" ] && set -- $(ls ${INSTALLED_DIR}) while [ ! -z "$*" ]; do - validate_files $1 || printf "${LIGHT_RED}Failed to verify $1\n" + validate_files $1 || { + ${QUIET} && printf "%s\n" $1 || printf "${LIGHT_RED}Failed to verify $1\n" + + } shift done ;; -- cgit v1.2.1