Skip to content

Commit

Permalink
Merge pull request #9 from KhangPhucNguyen/master
Browse files Browse the repository at this point in the history
#8: garbage-out should not depend on a stamp
  • Loading branch information
phunehehe committed Jun 23, 2012
2 parents f44bd45 + 7b49973 commit f54540f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion garbage-conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ home_dir="/home/$(whoami)"

stamp="GARBAGE"
ar_dir="$home_dir/.archive"
limit_size=50
limit_size=1000

local_conf="$home_dir/.garbage-conf"
[[ -f "$local_conf" ]] && . "$local_conf"
12 changes: 5 additions & 7 deletions garbage-out
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ target="${1:-.}"
cur_size="$(du -s "$target" | awk '{print $1}')"
if [[ "$cur_size" -gt "$limit_size" ]]
then
find "$target" -type f -regextype sed -regex ".*.$stamp-[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}_[0-9]\{2\}-[0-9]\{2\}-[0-9]\{2\}" -printf "%f;%p\n" |
perl -pe 's|.*?GARBAGE-||' |
sort |
while read garbage
find $target -type f -printf '%C@ %p\0' | sort -z -k 1 -n |
while read -d $'\0' garbage
do
timestamp="$(echo "$garbage" | cut -d ';' -f 1)"
path="$(echo "$garbage" | cut -d ';' -f 2)"
[[ "$timestamp" -gt "$(date --date=yesterday +'%Y-%m-%d_%H-%M-%S')" ]] && break
timestamp="$(echo "$garbage" | cut -d ' ' -f 1)"
path="$(echo "$garbage" | cut -d ' ' -f 2-)"
[[ "$timestamp" -lt "$(date --date=yesterday +'%s')" ]] && break
rm "$path"
cur_size="$(du -s "$target" | awk '{print $1}')"
[[ "$cur_size" -lt "$limit_size" ]] && break
Expand Down

0 comments on commit f54540f

Please sign in to comment.