@@ -70,7 +70,7 @@ for f in "$FTP_BASE/${PKGPOOL}"/*${PKGEXT_glob}; do
printf '%s\n' "${f##*/}"
done | sort > "${WORKDIR}/pool"
# create a list of packages in our db
-find "${WORKDIR}" -maxdepth 1 -type f -name 'db-*' -exec cat {} \; | sort -u > "${WORKDIR}/db"
+cat "${WORKDIR}"/db-* 2>/dev/null | sort -u > "${WORKDIR}/db"
old_pkgs=($(comm -23 "${WORKDIR}/pool" "${WORKDIR}/db"))
if [ ${#old_pkgs[@]} -ge 1 ]; then
@@ -46,7 +46,11 @@ for repo in ${PKGREPOS[@]}; do
done
# Create a list of all available source package file names
-find "${FTP_BASE}/${SRCPOOL}" -xtype f -name "*${SRCEXT}" -printf '%f\n' | sort -u > "${WORKDIR}/available-src-pkgs"
+for f in "${FTP_BASE}"/${SRCPOOL}/*${SRCEXT}; do
+ if [[ -f $f ]]; then
+ printf '%s\n' "${f##*/}"
+ fi
+done | sort -u > "${WORKDIR}/available-src-pkgs"
# Check for all packages if we need to build a source package
for repo in ${PKGREPOS[@]}; do
@@ -117,8 +121,8 @@ for repo in ${PKGREPOS[@]}; do
done
# Cleanup old source packages
-find "${WORKDIR}" -maxdepth 1 -type f -name 'expected-src-pkgs' -exec cat {} \; | sort -u > "${WORKDIR}/expected-src-pkgs.sort"
-find "${WORKDIR}" -maxdepth 1 -type f -name 'available-src-pkgs' -exec cat {} \; | sort -u > "${WORKDIR}/available-src-pkgs.sort"
+sort -u "${WORKDIR}/expected-src-pkgs" > "${WORKDIR}/expected-src-pkgs.sort"
+sort -u "${WORKDIR}/available-src-pkgs" > "${WORKDIR}/available-src-pkgs.sort"
old_pkgs=($(comm -23 "${WORKDIR}/available-src-pkgs.sort" "${WORKDIR}/expected-src-pkgs.sort"))
if [ ${#old_pkgs[@]} -ge 1 ]; then
@@ -133,7 +137,13 @@ if [ ${#old_pkgs[@]} -ge 1 ]; then
done
fi
-old_pkgs=($(find ${SOURCE_CLEANUP_DESTDIR} -type f -name "*${SRCEXT}" -mtime +${SOURCE_CLEANUP_KEEP} -printf '%f\n'))
+old_pkgs=()
+touch -d "${SOURCE_CLEANUP_KEEP} days ago" "${WORKDIR}/cleanup_timestamp"
+for f in "${SOURCE_CLEANUP_DESTDIR}"/*${SRCEXT}; do
+ if [[ ${WORKDIR}/cleanup_timestamp -nt $f ]]; then
+ old_pkgs+=("${f##*/}")
+ fi
+done
if [ ${#old_pkgs[@]} -ge 1 ]; then
msg "Removing old source packages from the cleanup directory..."
for old_pkg in ${old_pkgs[@]}; do
From: Luke Shumaker <lukeshu@parabola.nu> This fully removes the use of find from the codebase, and leads to a micro-optimization in a couple cases. Of the 5 instances in these files: - (ftpdir-cleanup) One was unnecessary as `cat` can natively consume all files passed to it (from a glob) and no directory traversal was in use. We don't have to worry about the glob being empty, unless config:ARCHES or config:PKGREPOS is mis/non-configured and is empty. - (sourceballs) One was only being used to strip leading directory paths, and can be replaced by ${filepath##*/} in a for loop. - (sourceballs) Two were unnecessary as they were hardcoded to read a single file. - (sourceballs) One was checking the modification time of the files, and can be replaced with touch(1) and [[ -nt ]]. Although this introduces an additional temporary file, this is not such a big deal. This is based on patches by Eli Schwartz <eschwartz@archlinux.org> --- cron-jobs/ftpdir-cleanup | 2 +- cron-jobs/sourceballs | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-)