Avoid using glob patterns that might match enough files to give

"Arg list too long" errors.  Change the "find" command to use
"-exec ... +" instead of "-exec ... \;" to make it more efficient.
This commit is contained in:
apb 2012-10-24 21:23:55 +00:00
parent 975e296a40
commit 410421ee21

View File

@ -1,6 +1,6 @@
#!/bin/sh
#
# $NetBSD: cleartmp,v 1.10 2007/12/04 22:09:01 mjf Exp $
# $NetBSD: cleartmp,v 1.11 2012/10/24 21:23:55 apb Exp $
#
# PROVIDE: cleartmp
@ -17,11 +17,6 @@ stop_cmd=":"
cleartmp_start()
{
echo "Clearing temporary files."
#
# Prune quickly with one rm, then use find to clean up
# /tmp/[lq]* (this is not needed with mfs /tmp, but
# doesn't hurt anything).
#
if checkyesno per_user_tmp && [ -d ${per_user_tmp_dir} ]; then
tmp_dir=${per_user_tmp_dir}
else
@ -36,9 +31,20 @@ cleartmp_start()
fi
fi
(cd ${tmp_dir} && rm -rf [a-km-pr-zA-Z]* &&
#
# Delete almost everything, except lost+found, quota.user,
# and quota.group in the top level. (This is not needed
# with mfs or tmpfs /tmp, but doesn't hurt anything).
#
# The find command, with "-exec ... +" instead of "-exec
# ... \;", will pass many file or dir names to each
# invocation of "rm -rf". We avoid using any glob
# patterns because of the risk of "Arg list too long"
# errors when there are very many files.
#
(cd ${tmp_dir} &&
find -x . ! -name . ! -name lost+found ! -name quota.user \
! -name quota.group -exec rm -rf -- {} \; -type d -prune)
! -name quota.group -exec rm -rf -- {} \+ -type d -prune)
}
load_rc_config $name