From 7aa5ff9ac61a24f3b8fc7c47352d64a938df316f Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sat, 27 Jul 2013 14:19:29 -0400 Subject: lib/garbage.sh: New file. --- (limited to 'lib/garbage.sh') diff --git a/lib/garbage.sh b/lib/garbage.sh new file mode 100644 index 0000000..2862ad9 --- /dev/null +++ b/lib/garbage.sh @@ -0,0 +1,65 @@ +# pro-archman +# lib/garbage.sh +# Functions for garbage collection +# +# Copyright (C) 2013 Patrick "P. J." McDermott +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +use dir + +collect_garbage() +{ + local cur_time= + local garbage= + local gar_time= + local dirs= + local file= + + # 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') + + for garbage in "${archive}/.db/garbage/"*; do + gar_time=${garbage##*/} + if [ ${cur_time} -lt ${gar_time} ]; then + break + fi + while read -r dirs file; do + rm -f "${archive}/${file}" + while [ ${dirs} -gt 0 ]; do + file="${file%/*}" + try_rmdir "${archive}/${file}" + dirs=$(($dirs - 1)) + done + done <<-EOF + ${garbage} + EOF + rm -f "${garbage}" + done +} + +mark_pool_garbage() +{ + local file="${1}" + local time= + + # 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 + $conf_pool_gc_delay)) + + mkdir -p "${archive}/.db/garbage" + printf '2 %s\n' "${file}" >>"${archive}/.db/garbage/${time}" +} -- cgit v0.9.1