summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-04-09 22:55:23 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-04-09 22:55:23 (EDT)
commit35e6cf8b9a26e767615b773cceafb543484b75ef (patch)
tree03158fabd8aef0e098c702cb9d3cd248d115fad2 /src
parent5f61f497e98fdf12591bfe19461ed5e27706cd01 (diff)
garbage: Replace use of non-portable %s date spec
Diffstat (limited to 'src')
-rw-r--r--src/garbage.sh26
1 files changed, 20 insertions, 6 deletions
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
# <http://www.gnu.org/licenses/>.
+time()
+{
+ # Based on code from <https://www.etalabs.net/sh_tricks.html> 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"