From 35e6cf8b9a26e767615b773cceafb543484b75ef Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Tue, 09 Apr 2019 22:55:23 -0400 Subject: garbage: Replace use of non-portable %s date spec --- (limited to 'src') diff --git a/src/garbage.sh b/src/garbage.sh index 58dab41..556f3db 100644 --- a/src/garbage.sh +++ b/src/garbage.sh @@ -20,6 +20,24 @@ # along with the ProteanOS Archive Manager. If not, see # . +time() +{ + # Based on code from by Rich + # Felker, with whitespace added for readability. + printf '%d' $(($(TZ=UTC0 date "+ + ( + (%Y - 1600) * 365 + + (%Y - 1600) / 4 + - (%Y - 1600) / 100 + + (%Y - 1600) / 400 + + 1%j - 1000 + - 135140 + ) * 86400 + + (1%H - 100) * 3600 + + (1%M - 100) * 60 + + (1%S - 100)"))) +} + collect_garbage() { local cur_time= @@ -30,9 +48,7 @@ collect_garbage() info_v "$(get_msg 'collecting_garbage')" - # NB: The %s format conversion specifier is not specified by POSIX, but - # it is supported by the GNU and BusyBox implementations of date. - cur_time=$("${DATE}" '+%s') + cur_time=$(time) for garbage in "${base_dir}/.db/garbage/"*; do if [ ! -f "${garbage}" ]; then @@ -64,9 +80,7 @@ mark_pool_garbage() info_v "$(get_msg 'marking_garbage_file')" "${file}" - # NB: The %s format conversion specifier is not specified by POSIX, but - # it is supported by the GNU and BusyBox implementations of date. - time=$(date '+%s') + time=$(time) time=$(($time + $conf_pool_gc_delay)) mkdir -p "${base_dir}/.db/garbage" -- cgit v0.9.1