From 9de220fb31da37c3f7de160e466a44c98dfa03c9 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Sun, 26 Nov 2017 20:36:17 +0100 Subject: bin/cleanup: delete error logs more exactly --- bin/cleanup | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'bin/cleanup') diff --git a/bin/cleanup b/bin/cleanup index e342873..ff4247c 100755 --- a/bin/cleanup +++ b/bin/cleanup @@ -39,29 +39,32 @@ fi # remove logs where package is not broken/locked anymore -# TODO: be a little more secure on deleting stuff (deleting "a.*" also deletes "a.b.*", -# so removing logs of "a" will also remove logs of "a.b". - { - find "${build_log_directory}/error" -maxdepth 1 -type f -printf '%f\n' | \ - sed 's|\.[^.]\+\.build-log\.gz$||' | \ - sort -u + find "${build_log_directory}/error" -maxdepth 1 -type f -printf '1 %f %f\n' | \ + sed 's|\.[^. ]\+\.build-log\.gz$||' find "${work_dir}/package-states" -maxdepth 1 \( \ -name '*.broken' -o \ -name '*.done' -o \ -name '*.locked' -o \ -name '*.testing' \ - \) -printf '%f\n' | \ - sed ' - s|\.[^.]\+$|| - p - ' + \) -printf '0 0 %f\n' | \ + sed 's|\.[^.]\+$||' } | \ - sort | \ - uniq -u | \ - cut -d' ' -f1 | \ - while read -r s; do - rm -f "${build_log_directory}/error/${s}."* + sort -k3,3 -k1,2 | \ + uniq --group=prepend -f2 | \ + while read -r num file _; do + if [ "${num}" = '0' ]; then + while read -r line; do + if [ -z "${line}" ]; then + break + fi + done + continue + fi + if [ -z "${num}${file}" ]; then + continue + fi + rm -f "${build_log_directory}/error/${file}" done # only keep 10 newest logs per failed package -- cgit v1.2.3-70-g09d2