diff options
author | P. J. McDermott <pjm@nac.net> | 2013-07-27 14:19:29 (EDT) |
---|---|---|
committer | P. J. McDermott <pjm@nac.net> | 2013-07-27 14:19:29 (EDT) |
commit | 7aa5ff9ac61a24f3b8fc7c47352d64a938df316f (patch) | |
tree | 3ccb75aeece3167a16d66ce3ed7a0706df409aa1 | |
parent | 36e4873cc40db076e16f66e5e88cb812dd1b5b20 (diff) |
lib/garbage.sh: New file.
-rw-r--r-- | lib/garbage.sh | 65 | ||||
-rw-r--r-- | lib/local.mk | 1 |
2 files changed, 66 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>. + +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}" +} diff --git a/lib/local.mk b/lib/local.mk index 6c8b59e..10e1afa 100644 --- a/lib/local.mk +++ b/lib/local.mk @@ -8,4 +8,5 @@ pkglib_srcs = \ lib/dir.sh \ lib/db.sh \ lib/index.sh \ + lib/garbage.sh \ lib/cmd.sh |