From 0262970234c63e66d19692ef42f159b1f420f26e Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Tue, 24 Jul 2012 11:06:01 +0200 Subject: [PATCH 01/17] bee-remove: Only remove packages that have a CONTENT file Fixes #114 for bee-remove --- src/bee-remove.sh.in | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bee-remove.sh.in b/src/bee-remove.sh.in index 01084d0..bc1ea15 100644 --- a/src/bee-remove.sh.in +++ b/src/bee-remove.sh.in @@ -58,7 +58,11 @@ pkg_remove() { do_remove() { pkg=${1} - mv ${BEE_METADIR}/${pkg}/CONTENT{,.removed} + mv ${BEE_METADIR}/${pkg}/CONTENT{,.removed} 2>/dev/null + if [ "$?" != "0" ] ; then + return 1 + fi + mkdir -p ${BEECACHE_CACHEDIR} ${BEEFLOCK} ${BEECACHE_CACHEDIR}/INVENTORY \ ${BEE_LIBEXECDIR}/bee/bee-cache-update ${pkg} \ From 70e56ae41c4c979bebfc068a2159a6b68b52ae5f Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Tue, 24 Jul 2012 11:08:20 +0200 Subject: [PATCH 02/17] bee-remove: Change suffix of renamed CONTENT file --- src/bee-remove.sh.in | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bee-remove.sh.in b/src/bee-remove.sh.in index bc1ea15..d5b9ccf 100644 --- a/src/bee-remove.sh.in +++ b/src/bee-remove.sh.in @@ -58,7 +58,7 @@ pkg_remove() { do_remove() { pkg=${1} - mv ${BEE_METADIR}/${pkg}/CONTENT{,.removed} 2>/dev/null + mv ${BEE_METADIR}/${pkg}/CONTENT{,.bee-remove} 2>/dev/null if [ "$?" != "0" ] ; then return 1 fi @@ -75,7 +75,7 @@ do_remove() { fi [ "${NOOP}" != "yes" ] && \ - run_hooks pre-remove ${pkg} ${BEE_METADIR}/${pkg}/CONTENT.removed + run_hooks pre-remove ${pkg} ${BEE_METADIR}/${pkg}/CONTENT.bee-remove echo "removing package '${pkg}'" @@ -89,7 +89,7 @@ do_remove() { done [ "${NOOP}" != "yes" ] && \ - run_hooks post-remove ${pkg} ${BEE_METADIR}/${pkg}/CONTENT.removed + run_hooks post-remove ${pkg} ${BEE_METADIR}/${pkg}/CONTENT.bee-remove if [ -r "${BEE_METADIR}/${pkg}/META" ] ; then . "${BEE_METADIR}/${pkg}/META" @@ -108,7 +108,7 @@ do_remove() { fi # if dir does is not part of package -> skip it - content_file="${BEE_METADIR}/${pkg}/CONTENT.removed" + content_file="${BEE_METADIR}/${pkg}/CONTENT.bee-remove" if ! grep -q -l -E ":file=${dir}(/|$)" "${content_file}" ; then continue fi From 876c60fc2007e47b056e118304c9fb4637589860 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Tue, 24 Jul 2012 11:22:52 +0200 Subject: [PATCH 03/17] bee-cache-update: Use CONTENT.bee-remove to create .bcr file --- src/bee-cache-update.sh.in | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/bee-cache-update.sh.in b/src/bee-cache-update.sh.in index 46718ec..da733db 100644 --- a/src/bee-cache-update.sh.in +++ b/src/bee-cache-update.sh.in @@ -48,8 +48,16 @@ function create_pkgbcfile() if [ -e "${PKGBCFILE}" ] ; then print_info "moving ${PKGBCFILE} to ${PKGBCRFILE}.." mv "${PKGBCFILE}" "${PKGBCRFILE}" - fi; - return 0 + return 0 + elif [ -e "${PKGBCRFILE}" ] ; then + return 0 + elif [ -e "${CONTENTFILE}.bee-remove" ] ; then + CONTENTFILE=${CONTENTFILE}.bee-remove + PKGBCFILE=${PKGBCRFILE} + tmpfile=${PKGBCFILE}.tmp.$$ + else + return 0 + fi fi print_info "creating ${PKGBCFILE} .." From 3829384bbbab0551b8f46b317d3879b6a6f157b1 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Tue, 24 Jul 2012 14:07:44 +0200 Subject: [PATCH 04/17] bee-cache-update: reverse sort INVENTORY This is needed to easily remove directories after the files inside the directory are removed. --- src/bee-cache-update.sh.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bee-cache-update.sh.in b/src/bee-cache-update.sh.in index da733db..daa133f 100644 --- a/src/bee-cache-update.sh.in +++ b/src/bee-cache-update.sh.in @@ -64,7 +64,7 @@ function create_pkgbcfile() ${BEE_LIBEXECDIR}/bee/bee-cache-inventory \ --prepend "${PKGALLPKG} " \ ${CONTENTFILE} \ - | sort -k 8 -k 1 \ + | sort -r -k 8 -k 1 \ >${tmpfile} if [ ${PIPESTATUS[0]} != 0 -o ${PIPESTATUS[1]} != 0 ] ; then @@ -100,7 +100,7 @@ function update_inventory() print_info "merging ${PKGBCFILE} with ${INVENTORYFILE} .." - sort -u -m -k 8 -k 1 >${tmpfile} \ + sort -u -m -r -k 8 -k 1 >${tmpfile} \ ${INVENTORYFILE} \ ${PKGBCFILE} @@ -123,7 +123,7 @@ function create_inventory() ${BEE_LIBEXECDIR}/bee/bee-cache-inventory \ ${BEE_METADIR} \ - | sort -k 8 -k 1 \ + | sort -r -k 8 -k 1 \ >${tmpfile} if [ ${PIPESTATUS[0]} != 0 -o ${PIPESTATUS[1]} != 0 ] ; then From 4ac9f5c866c31618fe53953ff397e96ec5aeda08 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Tue, 24 Jul 2012 21:10:39 +0200 Subject: [PATCH 05/17] bee-cache-update: Preserve uniqueness of inventory entries.. ..even if a pkg is added twice. --- src/bee-cache-update.sh.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bee-cache-update.sh.in b/src/bee-cache-update.sh.in index daa133f..2147a4e 100644 --- a/src/bee-cache-update.sh.in +++ b/src/bee-cache-update.sh.in @@ -100,7 +100,7 @@ function update_inventory() print_info "merging ${PKGBCFILE} with ${INVENTORYFILE} .." - sort -u -m -r -k 8 -k 1 >${tmpfile} \ + sort -u -m -u -r -k 8 -k 1 >${tmpfile} \ ${INVENTORYFILE} \ ${PKGBCFILE} From 682802d266341c31e1d8686e84765dddc50a5aeb Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Tue, 24 Jul 2012 14:11:31 +0200 Subject: [PATCH 06/17] bee-cache: Add new tool to manage inventory This replaces bee-dep with the new bee-cache tool in bee-install and in bee-remove. --- .gitignore | 1 + Makefile | 1 + src/bee-cache.sh.in | 201 ++++++++++++++++++++++++++++++++++++++++++ src/bee-install.sh.in | 11 +-- src/bee-remove.sh.in | 19 ++-- 5 files changed, 215 insertions(+), 18 deletions(-) create mode 100644 src/bee-cache.sh.in diff --git a/.gitignore b/.gitignore index 616155a..e74fba2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /bee.sh +/bee-cache.sh /bee-check.sh /bee-init.sh /bee-install.sh diff --git a/Makefile b/Makefile index 223cb80..ff0c88a 100644 --- a/Makefile +++ b/Makefile @@ -66,6 +66,7 @@ PROGRAMS_SHELL+=beesh HELPER_BEE_C+=bee-dep +HELPER_BEE_SHELL+=bee-cache HELPER_BEE_SHELL+=bee-check HELPER_BEE_SHELL+=bee-download HELPER_BEE_SHELL+=bee-init diff --git a/src/bee-cache.sh.in b/src/bee-cache.sh.in new file mode 100644 index 0000000..2182d31 --- /dev/null +++ b/src/bee-cache.sh.in @@ -0,0 +1,201 @@ +#!/bin/bash +# +# bee-cache - manage inventory +# +# Copyright (C) 2012 +# Marius Tolzmann +# Tobias Dreyer +# and other bee developers +# +# This file is part of bee. +# +# bee is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +if [ -z "${BEE_VERSION}" ] ; then + echo >&2 "BEE-ERROR: please call $0 from bee .." + exit 1 +fi + +VERSION=${BEE_VERSION} + +: ${BEE_BINDIR:=@BINDIR@} +: ${BEEFLOCK=${BEE_BINDIR}/beeflock} +: ${BEECACHE_CACHEDIR=${BEE_CACHEDIR}/bee-cache} +: ${BEECACHE_INVENTORY=${BEECACHE_CACHEDIR}/INVENTORY} + +function cache_verify() { + if ! ${BEEFLOCK} --shared "${BEECACHE_INVENTORY}" \ + sort -c -u -r -k8 -k1 "${BEECACHE_INVENTORY}" 2>/dev/null ; then + rm -fr "${BEECACHE_CACHEDIR}" + fi + + mkdir -p "${BEECACHE_CACHEDIR}" +} + +function cache_update() { + local pkgs="${@}" + + for p in "${pkgs[@]}" ; do + cache_update_pkg "${p}" + done +} + +function cache_update_pkg() { + local pkg=${1} + + ${BEEFLOCK} ${BEECACHE_INVENTORY} \ + ${BEE_LIBEXECDIR}/bee/bee-cache-update ${pkg} \ + >/dev/null + + if [ $? -ne 0 ] ; then + echo >&2 "bee-cache: ${pkg}: Updating inventory failed." + return 1 + fi + + return 0 +} + +function cache_uniq() { + local file=${1} + + uniq -u -f7 ${file} +} + +function print_uniq_files() { + local pkg=$1 + + if [ -z "${pkg}" ] ; then + echo >&2 "bee-cache: print-uniq-files: no package provided." + return 1 + fi + + print_uniq_files_for_pkg "${pkg}" \ + <( tmp_merge_install_inventory_files "${TMPINSTALL[@]}" ) +} + +function print_uniq_files_for_pkg() { + local pkg=$1 + local inventory=$2 + + cache_uniq ${inventory} \ + | grep -E "^${pkg} " \ + | cut -d ' ' -f8- +} + +function tmp_merge_install_inventory_files() { + ${BEEFLOCK} --shared ${BEECACHE_INVENTORY} sort -m -u -r -k8 -k1 \ + ${BEECACHE_INVENTORY} "${@}" +} + +function tmpinstall_to_filenames() { + local -a fn + + for f in "${TMPINSTALL[@]}" ; do + if [ -e "${f}" ] ; then + fn=( "${fn[@]}" "$f" ) + continue + fi + + if [ -e "${BEECACHE_CACHEDIR}/${f}.bc" ] ; then + fn=( "${fn[@]}" "${BEECACHE_CACHEDIR}/${f}.bc" ) + continue + fi + + if [ -e "${BEECACHE_CACHEDIR}/${f}.bcr" ] ; then + fn=( "${fn[@]}" "${BEECACHE_CACHEDIR}/${f}.bcr" ) + continue + fi + + cache_update "${f}" + + if [ -e "${BEECACHE_CACHEDIR}/${f}.bc" ] ; then + fn=( "${fn[@]}" "${BEECACHE_CACHEDIR}/${f}.bc" ) + continue + fi + + if [ -e "${BEECACHE_CACHEDIR}/${f}.bcr" ] ; then + fn=( "${fn[@]}" "${BEECACHE_CACHEDIR}/${f}.bcr" ) + continue + fi + + echo >&2 "bee-cache: ${f}: Can't create inventory." + exit 1 + done + + TMPINSTALL=( "${fn[@]}" ) + return 0 +} + +function usage() { + cat <<-EOF + bee-cache v${VERSION} 2012 + by Marius Tolzmann and Tobias Dreyer <{tolzmann,dreyer}@molgen.mpg.de> + Max Planck Institute for Molecular Genetics Berlin Dahlem + + Usage: bee remove [options] + + Options: + -h, --help display this help + + EOF +} + +options=$(${BEE_BINDIR}/beegetopt --name bee-cache \ + --option help/h \ + --option tmpinstall/i= \ + -- "$@") + +if [ $? != 0 ] ; then + usage + exit 1 +fi +eval set -- "${options}" + +declare -a TMPINSTALL + +while true ; do + case "$1" in + --help) + usage + exit 0 + ;; + --tmpinstall) + TMPINSTALL=( "${tmpinstall[@]}" "$2" ) + shift 2 + ;; + --) + shift + break + ;; + esac +done + +cmd=$1 +shift + +cache_verify +tmpinstall_to_filenames + +case "${cmd}" in + update) + cache_update "${@}" + ;; + print-uniq-files) + print_uniq_files "${@}" + ;; + *) + echo >&2 "bee-cache: ${cmd}: Unknown command." + exit 1 +esac diff --git a/src/bee-install.sh.in b/src/bee-install.sh.in index ee09a52..3ef466e 100644 --- a/src/bee-install.sh.in +++ b/src/bee-install.sh.in @@ -31,8 +31,6 @@ fi VERSION=${BEE_VERSION} : ${BEE_BINDIR:=@BINDIR@} -: ${BEEFLOCK=${BEE_BINDIR}/beeflock} -: ${BEECACHE_CACHEDIR=${BEE_CACHEDIR}/bee-cache} function debug_msg() { if [ "${OPT_DEBUG}" != "1" ] ; then @@ -337,6 +335,9 @@ function do_install() { return } +function bee-cache() { + ${BEE_LIBEXECDIR}/bee/bee.d/bee-cache "${@}" +} function do_install_file() { local file=$1 @@ -399,14 +400,10 @@ function do_install_file() { # create CONTENT file from CONTENT.INSTALL mv ${BEE_METADIR}/${pkg}/CONTENT{.INSTALL,} - mkdir -p ${BEECACHE_CACHEDIR} - ${BEEFLOCK} ${BEECACHE_CACHEDIR}/INVENTORY \ - ${BEE_LIBEXECDIR}/bee/bee-cache-update ${pkg} \ - >/dev/null + bee-cache update ${pkg} run_hooks post-install ${pkg} ${BEE_LIBEXECDIR}/bee/bee.d/bee-check -d ${pkg} > ${BEE_METADIR}/${pkg}/DEPENDENCIES - ${BEE_LIBEXECDIR}/bee/bee.d/bee-dep update ${pkg} } function run_hooks() { diff --git a/src/bee-remove.sh.in b/src/bee-remove.sh.in index d5b9ccf..85e3046 100644 --- a/src/bee-remove.sh.in +++ b/src/bee-remove.sh.in @@ -31,8 +31,6 @@ fi VERSION=${BEE_VERSION} : ${BEE_BINDIR:=@BINDIR@} -: ${BEEFLOCK=${BEE_BINDIR}/beeflock} -: ${BEECACHE_CACHEDIR=${BEE_CACHEDIR}/bee-cache} pkg_remove_all() { for pkg in "${@}" ; do @@ -55,6 +53,10 @@ pkg_remove() { ${BEE_LIBEXECDIR}/bee/bee.d/bee-list -i "${search}" } +function bee-cache() { + ${BEE_LIBEXECDIR}/bee/bee.d/bee-cache "${@}" +} + do_remove() { pkg=${1} @@ -63,24 +65,19 @@ do_remove() { return 1 fi - mkdir -p ${BEECACHE_CACHEDIR} - ${BEEFLOCK} ${BEECACHE_CACHEDIR}/INVENTORY \ - ${BEE_LIBEXECDIR}/bee/bee-cache-update ${pkg} \ - >/dev/null - - FILES=$(${BEE_LIBEXECDIR}/bee/bee.d/bee-dep remove --print ${pkg}) + bee-cache update ${pkg} if [ $? -ne 0 ] ; then - echo "removal of ${pkg} failed" + echo >&2 "bee-remove: ${pkg}: bee-cache update failed." exit 1 fi [ "${NOOP}" != "yes" ] && \ run_hooks pre-remove ${pkg} ${BEE_METADIR}/${pkg}/CONTENT.bee-remove - echo "removing package '${pkg}'" + FILES=( $(bee-cache --tmpinstall "${pkg}" print-uniq-files "${pkg}") ) # removing files - for f in $FILES ; do + for f in "${FILES[@]}" ; do if [ -d "${f}" -a ! -h "$f" ] ; then ${NOOP:+echo} rmdir ${OPT_VERBOSE:+-v} ${f} else From 466d4ffabddb68676fd249e3585b35c9301d86b2 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Tue, 24 Jul 2012 23:05:24 +0200 Subject: [PATCH 07/17] bee-cache: Add new command 'print-conflicting-files' this prints all "real" conflicts where files with an identical filename have different sizes and content (identified by md5sum) --- src/bee-cache.sh.in | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/bee-cache.sh.in b/src/bee-cache.sh.in index 2182d31..31c2157 100644 --- a/src/bee-cache.sh.in +++ b/src/bee-cache.sh.in @@ -67,6 +67,33 @@ function cache_update_pkg() { return 0 } +function cache_conflicts() { + local file=${1} + + uniq -D -f7 ${file} | uniq -u -f5 +} + +function print_conflicting_files() { + local pkg=$1 + + if [ -z "${pkg}" ] ; then + echo >&2 "bee-cache: print-conflicting-files: No package provided." + return 1 + fi + + print_conflicting_files_for_pkg "${pkg}" \ + <( tmp_merge_install_inventory_files "${TMPINSTALL[@]}" ) +} + +function print_conflicting_files_for_pkg() { + local pkg=$1 + local inventory=$2 + + cache_conflicts ${inventory} \ + | grep -E "^${pkg} " \ + | cut -d ' ' -f8- +} + function cache_uniq() { local file=${1} @@ -195,6 +222,9 @@ case "${cmd}" in print-uniq-files) print_uniq_files "${@}" ;; + print-conflicting-files) + print_conflicting_files "${@}" + ;; *) echo >&2 "bee-cache: ${cmd}: Unknown command." exit 1 From 913c9d05c90e4135278cff0a6a10a0653c642585 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Tue, 24 Jul 2012 23:20:30 +0200 Subject: [PATCH 08/17] bee-cache: Introduce new --fields option .. to select inventory fields to print --- src/bee-cache.sh.in | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bee-cache.sh.in b/src/bee-cache.sh.in index 31c2157..644bfa4 100644 --- a/src/bee-cache.sh.in +++ b/src/bee-cache.sh.in @@ -91,7 +91,7 @@ function print_conflicting_files_for_pkg() { cache_conflicts ${inventory} \ | grep -E "^${pkg} " \ - | cut -d ' ' -f8- + | cut -d ' ' -f${FIELDS} } function cache_uniq() { @@ -118,7 +118,7 @@ function print_uniq_files_for_pkg() { cache_uniq ${inventory} \ | grep -E "^${pkg} " \ - | cut -d ' ' -f8- + | cut -d ' ' -f${FIELDS} } function tmp_merge_install_inventory_files() { @@ -181,6 +181,7 @@ function usage() { options=$(${BEE_BINDIR}/beegetopt --name bee-cache \ --option help/h \ + --option fields/f= \ --option tmpinstall/i= \ -- "$@") @@ -191,6 +192,7 @@ fi eval set -- "${options}" declare -a TMPINSTALL +declare FIELDS="8-" while true ; do case "$1" in @@ -202,6 +204,10 @@ while true ; do TMPINSTALL=( "${tmpinstall[@]}" "$2" ) shift 2 ;; + --fields) + FIELDS=${2} + shift 2 + ;; --) shift break From c4e065b71ef76e1f56f42af14609c6089246fe11 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Tue, 24 Jul 2012 23:56:39 +0200 Subject: [PATCH 09/17] bee-cache: Add new command 'print-conflicts' print all conflicts with other packages --- src/bee-cache.sh.in | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/bee-cache.sh.in b/src/bee-cache.sh.in index 644bfa4..1a17196 100644 --- a/src/bee-cache.sh.in +++ b/src/bee-cache.sh.in @@ -67,6 +67,21 @@ function cache_update_pkg() { return 0 } +function print_conflicts() { + local pkg=${1} + + pkgfullname=$(${BEE_BINDIR}/beeversion --pkgfullname ${pkg}) + + if [ -z "${pkgfullname}" ] ; then + echo >&2 "bee-cache: ${pkg}: Can't parse bee-package." + exit 1 + fi + + grep --file=<(print_conflicting_files "${pkg}" | cut -d ' ' -f8-) \ + <( tmp_merge_install_inventory_files "${TMPINSTALL[@]}" ) \ + | grep -v -E "^${pkgfullname}-[^-]+-[^-]+ " +} + function cache_conflicts() { local file=${1} @@ -90,8 +105,7 @@ function print_conflicting_files_for_pkg() { local inventory=$2 cache_conflicts ${inventory} \ - | grep -E "^${pkg} " \ - | cut -d ' ' -f${FIELDS} + | grep -E "^${pkg} " } function cache_uniq() { @@ -117,8 +131,7 @@ function print_uniq_files_for_pkg() { local inventory=$2 cache_uniq ${inventory} \ - | grep -E "^${pkg} " \ - | cut -d ' ' -f${FIELDS} + | grep -E "^${pkg} " } function tmp_merge_install_inventory_files() { @@ -226,10 +239,13 @@ case "${cmd}" in cache_update "${@}" ;; print-uniq-files) - print_uniq_files "${@}" + print_uniq_files "${@}" | cut -d ' ' -f${FIELDS} ;; print-conflicting-files) - print_conflicting_files "${@}" + print_conflicting_files "${@}" | cut -d ' ' -f${FIELDS} + ;; + print-conflicts) + print_conflicts "${@}" | cut -d ' ' -f${FIELDS} ;; *) echo >&2 "bee-cache: ${cmd}: Unknown command." From dadec22c722395ea8968eaf9ce657e32985e70ee Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Wed, 25 Jul 2012 01:07:32 +0200 Subject: [PATCH 10/17] bee-install: Print conflicts after installing/updating a package --- src/bee-install.sh.in | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/bee-install.sh.in b/src/bee-install.sh.in index 3ef466e..67c1d5a 100644 --- a/src/bee-install.sh.in +++ b/src/bee-install.sh.in @@ -404,6 +404,18 @@ function do_install_file() { run_hooks post-install ${pkg} ${BEE_LIBEXECDIR}/bee/bee.d/bee-check -d ${pkg} > ${BEE_METADIR}/${pkg}/DEPENDENCIES + + last="" + while read p f ; do + if [ "${last}" != "${f}" ] ; then + [ "${last}" != "" ] && echo "" + echo " conflicting file found: $f" + echo -n " also in packages:" + last=${f} + fi + echo -n " $p" + done < <(bee-cache print-conflicts ${pkg} -f1,8- | sort -k2 -k1 -u ) + [ "${last}" != "" ] && echo "" } function run_hooks() { From 505191d6f459b9f05451192c512c481ca26f4e28 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Wed, 25 Jul 2012 11:02:11 +0200 Subject: [PATCH 11/17] beesh: Show conflicts with installed packages --- src/beesh.sh.in | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/beesh.sh.in b/src/beesh.sh.in index d99f4f5..07b4557 100644 --- a/src/beesh.sh.in +++ b/src/beesh.sh.in @@ -798,6 +798,7 @@ PKGALLPKG= config_handle_deprecated_beefile expand_prefix_variables +config_export ############################################################################### @@ -858,6 +859,30 @@ bee_crosscheck bee_pkg_pack +function bee-cache() { + ${BEE_LIBEXECDIR}/bee/bee.d/bee-cache "${@}" +} + +function bee_check_conflicts() { + ${BEE_LIBEXECDIR}/bee/bee-cache-inventory CONTENT \ + --prepend "${PKGALLPKG} " \ + | sort -r -u -k8 -k1 \ + > ${PKGALLPKG}.bc + + last="" + while read p f ; do + if [ "${last}" != "${p}" ] ; then + print_info "${COLOR_RED}Conflicts with installed package found: ${p}:${COLOR_NORMAL}" + last=${p} + fi + print_info "${COLOR_NORMAL} $f" + done < <(bee-cache print-conflicts ${PKGALLPKG} \ + --tmpinstall ${PKGALLPKG}.bc \ + -f1,8- | sort -k1 -u ) +} + +bee_check_conflicts + cd ${BEEWORKDIR} bee_archivebuild @@ -878,7 +903,6 @@ echo if [ "${OPT_INSTALL}" = "yes" ] ; then - config_export print_info "installing ${PKGALLPKG} .." ${BEE_LIBEXECDIR}/bee/bee.d/bee-install ${OPT_FORCE:+-f} ${OPT_UPDATE:+-u} ${BEE_PKGDIR}/${PKGALLPKG}.bee.tar.bz2 From 4559de83c952b95d526d51bfd382b097f05517b2 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Wed, 25 Jul 2012 11:11:16 +0200 Subject: [PATCH 12/17] bee-install: Change conflict output --- src/bee-install.sh.in | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/bee-install.sh.in b/src/bee-install.sh.in index 67c1d5a..d12a5af 100644 --- a/src/bee-install.sh.in +++ b/src/bee-install.sh.in @@ -407,15 +407,12 @@ function do_install_file() { last="" while read p f ; do - if [ "${last}" != "${f}" ] ; then - [ "${last}" != "" ] && echo "" - echo " conflicting file found: $f" - echo -n " also in packages:" - last=${f} + if [ "${last}" != "${p}" ] ; then + echo -e " Conflicts with installed package found: ${p}:" + last=${p} fi - echo -n " $p" + echo " $f" done < <(bee-cache print-conflicts ${pkg} -f1,8- | sort -k2 -k1 -u ) - [ "${last}" != "" ] && echo "" } function run_hooks() { From 13c9373cc873caf06de4d70e55aef67ce400fe80 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Wed, 25 Jul 2012 13:42:51 +0200 Subject: [PATCH 13/17] bee-cache/bee-dep: Remove old bee-dep All functionality of bee-dep that was integrated into build/install/remove processes is now replaced by bee-cache. This fixes the conflict part of issue #45. We still need to find a way to handle dependencies. --- .gitignore | 2 - Makefile | 7 - manpages/bee-dep.1.in | 86 --- src/bee-dep.c | 926 ------------------------------- src/beedep_tree.c | 416 -------------- src/beedep_tree.h | 55 -- src/graph.c | 1228 ----------------------------------------- src/graph.h | 61 -- src/hash.c | 99 ---- src/hash.h | 45 -- src/node.c | 78 --- src/node.h | 47 -- 12 files changed, 3050 deletions(-) delete mode 100644 manpages/bee-dep.1.in delete mode 100644 src/bee-dep.c delete mode 100644 src/beedep_tree.c delete mode 100644 src/beedep_tree.h delete mode 100644 src/graph.c delete mode 100644 src/graph.h delete mode 100644 src/hash.c delete mode 100644 src/hash.h delete mode 100644 src/node.c delete mode 100644 src/node.h diff --git a/.gitignore b/.gitignore index e74fba2..c7de0f6 100644 --- a/.gitignore +++ b/.gitignore @@ -17,7 +17,6 @@ /beeversion /beegetopt /beeflock -/bee-dep /beelib.config.sh /bee.1 /bee-check.1 @@ -26,7 +25,6 @@ /bee-list.1 /bee-query.1 /bee-remove.1 -/bee-dep.1 /beefind.sh /bee-cache-inventory /bee-cache-update.sh diff --git a/Makefile b/Makefile index ff0c88a..a00d031 100644 --- a/Makefile +++ b/Makefile @@ -64,8 +64,6 @@ PROGRAMS_SHELL+=bee PROGRAMS_SHELL+=beefind PROGRAMS_SHELL+=beesh -HELPER_BEE_C+=bee-dep - HELPER_BEE_SHELL+=bee-cache HELPER_BEE_SHELL+=bee-check HELPER_BEE_SHELL+=bee-download @@ -108,7 +106,6 @@ HELPER_HOOKS_SHELL+=gconf-install-schemas MANPAGES+=bee.1 MANPAGES+=bee-check.1 -MANPAGES+=bee-dep.1 MANPAGES+=bee-download.1 MANPAGES+=bee-list.1 MANPAGES+=bee-init.1 @@ -146,7 +143,6 @@ BEESEP_OBJECTS=beesep.o BEECUT_OBJECTS=beecut.o BEEUNIQ_OBJECTS=beeuniq.o BEESORT_OBJECTS=bee_tree.o bee_version_compare.o bee_version_output.o bee_version_parse.o bee_getopt.o beesort.o -BEEDEP_OBJECTS=bee-dep.o graph.o hash.o beedep_tree.o node.o BEEGETOPT_OBJECTS=bee_getopt.o beegetopt.o BEEFLOCK_OBJECTS=bee_getopt.o beeflock.o BEECACHEINVENTORY_OBJECTS=bee-cache-inventory.o bee_getopt.o @@ -174,9 +170,6 @@ beeuniq: $(addprefix src/, ${BEEUNIQ_OBJECTS}) beesort: $(addprefix src/, ${BEESORT_OBJECTS}) $(call quiet-command,${CC} ${LDFLAGS} -o $@ $^,"LD $@") -bee-dep: $(addprefix src/, ${BEEDEP_OBJECTS}) - $(call quiet-command,${CC} ${LDFLAGS} -o $@ $^,"LD $@") - beegetopt: $(addprefix src/, ${BEEGETOPT_OBJECTS}) $(call quiet-command,${CC} ${LDFLAGS} -o $@ $^,"LD $@") diff --git a/manpages/bee-dep.1.in b/manpages/bee-dep.1.in deleted file mode 100644 index 529accb..0000000 --- a/manpages/bee-dep.1.in +++ /dev/null @@ -1,86 +0,0 @@ -.TH "bee\-dep" "1" "2012-05-16" "bee @BEE_VERSION@" "bee - bau et einfach" - -.SH "NAME" -bee\-dep \- bee dependency tool - -.SH "SYNOPSIS" -.SY "bee dep" - -.OP -.YS - -.SH "DESCRIPTION" -.B bee\-dep -reads the DEPENDENCIES file of every installed package and is able to query several information about the packages. - -.SH "COMMANDS" -.TP -.B rebuild -Rebuild the cache. Therefore the old cache is deleted and then recreated with the information of the DEPENDENCIES file of each installed package. -.SY update -.OP pkgname -.YS -Update the cache for a specific package. -.SY remove -.OP options -.I -.YS -Remove a package from the cache. -.SY list -.OP options -.OP pkgname -.YS -Query information about a package. -.TP -.B conflicts -Show conflicting packages. - -.SH "ENVIRONMENT" -.TP -BEE_METADIR -Directory where to search for installed bee packages -.TP -BEE_CACHEDIR -Directory where to save and read the cache file -.I index.db -and -the lock file -.I index.lock - -.SH "AUTHORS" -.P -.MT ruester@molgen.mpg.de -Matthias Ruester -.ME -.br -.MT schwass@molgen.mpg.de -Lucas Schwass -.ME -.br -.MT tolzmann@molgen.mpg.de -Marius Tolzmann -.ME -.br -.MT dreyer@molgen.mpg.de -Tobias Dreyer -.ME -.br -and other bee developers - -.SH "BEE" -.P -This file is part of bee. -.P -Please report bugs to bee-dev@googlegroups.com or directly to the authors. - -.SH "SEE ALSO" -.BR bee (1) -.BR bee\-check (1) -.BR bee\-dep (1) -.BR bee\-download (1) -.BR bee\-init (1) -.BR bee\-install (1) -.BR bee\-list (1) -.BR bee\-query (1) -.BR bee\-remove (1) -.BR bee\-update (1) diff --git a/src/bee-dep.c b/src/bee-dep.c deleted file mode 100644 index 12524b8..0000000 --- a/src/bee-dep.c +++ /dev/null @@ -1,926 +0,0 @@ -/* -** bee-dep - dependency tool for bee -** -** Copyright (C) 2009-2012 -** Matthias Ruester -** Lucas Schwass -** Marius Tolzmann -** Tobias Dreyer -** and other bee developers -** -** This file is part of bee. -** -** bee is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, see . -*/ - -#define _GNU_SOURCE - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "graph.h" - -#define CACHENAME "index.db" -#define TMPNAME "index.tmp" -#define LOCKNAME "index.lock" - -#define REBUILD 1 -#define UPDATE 2 -#define REMOVE 3 -#define LIST 4 -#define CONFLICTS 5 - -static char *bee_version(void) -{ - static char *bee_v = NULL; - - if (!bee_v) - bee_v = getenv("BEE_VERSION"); - - return bee_v; -} - -static char *bee_metadir(void) -{ - static char *bee_md = NULL; - - if (!bee_md) - bee_md = getenv("BEE_METADIR"); - - return bee_md; -} - -static char *bee_cachedir(void) -{ - static char *bee_cd = NULL; - - if (!bee_cd) - bee_cd = getenv("BEE_CACHEDIR"); - - return bee_cd; -} - -static void get_bee_variables(void) -{ - if (!bee_version()) { - fprintf(stderr, "BEE-ERROR: please call bee-dep from bee\n"); - exit(EXIT_FAILURE); - } - - if (!bee_metadir()) { - fprintf(stderr, "BEE-ERROR: BEE_METADIR not set\n"); - exit(EXIT_FAILURE); - } - - if (!bee_cachedir()) { - fprintf(stderr, "BEE_ERROR: BEE_CACHEDIR not set\n"); - exit(EXIT_FAILURE); - } -} - -static char *cache_filename(void) -{ - static char cache[PATH_MAX + 1] = {0}; - - if (!cache[0]) - sprintf(cache, "%s/%s", bee_cachedir(), CACHENAME); - - return cache; -} - -static char *lock_filename(void) -{ - static char lock[PATH_MAX + 1] = {0}; - - if (!lock[0]) - sprintf(lock, "%s/%s", bee_cachedir(), LOCKNAME); - - return lock; -} - -static void usage_header(void) -{ - printf("bee-dep v%s 2011-2012\n" - " by Matthias Ruester and Lucas Schwass\n" - " Max Planck Institute for Molecular Genetics Berlin Dahlem\n\n", - bee_version()); -} - -static void usage(void) -{ - usage_header(); - puts("Usage: bee dep []\n\n" - - "Commands:\n" - " rebuild rebuild the cache\n" - " update update the cache for a specific package\n" - " remove remove a package from the cache\n" - " list list information\n" - " conflicts show conflicting packages\n\n" - - "See 'bee dep --help' for more information on a specific command."); -} - -static void usage_rebuild(void) -{ - usage_header(); - puts("Usage: bee dep rebuild\n\n" - - "Rebuild the cache.\n"); -} - -static void usage_update(void) -{ - usage_header(); - puts("Usage: bee dep update \n\n" - - "Update the information about a package.\n"); -} - -static void usage_remove(void) -{ - usage_header(); - puts("Usage: bee dep remove [options] \n\n" - - "Remove a package from the cache.\n\n" - - "Options:\n" - " --print print which files can be deleted from the hard drive\n"); -} - -static void usage_list(void) -{ - usage_header(); - puts("Usage: bee dep list [options]\n\n" - - "Get information from the cache.\n\n" - - "Options:\n" - " --packages list all packages\n" - " --files list all files of a package\n" - " --depending-on list packages depending on a pkg or file\n" - " --required-by list packages required by a pkg or file\n" - " --removable show all removable files of a package\n" - " --provider-of show the providers of a file\n" - " --not-cached print files which are not in the cache;\n" - " check those files which are listed in \n" - " --broken list all broken dependencies\n" - " --count do not print results; just count\n"); -} - -static void usage_conflicts(void) -{ - usage_header(); - puts("Usage: bee dep conflicts\n\n" - - "Print conflicting packages.\n"); -} - -/* create all directories in path with mode mode */ -int mkdirp(char *path, mode_t mode) -{ - char *dir, *pdir, *end; - int ret; - - assert(path); - - dir = end = path; - - while (*dir) { - /* skip "/" */ - dir = end + strspn(end, "/"); - - /* skip non-"/" */ - end = dir + strcspn(dir, "/"); - - /* grab everything in path till current end */ - if (!(pdir = strndup(path, end - path))) - return -1; - - /* create the directory ; ignore err if it already exists */ - ret = mkdir(pdir, mode); - - free(pdir); - - if (ret == -1 && errno != EEXIST) - return -1; - } - - return 0; -} - -void ensure_directories(void) -{ - if (mkdirp(bee_cachedir(), 0755) == -1) { - perror("bee-dep: mkdirp"); - exit(EXIT_FAILURE); - } -} - -static struct hash *init_cache(void) -{ - struct dirent **package; - int i, pkg_cnt; - char path[PATH_MAX + 1]; - struct stat st; - struct hash *graph; - - if (stat(bee_metadir(), &st) == -1) - return NULL; - - if ((pkg_cnt = scandir(bee_metadir(), &package, 0, alphasort)) < 0) { - perror("bee-dep: init_cache: scandir"); - return NULL; - } - - graph = hash_new(); - - /* skip . and .. */ - free(package[0]); - free(package[1]); - - for (i = 2; i < pkg_cnt; i++) { - sprintf(path, "%s/%s", bee_metadir(), package[i]->d_name); - - if (stat(path, &st) == -1) { - perror("bee-dep: init_cache: stat"); - hash_free(graph); - return NULL; - } - - if (S_ISDIR(st.st_mode)) { - strcat(path, "/DEPENDENCIES"); - - if (stat(path, &st) == -1) { - fprintf(stderr, - "bee-dep: init_cache: missing " - "DEPENDENCIES file for package \"%s\"\n", - package[i]->d_name); - hash_free(graph); - return NULL; - } - - if (graph_insert_nodes(graph, path)) { - hash_free(graph); - return NULL; - } - } - - free(package[i]); - } - - free(package); - - if (save_cache(graph, cache_filename())) { - hash_free(graph); - return NULL; - } - - return graph; -} - -static int update_cache(struct hash *graph) -{ - struct dirent **package; - int i, pkg_cnt; - char path[PATH_MAX + 1]; - struct stat st; - struct tree_node *t; - - if (stat(bee_metadir(), &st) == -1) - return 0; - - if ((pkg_cnt = scandir(bee_metadir(), &package, 0, alphasort)) < 0) { - perror("bee-dep: update_cache: scandir"); - return 1; - } - - /* skip . and .. */ - free(package[0]); - free(package[1]); - - /* add new (not known) packages */ - for (i = 2; i < pkg_cnt; i++) { - if (hash_search(graph, package[i]->d_name)) - continue; - - printf("adding %s\n", package[i]->d_name); - - if (sprintf(path, "%s/%s", bee_metadir(), package[i]->d_name) < 0) { - perror("bee-dep: update_cache: sprintf"); - return 1; - } - - if (stat(path, &st) == -1) { - perror("bee-dep: update_cache: stat"); - return 1; - } - - if (S_ISDIR(st.st_mode)) { - strcat(path, "/DEPENDENCIES"); - - if (stat(path, &st) == -1) { - fprintf(stderr, - "bee-dep: update_cache: missing " - "DEPENDENCIES file for package \"%s\"\n", - package[i]->d_name); - return 1; - } - - if (graph_insert_nodes(graph, path)) - return 1; - } - - free(package[i]); - } - - free(package); - - /* remove packages which not exist anymore */ - for (i = 0; i < TBLSIZE; i++) { - t = tree_first(graph->tbl[i]->root); - - while (t) { - if (IS_PKG(t->n)) { - if (sprintf(path, "%s/%s", bee_metadir(), t->n->name) < 0) { - perror("bee-dep: update_cache: sprintf"); - return 1; - } - - if (stat(path, &st) == -1) { - printf("removing %s\n", t->n->name); - - if (remove_package(graph, t->n->name)) - return 1; - } - } - - t = tree_next(t); - } - } - - return 0; -} - -struct hash *get_cache(void) -{ - struct hash *graph; - struct stat st; - - if (stat(cache_filename(), &st) == -1) - graph = init_cache(); - else - graph = load_cache(cache_filename()); - - if (!graph) - exit(EXIT_FAILURE); - - return graph; -} - -static int bee_dep_rebuild(int argc, char *argv[]) -{ - int c, help; - struct hash *graph; - struct option long_options[] = { - {"help", 0, &help, 1}, - {0, 0, 0, 0} - }; - - help = 0; - - while ((c = getopt_long(argc, argv, "", long_options, NULL)) != -1) { - switch (c) { - case '?': - usage_update(); - return 1; - } - } - - if (help) { - usage_rebuild(); - return 0; - } - - if (argc > 1) { - fprintf(stderr, "bee-dep: too many arguments\n"); - return 1; - } - - graph = init_cache(); - hash_free(graph); - - return 0; -} - -static int bee_dep_update(int argc, char *argv[]) -{ - int c, help; - char *pkg; - char path[PATH_MAX + 1]; - struct hash *graph; - struct stat st; - struct option long_options[] = { - {"help", 0, &help, 1}, - {0, 0, 0, 0} - }; - - help = 0; - - while ((c = getopt_long(argc, argv, "", long_options, NULL)) != -1) { - switch (c) { - case '?': - usage_update(); - return 1; - } - } - - if (help) { - usage_update(); - return 0; - } - - if (argc == 1) { - graph = get_cache(); - - if (update_cache(graph) || save_cache(graph, cache_filename())) { - hash_free(graph); - return 1; - } - - hash_free(graph); - return 0; - } - - if (argc < 2) { - fprintf(stderr, "bee-dep: pkgname needed\n"); - return 1; - } - - if (argc > 2) { - fprintf(stderr, "bee-dep: too many arguments\n"); - return 1; - } - - pkg = argv[1]; - - if (sprintf(path, "%s/%s/DEPENDENCIES", bee_metadir(), pkg) < 0) { - perror("bee-dep: sprintf"); - return 1; - } - - graph = get_cache(); - - if (stat(path, &st) != -1) { - if (hash_search(graph, pkg)) { - hash_free(graph); - return 0; - } - - if (graph_insert_nodes(graph, path)) { - hash_free(graph); - return 1; - } - } else { - if (remove_package(graph, pkg)) { - hash_free(graph); - return 1; - } - } - - if (save_cache(graph, cache_filename())) { - hash_free(graph); - return 1; - } - - hash_free(graph); - return 0; -} - -static int bee_dep_remove(int argc, char *argv[]) -{ - int i, c, help, print; - struct hash *graph; - char *pkg; - struct option long_options[] = { - {"help", 0, &help, 1}, - {"print", 0, &print, 1}, - {0, 0, 0, 0} - }; - - help = print = 0; - - while ((c = getopt_long(argc, argv, "", long_options, NULL)) != -1) { - switch (c) { - case '?': - usage_remove(); - return 1; - } - } - - if (help) { - usage_remove(); - return 0; - } - - if (optind == argc) { - fprintf(stderr, "bee-dep: pkgname needed\n"); - return 1; - } - - graph = get_cache(); - - for (i = optind; i < argc; i++) { - pkg = argv[i]; - - if (print && print_removable(graph, pkg)) { - hash_free(graph); - return 1; - } - - if (remove_package(graph, pkg)) { - hash_free(graph); - return 1; - } - } - - if (save_cache(graph, cache_filename())) { - hash_free(graph); - return 1; - } - - hash_free(graph); - return 0; -} - -static int bee_dep_list(int argc, char *argv[]) -{ - int c, i, opt_count, help, files, packages, count, - depending_on, required_by, removable, provider_of, - not_cached, broken; - struct hash *graph; - char *name; - struct option long_options[] = { - {"help", 0, &help, 1}, - {"files", 0, &files, 1}, - {"packages", 0, &packages, 1}, - {"count", 0, &count, 1}, - {"depending-on", 0, &depending_on, 1}, - {"required-by", 0, &required_by, 1}, - {"removable", 0, &removable, 1}, - {"provider-of", 0, &provider_of, 1}, - {"not-cached", 0, ¬_cached, 1}, - {"broken", 0, &broken, 1}, - {0, 0, 0, 0} - }; - - opt_count = help = files = packages = provider_of = - count = depending_on = required_by = removable = not_cached = - broken = 0; - - while ((c = getopt_long(argc, argv, "", long_options, NULL)) != -1) { - switch (c) { - case '?': - usage_list(); - return 1; - - default: - opt_count++; - } - } - - if (help) { - usage_list(); - return 0; - } - - if (!opt_count && optind != argc) { - fprintf(stderr, "bee-dep: too many arguments\n"); - return 1; - } - - if (!opt_count) - packages = 1; - - if (opt_count > 1 && !count) { - fprintf(stderr, "bee-dep: too many options specified\n"); - return 1; - } - - if (packages) { - graph = get_cache(); - - if (count) - printf("%d\n", count_packages(graph)); - else - list_packages(graph); - - hash_free(graph); - return 0; - } - - if (broken && optind < argc) { - fprintf(stderr, "bee-dep: too many arguments\n"); - return 1; - } - - if (optind == argc && !broken) { - fprintf(stderr, "bee-dep: arguments needed\n"); - return 1; - } - - if (count && (depending_on || required_by)) - fprintf(stderr, "bee-dep: ignoring option --count\n"); - - graph = get_cache(); - - for (i = optind; i < argc; i++) { - name = argv[i]; - - if (optind < argc - 1) - printf("%s:\n", name); - - if (files) { - if (count) { - c = count_files(graph, name); - - if (c < 0) { - hash_free(graph); - return 1; - } - - printf("%d\n", c); - } else if (list_files(graph, name)) { - hash_free(graph); - return 1; - } - } - - if (removable) { - if (count) { - c = count_removable(graph, name); - - if (c < 0) { - hash_free(graph); - return 1; - } - - printf("%d\n", c); - } else if (print_removable(graph, name)) { - hash_free(graph); - return 1; - } - } - - if (depending_on && print_neededby(graph, name)) { - hash_free(graph); - return 1; - } - - if (required_by && print_needs(graph, name)) { - hash_free(graph); - return 1; - } - - if (provider_of) { - if (count) { - c = count_providers(graph, name); - - if (c < 0) { - hash_free(graph); - return 1; - } - - printf("%d\n", c); - } else if (print_providers(graph, name)) { - hash_free(graph); - return 1; - } - } - - if (not_cached) { - c = print_not_cached(graph, name, !count); - - if (c < 0) { - hash_free(graph); - return 1; - } - - if (count) - printf("%d\n", c); - } - } - - if (broken) { - c = print_broken(graph, !count); - - if (c < 0) { - hash_free(graph); - return 1; - } - - if (count) - printf("%d\n", c); - } - - hash_free(graph); - return 0; -} - -static int bee_dep_conflicts(int argc, char *argv[]) -{ - int c, opt_count, help; - struct hash *graph; - struct option long_options[] = { - {"help", 0, &help, 1}, - {0, 0, 0, 0} - }; - - help = opt_count = 0; - - while ((c = getopt_long(argc, argv, "", long_options, NULL)) != -1) { - switch (c) { - case '?': - usage_conflicts(); - return 1; - - default: - opt_count++; - } - } - - if (help) { - usage_conflicts(); - return 0; - } - - if (optind < argc) { - fprintf(stderr, "bee-dep: too many arguments\n"); - return 1; - } - - graph = get_cache(); - - if (print_conflicts(graph)) { - hash_free(graph); - return 1; - } - - hash_free(graph); - return 0; -} - -static int get_command(char *command) -{ - if (!strcmp("rebuild", command)) - return REBUILD; - - if (!strcmp("update", command)) - return UPDATE; - - if (!strcmp("remove", command)) - return REMOVE; - - if (!strcmp("list", command)) - return LIST; - - if (!strcmp("conflicts", command)) - return CONFLICTS; - - return 0; -} - -static FILE *lockfile(void) -{ - static FILE *file = NULL; - - if (!file) { - ensure_directories(); - - if ((file = fopen(lock_filename(), "w")) == NULL) { - perror("bee-dep: lockfile"); - exit(EXIT_FAILURE); - } - - fprintf(file, "locked by pid %d\n", getpid()); - fflush(file); - } - - return file; -} - -void lock(void) -{ - FILE *f; - struct flock flo; - - f = lockfile(); - - flo.l_start = flo.l_len = 0; - flo.l_whence = SEEK_SET; - flo.l_type = F_WRLCK; - - if (fcntl(fileno(f), F_SETLKW, &flo) == -1) { - perror("bee-dep: lock"); - exit(EXIT_FAILURE); - } -} - -void unlock(void) -{ - FILE *f; - struct flock flo; - - f = lockfile(); - - if (!f) - return; - - flo.l_start = flo.l_len = 0; - flo.l_whence = SEEK_SET; - flo.l_type = F_UNLCK; - - rewind(f); - - if (ftruncate(fileno(f), 0) == -1) { - perror("bee-dep: unlock: ftruncate"); - exit(EXIT_FAILURE); - } - - if (fcntl(fileno(f), F_SETLK, &flo) == -1) { - perror("bee-dep: unlock: fcntl"); - exit(EXIT_FAILURE); - } - - if (fclose(f) == EOF) { - perror("bee-dep: unlock: fclose"); - exit(EXIT_FAILURE); - } -} - -int main(int argc, char *argv[]) -{ - int command; - - get_bee_variables(); - - if (argc < 2) { - usage(); - return 1; - } - - lock(); - if (atexit(unlock)) { - perror("bee-dep: atexit"); - return 1; - } - - command = get_command(argv[1]); - - argv++; - argc--; - - switch (command) { - case REBUILD: - return bee_dep_rebuild(argc, argv); - - case UPDATE: - return bee_dep_update(argc, argv); - - case REMOVE: - return bee_dep_remove(argc, argv); - - case LIST: - return bee_dep_list(argc, argv); - - case CONFLICTS: - return bee_dep_conflicts(argc, argv); - - default: - usage(); - return 1; - } - - return 0; -} diff --git a/src/beedep_tree.c b/src/beedep_tree.c deleted file mode 100644 index 556692e..0000000 --- a/src/beedep_tree.c +++ /dev/null @@ -1,416 +0,0 @@ -/* -** bee-dep - dependency tool for bee -** -** Copyright (C) 2009-2012 -** Matthias Ruester -** Lucas Schwass -** Marius Tolzmann -** Tobias Dreyer -** and other bee developers -** -** This file is part of bee. -** -** bee is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, see . -*/ - -#include -#include -#include - -#include "beedep_tree.h" - -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#define ABS(a) (((a) < 0) ? (-(a)) : (a)) - -struct tree *tree_new(void) -{ - struct tree *t; - - if ((t = calloc(1, sizeof(*t))) == NULL) { - perror("bee-dep: tree_new: calloc"); - exit(EXIT_FAILURE); - } - - return t; -} - -struct tree_node *tree_node_new(struct node *n) -{ - struct tree_node *t; - - if ((t = calloc(1, sizeof(*t))) == NULL) { - perror("bee-dep: tree_node_new: calloc"); - exit(EXIT_FAILURE); - } - - t->n = n; - - return t; -} - -void tree_node_update_values(struct tree_node *root) -{ - unsigned char depth_left, depth_right; - - do { - depth_left = root->left ? root->left->max_depth + 1 : 0; - depth_right = root->right ? root->right->max_depth + 1 : 0; - root->max_depth = MAX(depth_left, depth_right); - root->balance_value = depth_left - depth_right; - root = root->parent; - } while (root); -} - -struct tree_node *tree_node_rotate_left(struct tree_node *root) -{ - struct tree_node *pivot; - - /* if no rotation is possible return old root */ - if (!root->right) - return root; - - /* initialize rotation: point pivot to the new root */ - pivot = root->right; - pivot->parent = root->parent; - - /* start rotation by moving pivot roots child to old root */ - root->right = pivot->left; - if (root->right) - root->right->parent = root; - - /* continue rotation by making old root a child of pivot root */ - pivot->left = root; - root->parent = pivot; - - /* finish rotation by updating parents reference - of pivot root if needed */ - if (pivot->parent) { - if (pivot->parent->left == root) - pivot->parent->left = pivot; - else - pivot->parent->right = pivot; - } - - tree_node_update_values(root); - - return pivot; -} - -struct tree_node *tree_node_rotate_right(struct tree_node *root) -{ - struct tree_node *pivot; - - /* if no rotation is possible return old root */ - if (!root->left) - return root; - - /* initialize rotation: point pivot to the new root */ - pivot = root->left; - pivot->parent = root->parent; - - /* start rotation by moving pivot roots child to old root */ - root->left = pivot->right; - if (root->left) - root->left->parent = root; - - /* continue rotation by making old root a child of pivot root */ - pivot->right = root; - root->parent = pivot; - - /* finish rotation by updating parents reference - of pivot root if needed */ - if (pivot->parent) { - if (pivot->parent->left == root) - pivot->parent->left = pivot; - else - pivot->parent->right = pivot; - } - - tree_node_update_values(root); - - return pivot; -} - -struct tree_node *tree_node_balance(struct tree_node *n) -{ - struct tree_node *tn; - - if (ABS(n->balance_value) < 2) { - if (n->parent) - return tree_node_balance(n->parent); - return n; - } - - if (n->balance_value > 1) { - /* left right case */ - if (n->left->balance_value < 0) - n->left = tree_node_rotate_left(n->left); - - /* left left case */ - tn = tree_node_rotate_right(n); - } else { - /* right left case */ - if (n->right->balance_value > 0) - n->right = tree_node_rotate_right(n->right); - - /* right right case */ - tn = tree_node_rotate_left(n); - } - - if (tn->parent) - return tree_node_balance(tn->parent); - return tn; -} - -void tree_insert(struct tree *t, struct node *n) -{ - int comp; - struct tree_node *root; - - if (!t->root) { - t->root = tree_node_new(n); - return; - } - - root = t->root; - - while (root) { - comp = nodecmp(root->n, n); - - if (comp < 0) { - if (!root->left) { - root->left = tree_node_new(n); - root->left->parent = root; - break; - } - - root = root->left; - continue; - } - - if (comp > 0) { - if (!root->right) { - root->right = tree_node_new(n); - root->right->parent = root; - break; - } - - root = root->right; - continue; - } - - return; - } - - tree_node_update_values(root); - root = tree_node_balance(root); - - if (!root->parent) - t->root = root; -} - -struct tree_node *tree_search_tree_node(struct tree *t, struct node *n) -{ - int comp; - struct tree_node *root; - - root = t->root; - - while (root) { - comp = nodecmp(root->n, n); - - if (comp < 0) { - root = root->left; - continue; - } - - if (comp > 0) { - root = root->right; - continue; - } - - return root; - } - - return NULL; -} - -struct node *tree_search_node(struct tree *t, char *name) -{ - int comp; - struct tree_node *root; - - root = t->root; - - while (root) { - comp = strcmp(root->n->name, name); - - if (comp == 0) - return root->n; - - if (comp < 0) { - root = root->left; - continue; - } - - if (comp > 0) { - root = root->right; - continue; - } - } - - return NULL; -} - -struct tree_node *predecessor(struct tree_node *root) -{ - struct tree_node *current; - - current = root->left; - - if (!current) - return NULL; - - while (current->right) - current = current->right; - - return current; -} - -void tree_node_free(struct tree *t, struct tree_node *n) -{ - struct tree_node *delete, - *replace, - *to_update; - - delete = n; - - if (!delete) - return; - - if (delete->left) { - if (delete->right) { - replace = predecessor(delete); - - delete->n = replace->n; - delete = replace; - - if (delete->left) { - delete->n = delete->left->n; - delete = delete->left; - } - - } else { - delete->n = delete->left->n; - delete = delete->left; - } - } else { - if (delete->right) { - delete->n = delete->right->n; - delete = delete->right; - } - } - - if ((to_update = delete->parent)) { - if (to_update->left == delete) - to_update->left = NULL; - else - to_update->right = NULL; - } else { - t->root = NULL; - } - - free(delete); - - if (to_update) { - tree_node_update_values(to_update); - replace = tree_node_balance(to_update); - if (!replace->parent) - t->root = replace; - } -} - -void tree_count_nodes(struct tree_node *n, unsigned long *cnt) -{ - if (!n) - return; - - (*cnt)++; - - tree_count_nodes(n->left, cnt); - tree_count_nodes(n->right, cnt); -} - -unsigned long tree_count(struct tree *t) -{ - unsigned long cnt = 0; - - tree_count_nodes(t->root, &cnt); - - return cnt; -} - -void free_nodes(struct tree_node *n) -{ - if (!n) - return; - - free_nodes(n->left); - free_nodes(n->right); - node_free(n->n); -} - -void tree_free_all_nodes(struct tree *t) -{ - free_nodes(t->root); -} - -void free_tree_nodes(struct tree_node *n) -{ - if (!n) - return; - - free_tree_nodes(n->left); - free_tree_nodes(n->right); - free(n); -} - -void tree_free(struct tree *t) -{ - free_tree_nodes(t->root); - free(t); -} - -struct tree_node *tree_next(struct tree_node *t) -{ - struct tree_node *a; - - if (t->right) - return tree_first(t->right); - - do { - a = t; - t = t->parent; - } while (t && t->right == a); - - return t; -} - -struct tree_node *tree_first(struct tree_node *t) -{ - while (t && t->left) - t = t->left; - - return t; -} diff --git a/src/beedep_tree.h b/src/beedep_tree.h deleted file mode 100644 index 1123fee..0000000 --- a/src/beedep_tree.h +++ /dev/null @@ -1,55 +0,0 @@ -/* -** bee-dep - dependency tool for bee -** -** Copyright (C) 2009-2012 -** Matthias Ruester -** Lucas Schwass -** Marius Tolzmann -** Tobias Dreyer -** and other bee developers -** -** This file is part of bee. -** -** bee is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, see . -*/ - -#ifndef BEEDEP_TREE_H -#define BEEDEP_TREE_H - -#include "node.h" - -struct tree { - struct tree_node *root; -}; - -struct tree_node { - struct node *n; - struct tree_node *left, *right, *parent; - unsigned char max_depth; - char balance_value; -}; - -extern struct tree *tree_new(void); -extern void tree_insert(struct tree *root, struct node *n); -extern struct tree_node *tree_search_tree_node(struct tree *t, - struct node *n); -extern struct node *tree_search_node(struct tree *t, char *name); -extern void tree_node_free(struct tree *t, struct tree_node *n); -extern unsigned long tree_count(struct tree *t); -extern void tree_free_all_nodes(struct tree *t); -extern void tree_free(struct tree *t); -extern struct tree_node *tree_next(struct tree_node *t); -extern struct tree_node *tree_first(struct tree_node *t); - -#endif diff --git a/src/graph.c b/src/graph.c deleted file mode 100644 index 38da473..0000000 --- a/src/graph.c +++ /dev/null @@ -1,1228 +0,0 @@ -/* -** bee-dep - dependency tool for bee -** -** Copyright (C) 2009-2012 -** Matthias Ruester -** Lucas Schwass -** Marius Tolzmann -** Tobias Dreyer -** and other bee developers -** -** This file is part of bee. -** -** bee is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, see . -*/ - -#include -#include -#include -#include -#include - -#include "graph.h" - -#define IS_FILE(a) ((a)[0] == '/') -#define IS_DIR(a) (!strcmp((a)->type, DIR)) -#define IS_WHITESPACE(a) ((a) == ' ' || (a) == '\t' || (a) == '\n' || (a) == '\r') - -static void add_provide(struct node *a, struct node *b) -{ - tree_insert(a->provide, b); - tree_insert(b->providedby, a); -} - -static void add_need(struct node *a, struct node *b) -{ - tree_insert(a->need, b); - tree_insert(b->neededby, a); -} - -char *get_filename(char *s) -{ - while (*s != '/') - s++; - - return s; -} - -char *get_pkgname(char *s) -{ - char a[NODENAME_MAX]; - char *p, *i; - - p = s; - i = a; - - while (*p != '/') { - *i = *p; - p++; - i++; - } - - *i = '\0'; - - return strdup(a); -} - -char is_virtual_file(char *s) -{ - if (*s == '/') - return 0; - - while (*s && *s != '/') - s++; - - return *s == '/'; -} - -int graph_insert_nodes(struct hash *hash, char *filename) -{ - FILE *file; - register char *s, *p, *a; - char type_flag, u; - char line[LINE_MAX], - prop[LINE_MAX], - value[LINE_MAX], - pkgname[NODENAME_MAX] = {0}, - nodename[NODENAME_MAX] = {0}; - int l, line_cnt; - struct node *n, *h, *v, *c; - - if ((file = fopen(filename, "r")) == NULL) { - perror("bee-dep: graph_insert_nodes: fopen"); - return 1; - } - - line_cnt = type_flag = u = 0; - n = NULL; - - while (fgets(line, LINE_MAX, file)) { - line_cnt++; - - if (!line[0]) - continue; - - /* remove unnecessary characters */ - l = strlen(line); - s = line; - p = line + (l - 1) * sizeof(char); - h = NULL; - - while (p - s && *p && IS_WHITESPACE(*p)) - *(p--) = 0; - - while (*s && (*s == ' ' || *s == '\t')) - s++; - - l = p - s; - - if (l <= 0 || *s == '#') - continue; - - /* read node name */ - if (*s == '[') { - s++; - - if (*p != ']') { - fprintf(stderr, - "bee-dep: %s: error at line %d: missing bracket\n", - filename, line_cnt); - return 1; - } - - *p = '\0'; - - if (p - s == 0) { - fprintf(stderr, - "bee-dep: %s: error at line %d: empty node name\n", - filename, line_cnt); - return 1; - } - - if (IS_FILE(s)) { - if (!pkgname[0]) { - fprintf(stderr, - "bee-dep: %s: error at line %d: " - "dont know to which package" - "\"%s\" belongs to\n", filename, line_cnt, s); - return 1; - } - - sprintf(nodename, "%s%s", pkgname, s); - } else { - sprintf(nodename, "%s", s); - } - - c = node_new(nodename, UNKNOWN); - n = hash_safe_insert(hash, c); - if (c != n) - node_free(c); - - type_flag = 0; - continue; - } - - /* read node properties */ - a = s; - - while (*a && *a != ' ' && *a != '\t' && *a != '=') - a++; - - l = a - s; - - memset(prop, '\0', LINE_MAX); - strncpy(prop, s, l * sizeof(char)); - - while (*a && (*a == ' ' || *a == '\t' || *a == '=')) - a++; - - l = p - a + 1; - - memset(value, '\0', LINE_MAX); - strncpy(value, a, l * sizeof(char)); - - if (strcasecmp(prop, TYPE) == 0) { - if (type_flag) { - fprintf(stderr, - "bee-dep: %s: error at line %d: " - "ambiguous type \"%s\"\n", - filename, line_cnt, value); - return 1; - } - - node_set_type(n, value); - - if (is_virtual_file(n->name)) - node_set_type(hash_search(hash, get_filename(n->name)), - value); - - if (strcasecmp(PACKAGE, value) == 0) - sprintf(pkgname, "%s", n->name); - - type_flag = 1; - } else if (strcasecmp(prop, PROVIDES) == 0) { - c = node_new(value, UNKNOWN); - h = hash_safe_insert(hash, c); - - if (c != h) - node_free(c); - - if (IS_FILE(value)) { - sprintf(nodename, "%s%s", pkgname, value); - - c = node_new(nodename, UNKNOWN); - v = hash_safe_insert(hash, c); - - if (v != c) - node_free(c); - - add_provide(n, v); - add_provide(v, h); - } else { - add_provide(n, h); - } - } else if (strcasecmp(prop, NEEDS) == 0) { - c = node_new(value, UNKNOWN); - h = hash_safe_insert(hash, c); - - if (c != h) - node_free(c); - - add_need(n, h); - } - } - - if (fclose(file) == EOF) { - perror("bee-dep: graph_insert_nodes: fclose"); - return 1; - } - - if (line_cnt == 0) { - fprintf(stderr, "bee-dep: error: file '%s' is empty\n", filename); - return 1; - } - - return 0; -} - -static void search_dependencies(struct hash *hash, struct node *n, - struct tree *d) -{ - struct tree_node *t; - char *pkgname; - - t = tree_first(n->neededby->root); - - while (t) { - if (is_virtual_file(t->n->name)) { - pkgname = get_pkgname(t->n->name); - if (!tree_search_node(d, pkgname)) - tree_insert(d, hash_search(hash, pkgname)); - free(pkgname); - } - - t = tree_next(t); - } - - t = tree_first(n->provide->root); - - while (t) { - search_dependencies(hash, t->n, d); - t = tree_next(t); - } -} - -static int print_dependencies(struct hash *hash, struct node *n) -{ - struct tree *t; - struct tree_node *e; - - t = tree_new(); - - search_dependencies(hash, n, t); - - e = tree_first(t->root); - - while (e) { - if (strcmp(n->name, e->n->name) != 0) - puts(e->n->name); - - e = tree_next(e); - } - - tree_free(t); - - return 0; -} - -void add_all_neededby(struct hash *hash, struct node *n, struct tree *a) -{ - struct tree_node *t; - char *pkgname; - - t = tree_first(n->neededby->root); - - while (t) { - add_all_neededby(hash, t->n, a); - pkgname = get_pkgname(t->n->name); - if (is_virtual_file(t->n->name)) - tree_insert(a, hash_search(hash, pkgname)); - free(pkgname); - t = tree_next(t); - } -} - -void check_remove(struct hash *hash, struct node *n, struct tree *r) -{ - struct tree_node *t; - - t = tree_first(n->provide->root); - - while (t) { - check_remove(hash, t->n, r); - t = tree_next(t); - } - - if (tree_count(n->providedby) == 1) - add_all_neededby(hash, n, r); -} - -void print_broken_nodes(struct node *n, int *count, - char *header, char print, - struct tree *dry) -{ - struct tree_node *t; - char *pkgname; - - t = tree_first(n->provide->root); - - while (t) { - print_broken_nodes(t->n, count, header, print, dry); - t = tree_next(t); - } - - /* for the next step we have to assert - that n is a virtual file */ - if (!is_virtual_file(n->name)) - return; - - t = tree_first(n->need->root); - - while (t) { - if (!tree_count(t->n->providedby)) { - (*count)++; - - if (print) { - if (!*(header)) { - (*header) = 1; - pkgname = get_pkgname(n->name); - printf("%s:\n", pkgname); - free(pkgname); - } - - /* don't repeat yourself */ - if (!tree_search_tree_node(dry, t->n)) { - printf(" %s -> %s\n", - get_filename(n->name), t->n->name); - tree_insert(dry, t->n); - } - } - } - - t = tree_next(t); - } -} - -int print_broken(struct hash *hash, char print) -{ - int c, i; - char h; - struct tree_node *t; - struct tree *dry; - - c = 0; - - for (i = 0; i < TBLSIZE; i++) { - t = tree_first(hash->tbl[i]->root); - - while (t) { - h = 0; - - if (IS_PKG(t->n)) { - dry = tree_new(); - print_broken_nodes(t->n, &c, &h, print, dry); - tree_free(dry); - } - - t = tree_next(t); - } - } - - return c; -} - -void sort_dirs(char **dirs, int dir_cnt) -{ - int i, j; - size_t c; - char *h; - - for (i = 1; i < dir_cnt; i++) { - h = dirs[i]; - j = i; - c = strlen(h); - - while (j > 0 && strlen(dirs[j - 1]) < c) { - dirs[j] = dirs[j - 1]; - j--; - } - - dirs[j] = h; - } -} - -void search_removable(struct hash *hash, struct node *n, - struct tree *t, char *remove) -{ - struct tree_node *e; - char *pkgname; - - e = tree_first(n->provide->root); - - while (e) { - search_removable(hash, e->n, t, remove); - e = tree_next(e); - } - - if (IS_FILE(n->name) && tree_count(n->providedby) <= 1) { - pkgname = get_pkgname(n->providedby->root->n->name); - - if (!strcmp(pkgname, remove)) - tree_insert(t, n); - - free(pkgname); - } -} - -int print_removable(struct hash *hash, char *remove) -{ - struct node *n; - struct tree *t; - struct tree_node *e; - char **dirs, **files; - int cnt, dir_cnt, file_cnt, i; - - if ((n = hash_search(hash, remove)) == NULL) { - fprintf(stderr, - "bee-dep: print_removable: cannot find \"%s\"\n", - remove); - return 1; - } - - if (!IS_PKG(n)) { - fprintf(stderr, - "bee-dep: print_removable: \"%s\": no such package\n", - remove); - return 1; - } - - t = tree_new(); - - search_removable(hash, n, t, remove); - - cnt = tree_count(t); - - if ((dirs = calloc(cnt, sizeof(*dirs))) == NULL - || (files = calloc(cnt, sizeof(*files))) == NULL) { - perror("bee-dep: print_removable: calloc"); - return 1; - } - - e = tree_first(t->root); - dir_cnt = file_cnt = 0; - - while (e) { - if (IS_DIR(e->n)) - dirs[dir_cnt++] = e->n->name; - else - files[file_cnt++] = e->n->name; - - e = tree_next(e); - } - - sort_dirs(dirs, dir_cnt); - - for (i = 0; i < file_cnt; i++) - puts(files[i]); - - for (i = 0; i < dir_cnt; i++) - puts(dirs[i]); - - free(dirs); - free(files); - tree_free(t); - - return 0; -} - -int count_removable(struct hash *hash, char *remove) -{ - struct node *n; - struct tree *t; - int c; - - if ((n = hash_search(hash, remove)) == NULL) { - fprintf(stderr, - "bee-dep: print_removable: cannot find \"%s\"\n", - remove); - return -1; - } - - if (!IS_PKG(n)) { - fprintf(stderr, - "bee-dep: print_removable: \"%s\": no such package\n", - remove); - return -1; - } - - t = tree_new(); - - search_removable(hash, n, t, remove); - - c = tree_count(t); - - tree_free(t); - - return c; -} - -static int list_all_files(struct node *n, char print) -{ - struct tree_node *t; - int count; - - t = tree_first(n->provide->root); - count = 0; - - while (t) { - if (IS_FILE(t->n->name)) { - count++; - - if (print) - puts(t->n->name); - } - - count += list_all_files(t->n, print); - - t = tree_next(t); - } - - return count; -} - -static int count_all_files(struct node *n) -{ - struct tree_node *t; - int count; - - t = tree_first(n->provide->root); - count = 0; - - while (t) { - if (IS_FILE(t->n->name)) - count++; - - count += list_all_files(t->n, 0); - - t = tree_next(t); - } - - return count; -} - -int list_files(struct hash *hash, char *pkgname) -{ - struct node *n; - - if ((n = hash_search(hash, pkgname)) == NULL) { - fprintf(stderr, - "bee-dep: list_files: cannot find \"%s\"\n", - pkgname); - return 1; - } - - if (!IS_PKG(n)) { - fprintf(stderr, - "bee-dep: list_files: \"%s\": no such package\n", - pkgname); - return 1; - } - - list_all_files(n, 1); - - return 0; -} - -int count_files(struct hash *hash, char *pkgname) -{ - struct node *n; - - if ((n = hash_search(hash, pkgname)) == NULL) { - fprintf(stderr, - "bee-dep: count_files: cannot find \"%s\"\n", - pkgname); - return -1; - } - - if (!IS_PKG(n)) { - fprintf(stderr, - "bee-dep: count_files: \"%s\": no such package\n", - pkgname); - return -1; - } - - return count_all_files(n); -} - -static void get_all_providers(struct node *n, struct tree *all) -{ - struct tree_node *t; - - t = tree_first(n->providedby->root); - - while (t) { - if (IS_PKG(t->n) && !tree_search_node(all, t->n->name)) - tree_insert(all, node_new(t->n->name, "")); - - get_all_providers(t->n, all); - - t = tree_next(t); - } -} - -int print_providers(struct hash *hash, char *name) -{ - struct node *n; - struct tree_node *t; - struct tree *all; - - if ((n = hash_search(hash, name)) == NULL) { - fprintf(stderr, - "bee-dep: print_providers: cannot find \"%s\"\n", - name); - return 1; - } - - if (IS_PKG(n)) { - fprintf(stderr, - "bee-dep: print_providers: \"%s\" is a package\n", - name); - return 1; - } - - all = tree_new(); - - get_all_providers(n, all); - - t = tree_first(all->root); - - while (t) { - puts(t->n->name); - t = tree_next(t); - } - - tree_free_all_nodes(all); - tree_free(all); - - return 0; -} - -int count_providers(struct hash *hash, char *name) -{ - int count; - struct node *n; - struct tree *all; - - count = 0; - - if ((n = hash_search(hash, name)) == NULL) { - fprintf(stderr, - "bee-dep: count_providers: cannot find \"%s\"\n", - name); - return -1; - } - - if (IS_PKG(n)) { - fprintf(stderr, - "bee-dep: count_providers: error: \"%s\" is a package\n", - name); - return -1; - } - - all = tree_new(); - get_all_providers(n, all); - - count = tree_count(all); - - tree_free_all_nodes(all); - tree_free(all); - - return count; -} - -int get_virtual_files(struct node *n, char *name, struct tree *all) -{ - struct tree_node *t; - - t = tree_first(n->providedby->root); - - while (t) { - if (!strcmp(name, get_filename(t->n->name)) - && !tree_search_node(all, t->n->name)) - tree_insert(all, t->n); - - t = tree_next(t); - } - - return tree_count(all); -} - -static void search_requirements(struct hash *hash, struct node *n, - struct tree *d) -{ - struct tree_node *t, *u; - struct tree *providers; - - t = tree_first(n->need->root); - - while (t) { - providers = tree_new(); - - get_all_providers(t->n, providers); - - u = tree_first(providers->root); - - while (u) { - if (!tree_search_node(d, u->n->name)) - tree_insert(d, hash_search(hash, u->n->name)); - - u = tree_next(u); - } - - tree_free_all_nodes(providers); - tree_free(providers); - - t = tree_next(t); - } - - t = tree_first(n->provide->root); - - while (t) { - search_requirements(hash, t->n, d); - t = tree_next(t); - } -} - -static int print_requirements(struct hash *hash, struct node *n) -{ - struct tree *t; - struct tree_node *e; - - t = tree_new(); - - search_requirements(hash, n, t); - - e = tree_first(t->root); - - while (e) { - if (strcmp(n->name, e->n->name) != 0) - puts(e->n->name); - - e = tree_next(e); - } - - tree_free(t); - - return 0; -} - -int print_needs(struct hash *hash, char *name) -{ - struct tree_node *t, *v; - struct node *n; - struct tree *all, *vf; - char *pkgname; - int count; - char p; - - if ((n = hash_search(hash, name)) == NULL) { - fprintf(stderr, - "bee-dep: print_needs: cannot find \"%s\"\n", - name); - return 1; - } - - if (IS_PKG(n)) - return print_requirements(hash, n); - - vf = tree_new(); - count = 1; - - if (is_virtual_file(n->name)) - tree_insert(vf, n); - else - count = get_virtual_files(n, name, vf); - - if (!count) { - fprintf(stderr, "bee-dep: could not get virtual file for \"%s\"\n", - name); - tree_free(vf); - return 1; - } - - v = tree_first(vf->root); - - while (v) { - all = tree_new(); - - t = tree_first(v->n->need->root); - - while (t) { - get_all_providers(t->n, all); - t = tree_next(t); - } - - t = tree_first(all->root); - p = (t && count > 1); - - if (p) { - pkgname = get_pkgname(v->n->name); - printf("%s:\n", pkgname); - free(pkgname); - } - - while (t) { - puts(t->n->name); - t = tree_next(t); - } - - tree_free_all_nodes(all); - tree_free(all); - - v = tree_next(v); - - if (v && p) - puts(""); - } - - tree_free(vf); - - return 0; -} - -int print_neededby(struct hash *hash, char *name) -{ - struct node *n; - struct tree_node *t; - struct tree *all; - - if ((n = hash_search(hash, name)) == NULL) { - fprintf(stderr, - "bee-dep: print_needs: cannot find \"%s\"\n", - name); - return 1; - } - - if (IS_PKG(n)) - return print_dependencies(hash, n); - - all = tree_new(); - - t = tree_first(n->neededby->root); - - while (t) { - get_all_providers(t->n, all); - t = tree_next(t); - } - - t = tree_first(all->root); - - while (t) { - puts(t->n->name); - t = tree_next(t); - } - - tree_free_all_nodes(all); - tree_free(all); - - return 0; -} - -void list_packages(struct hash *hash) -{ - int i; - struct tree_node *t; - - for (i = 0; i < TBLSIZE; i++) { - t = tree_first(hash->tbl[i]->root); - - while (t) { - if (IS_PKG(t->n)) - puts(t->n->name); - t = tree_next(t); - } - } -} - -int count_packages(struct hash *hash) -{ - int i, c; - struct tree_node *t; - - c = 0; - - for (i = 0; i < TBLSIZE; i++) { - t = tree_first(hash->tbl[i]->root); - - while (t) { - if (IS_PKG(t->n)) - c++; - t = tree_next(t); - } - } - - return c; -} - -int save_cache(struct hash *hash, char *path) -{ - int i; - struct tree_node *s, *t; - FILE *file; - - if ((file = fopen(path, "w")) == NULL) { - perror("bee-dep: save_cache: fopen"); - return 1; - } - - for (i = 0; i < TBLSIZE; i++) { - if (hash->tbl[i]->root) { - t = tree_first(hash->tbl[i]->root); - - while (t) { - fprintf(file, "%s %s\n", t->n->name, t->n->type); - t = tree_next(t); - } - } - } - - fprintf(file, "#\n"); - - for (i = 0; i < TBLSIZE; i++) { - if (hash->tbl[i]->root) { - t = tree_first(hash->tbl[i]->root); - - while (t) { - if (t->n->need->root) { - s = tree_first(t->n->need->root); - - while (s) { - fprintf(file, "%s %s n\n", t->n->name, s->n->name); - s = tree_next(s); - } - } - - if (t->n->provide->root) { - s = tree_first(t->n->provide->root); - - while (s) { - fprintf(file, "%s %s p\n", t->n->name, s->n->name); - s = tree_next(s); - } - } - - t = tree_next(t); - } - } - } - - if (fclose(file) == EOF) { - perror("bee-dep: save_cache: fclose"); - return 1; - } - - return 0; -} - -struct hash *load_cache(char *filename) -{ - char line[LINE_MAX], - a[NODENAME_MAX], - b[NODENAME_MAX]; - char c; - struct node *k, *l; - int line_cnt; - FILE *file; - struct hash *hash; - - if ((file = fopen(filename, "r")) == NULL) { - perror("bee-dep: load_cache: fopen"); - return NULL; - } - - hash = hash_new(); - - line_cnt = 0; - - while (fgets(line, LINE_MAX, file)) { - line_cnt++; - - if (line[0] == '#') - break; - - if (sscanf(line, "%s %s", a, b) == EOF) { - fprintf(stderr, "beedep: load_cache: " - "cache file is broken (line %d)\n", line_cnt); - hash_free(hash); - return NULL; - } - - hash_insert(hash, node_new(a, b)); - } - - while (fgets(line, LINE_MAX, file)) { - line_cnt++; - - if (sscanf(line, "%s %s %c", a, b, &c) == EOF) { - fprintf(stderr, "beedep: load_cache: " - "cache file is broken (line %d)\n", line_cnt); - hash_free(hash); - return NULL; - } - - k = hash_search(hash, a); - l = hash_search(hash, b); - - if (!k || !l) { - fprintf(stderr, "beedep: load_cache: " - "cache file is broken (line %d)\n", line_cnt); - hash_free(hash); - return NULL; - } - - if (c == 'n') { - tree_insert(k->need, l); - tree_insert(l->neededby, k); - } else if (c == 'p') { - tree_insert(k->provide, l); - tree_insert(l->providedby, k); - } else { - fprintf(stderr, "beedep: load_cache: " - "cache file is broken (line %d)\n", line_cnt); - hash_free(hash); - return NULL; - } - } - - if (fclose(file) == EOF) { - perror("bee-dep: load_cache: fclose"); - hash_free(hash); - return NULL; - } - - return hash; -} - -void remove_all(struct hash *hash, struct node *n) -{ - struct tree *t; - struct tree_node *h, *s; - - if (n->neededby->root || n->providedby->root) - return; - - h = tree_first(n->provide->root); - - while (h) { - s = tree_search_tree_node(h->n->providedby, n); - tree_node_free(h->n->providedby, s); - remove_all(hash, h->n); - h = tree_next(h); - } - - h = tree_first(n->need->root); - - while (h) { - s = tree_search_tree_node(h->n->neededby, n); - tree_node_free(h->n->neededby, s); - remove_all(hash, h->n); - h = tree_next(h); - } - - t = hash->tbl[hash_index(n->name)]; - s = tree_search_tree_node(t, n); - tree_node_free(t, s); - - node_free(n); -} - -int remove_package(struct hash *hash, char *pkgname) -{ - struct node *n; - - if ((n = hash_search(hash, pkgname)) == NULL) { - fprintf(stderr, - "bee-dep: remove_package: cannot find \"%s\"\n", - pkgname); - return 1; - } - - if (!IS_PKG(n)) { - fprintf(stderr, - "bee-dep: remove_package: \"%s\": no such package\n", - pkgname); - return 1; - } - - remove_all(hash, n); - - return 0; -} - -int print_conflicts(struct hash *hash) -{ - int i; - struct tree_node *t, *s; - char *pkgname; - - for (i = 0; i < TBLSIZE; i++) { - t = tree_first(hash->tbl[i]->root); - - while (t) { - if (!IS_FILE(t->n->name) || IS_DIR(t->n) - || tree_count(t->n->providedby) < 2) { - t = tree_next(t); - continue; - } - - printf("%s: ", t->n->name); - - s = tree_first(t->n->providedby->root); - - while (s) { - if (IS_PKG(s->n)) { - printf("%s", s->n->name); - } else if (is_virtual_file(s->n->name)) { - pkgname = get_pkgname(s->n->name); - printf("%s", pkgname); - free(pkgname); - } else { - fprintf(stderr, "bee-dep: print_conflicts: " - "could not get pkgname for \"%s\"\n", - s->n->name); - return 1; - } - - s = tree_next(s); - - if (!s) - puts(""); - else - printf(" "); - } - - t = tree_next(t); - } - } - - return 0; -} - -int print_not_cached(struct hash *hash, char *filename, char print) -{ - int c; - FILE *file; - char lookup[PATH_MAX]; - - c = 0; - - if ((file = fopen(filename, "r")) == NULL) { - perror("bee-dep: print_not_cached: fopen"); - return -1; - } - - while (fgets(lookup, PATH_MAX, file) != NULL) { - /* skip empty lines */ - if (lookup[0] == '\n') - continue; - - /* remove trailing '\n' */ - lookup[strlen(lookup) - 1] = '\0'; - - if (hash_search(hash, lookup)) - continue; - - if (print) - puts(lookup); - - c++; - } - - if (fclose(file) == EOF) { - perror("bee-dep: print_not_cached: fclose"); - return -1; - } - - return c; -} diff --git a/src/graph.h b/src/graph.h deleted file mode 100644 index c7c1072..0000000 --- a/src/graph.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -** bee-dep - dependency tool for bee -** -** Copyright (C) 2009-2012 -** Matthias Ruester -** Lucas Schwass -** Marius Tolzmann -** Tobias Dreyer -** and other bee developers -** -** This file is part of bee. -** -** bee is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, see . -*/ - -#ifndef BEEDEP_GRAPH_H -#define BEEDEP_GRAPH_H - -#define NEEDS "needs" -#define PROVIDES "provides" -#define TYPE "type" - -#define PACKAGE "PACKAGE" -#define DIR "DIRECTORY" -#define UNKNOWN "VOID" - -#include "hash.h" - -#define IS_PKG(a) (!strcmp((a)->type, PACKAGE)) - -extern int graph_insert_nodes(struct hash *hash, char *filename); -extern int print_broken(struct hash *hash, char print); -extern int print_removable(struct hash *hash, char *remove); -extern int count_removable(struct hash *hash, char *remove); -extern int list_files(struct hash *hash, char *pkgname); -extern int count_files(struct hash *hash, char *pkgname); -extern int print_providers(struct hash *hash, char *name); -extern int count_providers(struct hash *hash, char *name); -extern int print_needs(struct hash *hash, char *name); -extern int print_neededby(struct hash *hash, char *name); -extern void list_packages(struct hash *hash); -extern int count_packages(struct hash *hash); -extern int remove_package(struct hash *hash, char *pkgname); -extern int print_conflicts(struct hash *hash); -extern int print_not_cached(struct hash *hash, char *filename, char print); -extern int save_cache(struct hash *hash, char *path); -extern struct hash *load_cache(char *filename); -extern unsigned long count_providedby(struct hash *hash, char *count); - -#endif diff --git a/src/hash.c b/src/hash.c deleted file mode 100644 index 8d082b0..0000000 --- a/src/hash.c +++ /dev/null @@ -1,99 +0,0 @@ -/* -** bee-dep - dependency tool for bee -** -** Copyright (C) 2009-2012 -** Matthias Ruester -** Lucas Schwass -** Marius Tolzmann -** Tobias Dreyer -** and other bee developers -** -** This file is part of bee. -** -** bee is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, see . -*/ - -#include -#include - -#include "hash.h" - -struct hash *hash_new(void) -{ - struct hash *h; - unsigned long i; - - if ((h = calloc(1, sizeof(struct hash))) == NULL) { - perror("bee-dep: hash_new: calloc"); - exit(EXIT_FAILURE); - } - - for (i = 0; i < TBLSIZE; i++) - h->tbl[i] = tree_new(); - - return h; -} - -unsigned long hash_index(char *key) -{ - register unsigned long index = 0; - char c; - - while ((c = *key++)) - index = c + (index << 6) + (index << 16) - index; - /* index = c + index * 65599 (prime number) */ - - return index % TBLSIZE; -} - -void hash_insert(struct hash *hash, struct node *n) -{ - unsigned long index = hash_index(n->name); - - tree_insert(hash->tbl[index], n); -} - -struct node *hash_safe_insert(struct hash *hash, struct node *n) -{ - unsigned long index = hash_index(n->name); - struct node *r; - - r = tree_search_node(hash->tbl[index], n->name); - - if (r) - return r; - - tree_insert(hash->tbl[index], n); - return n; -} - -struct node *hash_search(struct hash *hash, char *key) -{ - return tree_search_node(hash->tbl[hash_index(key)], key); -} - -void hash_free(struct hash *hash) -{ - int i; - - if (!hash) - return; - - for (i = 0; i < TBLSIZE; i++) { - tree_free_all_nodes(hash->tbl[i]); - tree_free(hash->tbl[i]); - } - - free(hash); -} diff --git a/src/hash.h b/src/hash.h deleted file mode 100644 index 9b0c5c4..0000000 --- a/src/hash.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -** bee-dep - dependency tool for bee -** -** Copyright (C) 2009-2012 -** Matthias Ruester -** Lucas Schwass -** Marius Tolzmann -** Tobias Dreyer -** and other bee developers -** -** This file is part of bee. -** -** bee is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, see . -*/ - -#ifndef BEEDEP_HASH_H -#define BEEDEP_HASH_H - -#include "beedep_tree.h" - -#define TBLSIZE 2000003L /* prime number */ - -struct hash { - struct tree *tbl[TBLSIZE]; -}; - -extern struct hash *hash_new(void); -extern unsigned long hash_index(char *key); -extern void hash_insert(struct hash *hash, struct node *n); -extern struct node *hash_safe_insert(struct hash *hash, struct node *n); -extern struct node *hash_search(struct hash *hash, char *key); -extern void hash_free(struct hash *hash); - -#endif diff --git a/src/node.c b/src/node.c deleted file mode 100644 index d0ec92b..0000000 --- a/src/node.c +++ /dev/null @@ -1,78 +0,0 @@ -/* -** bee-dep - dependency tool for bee -** -** Copyright (C) 2009-2012 -** Matthias Ruester -** Lucas Schwass -** Marius Tolzmann -** Tobias Dreyer -** and other bee developers -** -** This file is part of bee. -** -** bee is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, see . -*/ - -#include -#include -#include - -#include "node.h" - -struct node *node_new(char *name, char *type) -{ - struct node *n; - - if ((n = calloc(1, sizeof(struct node))) == NULL) { - perror("bee-dep: node_new: calloc"); - exit(EXIT_FAILURE); - } - - n->name = strdup(name); - n->type = strdup(type); - - n->need = tree_new(); - n->neededby = tree_new(); - n->provide = tree_new(); - n->providedby = tree_new(); - - return n; -} - -void node_set_type(struct node *n, char *type) -{ - if (n->type) - free(n->type); - - n->type = strdup(type); -} - -void node_free(struct node *n) -{ - tree_free(n->need); - tree_free(n->neededby); - tree_free(n->provide); - tree_free(n->providedby); - free(n->name); - free(n->type); - free(n); -} - -int nodecmp(struct node *a, struct node *b) -{ - if (a == b) - return 0; - - return strcmp(a->name, b->name); -} diff --git a/src/node.h b/src/node.h deleted file mode 100644 index 7f14dae..0000000 --- a/src/node.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -** bee-dep - dependency tool for bee -** -** Copyright (C) 2009-2012 -** Matthias Ruester -** Lucas Schwass -** Marius Tolzmann -** Tobias Dreyer -** and other bee developers -** -** This file is part of bee. -** -** bee is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 3 of the License, or -** (at your option) any later version. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, see . -*/ - -#ifndef BEEDEP_NODE_H -#define BEEDEP_NODE_H - -#include "beedep_tree.h" - -#define NODENAME_MAX (2 * PATH_MAX) - -struct node { - char *name, *type; - struct tree *need, - *neededby, - *provide, - *providedby; -}; - -extern struct node *node_new(char *name, char *type); -extern void node_set_type(struct node *n, char *type); -extern void node_free(struct node *n); -extern int nodecmp(struct node *a, struct node *b); - -#endif From dba3e796bf249d1976b9a4a2eb9be361eba117ce Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Wed, 25 Jul 2012 13:48:07 +0200 Subject: [PATCH 14/17] bee-install: deprecate DEPENDENCIES file --- src/bee-install.sh.in | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bee-install.sh.in b/src/bee-install.sh.in index d12a5af..ceeffb1 100644 --- a/src/bee-install.sh.in +++ b/src/bee-install.sh.in @@ -367,7 +367,7 @@ function do_install_file() { --transform="s,^BUILD$,${BEE_METADIR}/${pkg}/${beefile}," \ --transform="s,^META$,${BEE_METADIR}/${pkg}/META," \ --transform="s,^PATCHES,${BEE_METADIR}/${pkg}/PATCHES," \ - --transform="s,^DEPENDENCIES$,${BEE_METADIR}/${pkg}/DEPENDENCIES," \ + --transform="s,^DEPENDENCIES$,${BEE_METADIR}/${pkg}/DEPENDENCIES.deprecated," \ --show-transformed-names if [ ! -e "${BEE_METADIR}/${pkg}/CONTENT.INSTALL" ] ; then @@ -403,7 +403,6 @@ function do_install_file() { bee-cache update ${pkg} run_hooks post-install ${pkg} - ${BEE_LIBEXECDIR}/bee/bee.d/bee-check -d ${pkg} > ${BEE_METADIR}/${pkg}/DEPENDENCIES last="" while read p f ; do From 33b743f3e5f6be88bd9677721f42dfefe8ad8bf0 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Mon, 30 Jul 2012 12:01:26 +0200 Subject: [PATCH 15/17] bee-cache: Fix print-conflicts --- src/bee-cache.sh.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bee-cache.sh.in b/src/bee-cache.sh.in index 1a17196..aff3a95 100644 --- a/src/bee-cache.sh.in +++ b/src/bee-cache.sh.in @@ -77,7 +77,7 @@ function print_conflicts() { exit 1 fi - grep --file=<(print_conflicting_files "${pkg}" | cut -d ' ' -f8-) \ + grep --file=<(print_conflicting_files "${pkg}" | cut -d ' ' -f8- | sed -e 's,.*, &$,') \ <( tmp_merge_install_inventory_files "${TMPINSTALL[@]}" ) \ | grep -v -E "^${pkgfullname}-[^-]+-[^-]+ " } From 45d2b8a9fda8aac0fe7b1126b7a3004f87a66dec Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Mon, 30 Jul 2012 21:54:23 +0200 Subject: [PATCH 16/17] bee-cache-update: cleanup cachedir if metadir does not exist --- src/bee-cache-update.sh.in | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bee-cache-update.sh.in b/src/bee-cache-update.sh.in index 2147a4e..b0e9b59 100644 --- a/src/bee-cache-update.sh.in +++ b/src/bee-cache-update.sh.in @@ -38,13 +38,17 @@ function print_info() function create_pkgbcfile() { local PKGALLPKG=${1} - local CONTENTFILE=${BEE_METADIR}/${PKGALLPKG}/CONTENT + local PKGMETADIR=${BEE_METADIR}/${PKGALLPKG} + local CONTENTFILE=${PKGMETADIR}/CONTENT local PKGBCFILE=${CACHEDIR}/${PKGALLPKG}.bc local PKGBCRFILE=${PKGBCFILE%.bc}.bcr local tmpfile=${PKGBCFILE}.tmp.$$ - if [ ! -e "${CONTENTFILE}" ] ; then + if [ ! -d "${PKGMETADIR}" ] ; then + # cleanup cache if metadir does not exist + rm -f "${PKGBCFILE}" "${PKGBCRFILE}" + elif [ ! -e "${CONTENTFILE}" ] ; then if [ -e "${PKGBCFILE}" ] ; then print_info "moving ${PKGBCFILE} to ${PKGBCRFILE}.." mv "${PKGBCFILE}" "${PKGBCRFILE}" From 29456a889fbbb8ac50de86ef9f709a7dc0e6fb32 Mon Sep 17 00:00:00 2001 From: Marius Tolzmann Date: Mon, 30 Jul 2012 21:58:12 +0200 Subject: [PATCH 17/17] bee-remove: rerun bee-cache update after metadir was removed --- src/bee-remove.sh.in | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bee-remove.sh.in b/src/bee-remove.sh.in index 85e3046..2d0e546 100644 --- a/src/bee-remove.sh.in +++ b/src/bee-remove.sh.in @@ -129,6 +129,7 @@ do_remove() { #cleanup meta directory ${NOOP:+echo} rm -fr ${OPT_VERBOSE:+-v} ${BEE_METADIR}/${pkg} + bee-cache update ${pkg} } function run_hooks() {