# mounted-tmp - Clean /tmp directory
#
# Cleans up the /tmp directory when it does not exist as a temporary
# filesystem.

description	"Clean /tmp directory"

start on mounted MOUNTPOINT=/tmp
env MOUNTPOINT=/tmp

task

script
    . /etc/default/rcS

    cd "${MOUNTPOINT}"
    rm -f .X*-lock

    case "${TMPTIME}" in
        -*|infinite|infinity)
	    exit 0
	    ;;
    esac

    if [ "${TMPTIME}" = "0" -o -z "${TMPTIME}" ]
    then
	TEXPR=""
	DEXPR=""
    else
	TEXPR="-mtime +${TMPTIME} -ctime +${TMPTIME} -atime +${TMPTIME}"
	DEXPR="-mtime +${TMPTIME} -ctime +${TMPTIME}"
    fi

    EXCEPT='! -name .
            ! ( -path ./lost+found -uid 0 )
            ! ( -path ./quota.user -uid 0 )
            ! ( -path ./aquota.user -uid 0 )
            ! ( -path ./quota.group -uid 0 )
            ! ( -path ./aquota.group -uid 0 )
            ! ( -path ./.journal -uid 0 )
            ! ( -path ./.clean -uid 0 )
            ! ( -path "./...security*" -uid 0 )'

    # Remove all old files, then all empty directories
    find . -depth -xdev $TEXPR $EXCEPT ! -type d -delete
    find . -depth -xdev $DEXPR $EXCEPT -type d -empty -delete
end script
