improve trash-prune
This commit is contained in:
parent
6d513feff1
commit
30e80c351a
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue