From b8fb9e8ae492c1d19a9c084a2469dc09c026e072 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sat, 27 Jul 2013 17:49:28 -0400 Subject: lib/db.sh: Make functions more robust. --- diff --git a/lib/db.sh b/lib/db.sh index 7533126..27a1ae8 100644 --- a/lib/db.sh +++ b/lib/db.sh @@ -139,6 +139,9 @@ db_get_archplats() dir="${opt_base_dir}/feeds/${chan}/${dist}/.db" dir="${dir}/$(hash_name "${source}")/${source}" for dir in "${dir}/"*_*/; do + if [ ! -d "${dir}" ]; then + continue + fi dir="${dir%/}" dir="${dir##*/}" printf '%s %s\n' "${dir%%_*}" "${dir#*_}" @@ -216,8 +219,13 @@ db_inc_references() dir="${opt_base_dir}/pool/$(hash_name "${source}")/${source}/.db" dir="${dir}/${binver}_${arch}_${plat}" - refs="$(cat "${dir}/references")" - refs=$(($refs + 1)) + if [ -f "${dir}/references" ]; then + refs="$(cat "${dir}/references")" + refs=$(($refs + 1)) + else + refs=1 + mkdir -p "${dir}" + fi printf '%d\n' "${refs}" >"${dir}/references" printf '%d\n' "${refs}" @@ -235,8 +243,12 @@ db_dec_references() dir="${opt_base_dir}/pool/$(hash_name "${source}")/${source}/.db" dir="${dir}/${binver}_${arch}_${plat}" - refs="$(cat "${dir}/references")" - refs=$(($refs - 1)) + if [ -f "${dir}/references" ]; then + refs="$(cat "${dir}/references")" + refs=$(($refs - 1)) + else + refs=0 + fi if [ ${refs} -eq 0 ]; then rm -f "${dir}/references" else -- cgit v0.9.1