Plein de trucs
This commit is contained in:
@@ -22,15 +22,13 @@ MAX_USAGE="$2"
|
||||
# Failsafe mechansim. Delete a maxium of MAX_CYCLES files, raise an error after
|
||||
# that. Prevents possible runaway script. Disable by choosing a high value.
|
||||
#
|
||||
MAX_CYCLES=10
|
||||
MAX_CYCLES=100
|
||||
|
||||
|
||||
show_header () {
|
||||
|
||||
echo
|
||||
echo DELETE OLD FILES $VERSION
|
||||
echo
|
||||
|
||||
}
|
||||
|
||||
show_header
|
||||
@@ -89,31 +87,7 @@ check_capacity () {
|
||||
fi
|
||||
}
|
||||
|
||||
check_age () {
|
||||
|
||||
FILE="$1"
|
||||
if [ "$ARCH" == "Linux" ]
|
||||
then
|
||||
FILE_DATE=`stat -c %Z "$FILE"`
|
||||
elif [ "$ARCH" == "Darwin" ]
|
||||
then
|
||||
FILE_DATE=`stat -f %Sm -t %s "$FILE"`
|
||||
else
|
||||
echo "Error: unsupported architecture."
|
||||
echo "Send a patch for the correct stat arguments for your architecture."
|
||||
fi
|
||||
|
||||
NOW=`date +%s`
|
||||
AGE=$((NOW-FILE_DATE))
|
||||
if [ "$AGE" -gt "$OLDEST_DATE" ]
|
||||
then
|
||||
export OLDEST_DATE="$AGE"
|
||||
export OLDEST_FILE="$FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
process_file () {
|
||||
|
||||
FILE="$1"
|
||||
|
||||
#
|
||||
@@ -131,26 +105,11 @@ do
|
||||
echo "Error: after $MAX_CYCLES deleted files still not enough free space."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
reset
|
||||
|
||||
FILES=`find "$MOUNT" -type f`
|
||||
|
||||
IFS=$'\n'
|
||||
for x in $FILES
|
||||
do
|
||||
check_age "$x"
|
||||
done
|
||||
FILE=`find "$MOUNT" -type f -printf '%T+ %p\n' | sort | head -n 1 | cut -d ' ' -f 2`
|
||||
|
||||
process_file "$FILE"
|
||||
|
||||
if [ -e "$OLDEST_FILE" ]
|
||||
then
|
||||
#
|
||||
# Do something with file.
|
||||
#
|
||||
process_file "$OLDEST_FILE"
|
||||
else
|
||||
echo "Error: somehow, item $OLDEST_FILE disappeared."
|
||||
fi
|
||||
((CYCLES++))
|
||||
done
|
||||
# Delete empty directories while we’re at it
|
||||
|
Reference in New Issue
Block a user