Improve loops

Eliminating for loops and using pipe for input the while loops shall improve
the memory footprint and performance
This commit is contained in:
Thomas Gebert 2025-01-03 10:09:10 +01:00
parent 5a55e84e33
commit 55c66a333a

View File

@ -50,7 +50,7 @@ get_xattr_of_file() {
} }
find_files_with_atime() { find_files_with_atime() {
while read -r FILE; do find "${DIRECTORY}" -type f | while read -r FILE; do
ATIME_FILE=$(get_atime_of_file "${FILE}") ATIME_FILE=$(get_atime_of_file "${FILE}")
if [ "${ATIME_FILE}" == "" ]; then if [ "${ATIME_FILE}" == "" ]; then
continue continue
@ -58,12 +58,12 @@ find_files_with_atime() {
if [ ${ATIME_FILE} -ge ${ATIME_SEARCH} ]; then if [ ${ATIME_FILE} -ge ${ATIME_SEARCH} ]; then
echo "${FILE}" echo "${FILE}"
fi fi
done <<< $(find "${DIRECTORY}" -type f) done
} }
find_files_with_retention() { find_files_with_retention() {
while read -r FILE; do find "${DIRECTORY}" -type f | while read -r FILE; do
RETENTION_FILE=$(get_xattr_of_file "${FILE}" "trusted.worm.attr" | grep -o '[0-9]\+$') RETENTION_FILE=$(get_xattr_of_file "${FILE}" "trusted.worm.attr" | grep -o '[0-9]\+$')
if [ "${RETENTION_FILE}" == "" ]; then if [ "${RETENTION_FILE}" == "" ]; then
continue continue
@ -72,12 +72,12 @@ find_files_with_retention() {
if [ ${RETENTION_FILE} -eq ${RETENTION_SEARCH} ]; then if [ ${RETENTION_FILE} -eq ${RETENTION_SEARCH} ]; then
echo "${FILE}" echo "${FILE}"
fi fi
done <<< $(find "${DIRECTORY}" -type f) done
} }
set_atime() { set_atime() {
for FILE in $(find_files_with_retention "${DIRECTORY}" "${RETENTION_SEARCH}"); do find_files_with_retention "${DIRECTORY}" "${RETENTION_SEARCH}" | while read -r FILE; do
if [ -f "${FILE}" ]; then if [ -f "${FILE}" ]; then
ARCHIVE_TIME=$(get_xattr_of_file "${FILE}" "trusted.archive_time") ARCHIVE_TIME=$(get_xattr_of_file "${FILE}" "trusted.archive_time")
NEW_ATIME=$((ARCHIVE_TIME+NEW_RETENTION)) NEW_ATIME=$((ARCHIVE_TIME+NEW_RETENTION))
@ -89,7 +89,7 @@ set_atime() {
show_atime_retention() { show_atime_retention() {
while read -r FILE; do find "${DIRECTORY}" -type f | while read -r FILE; do
ATIME=$(get_atime_of_file "${FILE}") ATIME=$(get_atime_of_file "${FILE}")
if [ "${ATIME}" == "" ]; then if [ "${ATIME}" == "" ]; then
continue continue
@ -98,7 +98,7 @@ show_atime_retention() {
echo "${FILE}" echo "${FILE}"
echo " atime: $(date --date=@${ATIME}) || ${ATIME}" echo " atime: $(date --date=@${ATIME}) || ${ATIME}"
echo " trusted.worm.attr: ${TRUSTED_WORM_ATTR}" echo " trusted.worm.attr: ${TRUSTED_WORM_ATTR}"
done <<< $(find "${DIRECTORY}" -type f) done
} }
################################################################################ ################################################################################