41 lines
864 B
Bash
Executable file
41 lines
864 B
Bash
Executable file
#!/usr/bin/bash
|
|
#
|
|
# Remove expired pastes.
|
|
|
|
shopt -s lastpipe
|
|
shopt -s nullglob
|
|
|
|
DEBUG=${DEBUG:-0}
|
|
NOW=${EPOCHSECONDS}
|
|
TARGET=$1
|
|
declare -i TOTAL=0
|
|
|
|
trap '(( DEBUG > 0 )) && echo $TOTAL;' EXIT
|
|
|
|
# delete empty files
|
|
find "${TARGET}/" -mindepth 1 -maxdepth 1 -type f -empty -delete
|
|
|
|
# test for xattr support
|
|
touch "${TARGET}/__xattr__"
|
|
if ! setfattr -n user.sp.sunset -v 1234 "${TARGET}/__xattr__"; then
|
|
echo 'No xattr support.' >&2
|
|
rm -f -- "${TARGET}/__xattr__";
|
|
exit 2
|
|
fi
|
|
|
|
# substract __xattr__
|
|
(( --TOTAL ))
|
|
|
|
# fairly inefficient but sufficient for now
|
|
for file in "${TARGET}/"*; do
|
|
if epoch="$(getfattr -n user.sp.sunset --only-values "${file}" 2>/dev/null | tr -d '\0')"; then
|
|
if date -d "@${epoch}" &>/dev/null; then
|
|
if (( epoch < NOW )); then
|
|
rm -f -- "${file}" 1>&2
|
|
(( ++TOTAL ))
|
|
fi
|
|
fi
|
|
fi
|
|
done
|
|
|
|
# vi:set ft=bash ts=4 sw=4 noet noai:
|