diff options
author | P. J. McDermott <pjm@nac.net> | 2013-07-27 17:49:28 (EDT) |
---|---|---|
committer | P. J. McDermott <pjm@nac.net> | 2013-07-27 17:49:28 (EDT) |
commit | b8fb9e8ae492c1d19a9c084a2469dc09c026e072 (patch) | |
tree | ce85124bfe3a5a2730adaea9b521a606ef91f8a1 | |
parent | 66e122128bd7d54e59a9992613769a68c4469d5a (diff) |
lib/db.sh: Make functions more robust.
-rw-r--r-- | lib/db.sh | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -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 |