diff options
author | Andrew Cady <d@jerkface.net> | 2023-05-28 15:21:56 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2023-05-31 18:01:53 -0400 |
commit | 354acca1bfaf06ec7c0d44182ef3869d36a7fb3a (patch) | |
tree | 0124bae8b6e89b1c4dc90982f25c121c5f5d1df6 | |
parent | 6bf15b49a77237a549be136b5aa29daaa69cc2f4 (diff) |
switch to null delimiter based parsing for maximum compatibility; eliminates comments
-rwxr-xr-x | src/retain-snapshots | 11 |
1 files 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 | |||
5 | use_clock_time= # Delete according to clock time (WARNING: eventually deletes all data) | 5 | use_clock_time= # Delete according to clock time (WARNING: eventually deletes all data) |
6 | 6 | ||
7 | 7 | ||
8 | # Never edit this regex. | 8 | # Never edit this glob. |
9 | # Generated via: date -Ins | sed 's/[0-9]/[0-9]/g' | 9 | # Generated via: date -Ins | sed 's/[0-9]/[0-9]/g' |
10 | 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]' | 10 | 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]' |
11 | 11 | ||
12 | snapshot_prefix='.snapshot~' | 12 | snapshot_prefix='.snapshot~' |
13 | 13 | ||
@@ -25,11 +25,8 @@ main() | |||
25 | *) exit 1 ;; | 25 | *) exit 1 ;; |
26 | esac | 26 | esac |
27 | 27 | ||
28 | # Using `cd "$1"` and `find .` allows the path to contain | ||
29 | # newlines, while simple `find "$1"` would break the script. | ||
30 | # NB: Our snapshot name itself never contains whitespace. | ||
31 | cd "$1" || exit | 28 | cd "$1" || exit |
32 | find . -maxdepth 1 -type d -name "$snapshot_prefix""$datetime_regexp" | sort -rn | retain | 29 | find . -maxdepth 1 -type d -name "$snapshot_prefix""$datetime_glob" -print0 | sort -zrn | retain |
33 | } | 30 | } |
34 | 31 | ||
35 | is_readonly_subvolume() | 32 | is_readonly_subvolume() |
@@ -68,7 +65,7 @@ retain() | |||
68 | then | 65 | then |
69 | now=$(date +%s) | 66 | now=$(date +%s) |
70 | fi | 67 | fi |
71 | while read line | 68 | while read -d '' line |
72 | do | 69 | do |
73 | is_readonly_subvolume "$line" || break | 70 | is_readonly_subvolume "$line" || break |
74 | dateline=${line#*/"$snapshot_prefix"} | 71 | dateline=${line#*/"$snapshot_prefix"} |