From 354acca1bfaf06ec7c0d44182ef3869d36a7fb3a Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Sun, 28 May 2023 15:21:56 -0400 Subject: switch to null delimiter based parsing for maximum compatibility; eliminates comments --- src/retain-snapshots | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/retain-snapshots b/src/retain-snapshots index 1f9ee73..9b7fee3 100755 --- a/src/retain-snapshots +++ b/src/retain-snapshots @@ -5,9 +5,9 @@ retain_years= # TODO: read retain_years from .propagation use_clock_time= # Delete according to clock time (WARNING: eventually deletes all data) -# Never edit this regex. +# Never edit this glob. # Generated via: date -Ins | sed 's/[0-9]/[0-9]/g' -datetime_regexp='[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9],[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9]:[0-9][0-9]' +datetime_glob='[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9],[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9]:[0-9][0-9]' snapshot_prefix='.snapshot~' @@ -25,11 +25,8 @@ main() *) exit 1 ;; esac - # Using `cd "$1"` and `find .` allows the path to contain - # newlines, while simple `find "$1"` would break the script. - # NB: Our snapshot name itself never contains whitespace. cd "$1" || exit - find . -maxdepth 1 -type d -name "$snapshot_prefix""$datetime_regexp" | sort -rn | retain + find . -maxdepth 1 -type d -name "$snapshot_prefix""$datetime_glob" -print0 | sort -zrn | retain } is_readonly_subvolume() @@ -68,7 +65,7 @@ retain() then now=$(date +%s) fi - while read line + while read -d '' line do is_readonly_subvolume "$line" || break dateline=${line#*/"$snapshot_prefix"} -- cgit v1.2.3