]> git.ipfire.org Git - people/stevee/pakfire.git/blob - tools/functions-directories
Cleanup database and add indexes.
[people/stevee/pakfire.git] / tools / functions-directories
1 #!/bin/bash
2
3 function dir_is_empty() {
4 [ "$(ls -A $@ 2>/dev/null | wc -l)" = "0" ]
5 }
6
7 function directory_remove_orphans() {
8 if [ "${QUALITY_AGENT_NO_DIRECTORY_PRUNE}" = "yes" ]; then
9 return
10 fi
11
12 local basedir=${1}
13
14 log DEBUG "Removing orphans in ${basedir}"
15
16 local dir
17 local dir_pattern
18 for dir_pattern in ${ORPHAN_CANDIDATES}; do
19 dir=$(echo ${basedir}/${dir_pattern})
20
21 for dir in ${dir}; do
22 echo "DIR ${dir}" >&2
23 [ -d "${dir}" ] || continue
24
25 if dir_is_empty ${dir}; then
26 log DEBUG " Found orphaned directory: ${dir}"
27 rm -rf ${dir}
28 fi
29 done
30 done
31 }
32