#!/bin/bash

# Antidater les données des blocks connus
date=`date +%Y%m%d0000`

touch -t $date $DATA_PATH/emptybot/*.{png,txt}

for BLOCK in `grep -v LAST  $DATA_PATH/block_list.txt | grep -v CACHE | awk '{print $2}'`
do
  touch -t $date $DATA_PATH/*/$BLOCK.*
done

# Conserver les blocks vides
for BLOCK in `ls $DATA_PATH/emptybot/*.png`
do
  fichier=`basename $BLOCK`
  touch -t $date $DATA_PATH/*/$fichier
done

# Effacer ce qui trop vieux
if [ "$#" -eq  "0" ]
then
  if [ -d $DATA_PATH ]
  then
	echo "CLEAN +3 $DATA_PATH" > $TMP_PATH/clean_data.log
	find $DATA_PATH -mtime +3 -type f -name *.png -exec rm -f {} \;
	find $DATA_PATH -mtime +3 -type f -name *.zip -exec rm -f {} \;

    	find $TMP_PATH -mtime +3 -type f -name *.flag -exec rm -f {} \;
  fi
else
  if [ "$1" -eq "FULL" ]
  then
    if [ -d $DATA_PATH ]
    then
        rm -f $DATA_PATH/*/*
    fi
    if [ -d $TMP_PATH ]
    then
        rm -f $TMP_PATH/*
    fi
  fi
fi

