improve trash-prune
This commit is contained in:
parent
6d513feff1
commit
30e80c351a
|
@ -23,19 +23,24 @@ list_trash_dirs() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
prune_dir() {
|
prune() {
|
||||||
[ -w "$1" ] || return 1
|
[ -w "$1" ] || return 1
|
||||||
for file in "$1"/info/*; do
|
for file in "$1"/files/*; do
|
||||||
[ "$(head -1 "$file")" = "[Trash Info]" ] || continue
|
file=$(basename "$file")
|
||||||
if [ "$(date -ud "$days days ago" +%s)" -gt "$(date -ud "$(grep DeletionDate "$file" | cut -d '=' -f2)" +%s)" ]; then
|
[ "$file" = '*' ] && return
|
||||||
file=$(basename "$file")
|
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!"
|
echo "$file too old!"
|
||||||
rm "$1/info/$file"
|
rm -rf "$1/info/$file"
|
||||||
rm "$1/files/$file"
|
rm -rf "$1/files/$file"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
for dir in $(list_trash_dirs); do
|
for dir in $(list_trash_dirs); do
|
||||||
prune_dir $dir || echo "Not pruning $dir" >&2
|
prune "$dir" || echo "Failed to prune $dir"
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in New Issue