From e7054c4e7d99ff3a94327eda7c8f8f5f5d8e24e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kov=C3=A1cs=20Zolt=C3=A1n?= Date: Sun, 21 Sep 2025 11:20:56 +0200 Subject: [PATCH] rotate_folder now correctly handles "zero elements to keep" directives. --- .metadata | Bin 15851 -> 15851 bytes .templates/bin/rotate_folder | 34 ++++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/.metadata b/.metadata index 1b8c701465f3ba6e14cd20f264fd6be83e6ddd98..ef06ac0bbea516442745ea3fd825cdb4973df9d9 100644 GIT binary patch delta 77 zcmaD|{knQXGaFBG?bZwiAh_QVZ#j9QnCRs52CAD+vTai55jlJwEaN)qhT3FBP0`8w f`K32+*E`3{!rycvWAc6x(a8mdT$@+eI5PqOi>Dlz delta 68 zcmaD|{knQXGaJv{@~s&RKu{BWMPu?rG11BA4OBOuWZR@ZnO9zLvYMvA # Kovács Zoltán # License: GNU/GPL v3+ (https://www.gnu.org/licenses/gpl-3.0.en.html) +# 2025-09-15 v1.3 +# fix: now correctly handles "zero elements to keep" directives. # 2025-08-12 v1.2 # fix: now correctly handles configuration file pathnames containing spaces. # 2025-03-06 v1.1 @@ -304,13 +306,15 @@ function rotate_class { # This week concluded. done # The weekly schedule concluded. - # If we didn't save any file within this schedule we'll retain this file. - if [[ -z "$last_retained" && $pointer -lt ${#class_files[@]} ]]; then - last_retained="$file_mtime" - [[ -z "$DOIT" ]] && echo "WR ${class_files[$pointer]}" - (( pointer++ )) - [[ $pointer -lt ${#class_files[@]} ]] \ - && file_mtime=$("$STAT" -c %Y "$BACKUP_FOLDER/${class_files[$pointer]}") + if [[ "$RETAIN_WEEKS" -ge 1 ]]; then + # If we didn't save any file within this schedule we'll retain this file. + if [[ -z "$last_retained" && $pointer -lt ${#class_files[@]} ]]; then + last_retained="$file_mtime" + [[ -z "$DOIT" ]] && echo "WR ${class_files[$pointer]}" + (( pointer++ )) + [[ $pointer -lt ${#class_files[@]} ]] \ + && file_mtime=$("$STAT" -c %Y "$BACKUP_FOLDER/${class_files[$pointer]}") + fi fi # The monthly schedule. @@ -348,13 +352,15 @@ function rotate_class { # This month concluded. done # The monthly schedule concluded. - # If we didn't save any file within this schedule we'll retain this file. - if [[ -z "$last_retained" && $pointer -lt ${#class_files[@]} ]]; then - last_retained="$file_mtime" - [[ -z "$DOIT" ]] && echo "MR ${class_files[$pointer]}" - (( pointer++ )) - [[ $pointer -lt ${#class_files[@]} ]] \ - && file_mtime=$("$STAT" -c %Y "$BACKUP_FOLDER/${class_files[$pointer]}") + if [[ "$RETAIN_MONTHS" -ge 1 ]]; then + # If we didn't save any file within this schedule we'll retain this file. + if [[ -z "$last_retained" && $pointer -lt ${#class_files[@]} ]]; then + last_retained="$file_mtime" + [[ -z "$DOIT" ]] && echo "MR ${class_files[$pointer]}" + (( pointer++ )) + [[ $pointer -lt ${#class_files[@]} ]] \ + && file_mtime=$("$STAT" -c %Y "$BACKUP_FOLDER/${class_files[$pointer]}") + fi fi # All the schedules have been processed.