1
0
Fork 0

improve trash-prune

This commit is contained in:
Luca Bilke 2023-12-11 16:40:59 +01:00
parent 6d513feff1
commit 30e80c351a
1 changed files with 13 additions and 8 deletions

View File

@ -23,19 +23,24 @@ list_trash_dirs() {
done
}
prune_dir() {
prune() {
[ -w "$1" ] || return 1
for file in "$1"/info/*; do
[ "$(head -1 "$file")" = "[Trash Info]" ] || continue
if [ "$(date -ud "$days days ago" +%s)" -gt "$(date -ud "$(grep DeletionDate "$file" | cut -d '=' -f2)" +%s)" ]; then
file=$(basename "$file")
for file in "$1"/files/*; do
file=$(basename "$file")
[ "$file" = '*' ] && return
if [ ! -r "$1/info/$file" ] || [ ! "$(head -1 "$1/info/$file")" = "[Trash Info]" ]; then
[ -w "$1/info/$file" ] && rm -rf "$1/info/$file"
rm -rf "$1/files/$file"
continue
fi
if [ "$(date -ud "$days days ago" +%s)" -gt "$(date -ud "$(grep DeletionDate "$1/info/$file" | cut -d '=' -f2)" +%s)" ]; then
echo "$file too old!"
rm "$1/info/$file"
rm "$1/files/$file"
rm -rf "$1/info/$file"
rm -rf "$1/files/$file"
fi
done
}
for dir in $(list_trash_dirs); do
prune_dir $dir || echo "Not pruning $dir" >&2
prune "$dir" || echo "Failed to prune $dir"
done