#!/system/bin/sh

count=1
success=1
#since while read line may read EOF,and the last line will have not time to exct,so use || [[ -n ${line} ]]
delete_files()
{
	count=1	
	if test -f /system/etc/delfilelist
		then
			while read line || [[ -n ${line} ]]
			do
			 echo "$line"
			 if test -f $line
				then
			 	echo "busybox rm $line"
				busybox rm  $line
                if test -f $line
					then
						echo "rm failed by $line"
						success=0
					fi
			else
				echo "busybox rm -rf $line"
				busybox rm -rf  $line
                if test -d $line
					then
						echo "rm -rf failed by $line"
						success=0
					fi
            fi
		    count=`busybox expr $count + 1`
			done < /system/etc/delfilelist
		fi

}

check_delete_result()
{
	if test $success -ne 1
	then
		echo "-------------------->Remove old files FAILED, reboot..."
		busybox reboot
	else
		echo "-------------------->rm files successfully."
	fi
}

echo "delete files..."
	delete_files
	busybox sync
	check_delete_result
	busybox sync
	busybox sync

