好库网 好库网首页 | 我的好库
好饱的专栏

svn中限制上传文件大小的hooks

发布者:好饱
发布日期:2016/3/28 21:01:18   更新日期:2016/3/28 21:01:18
阅读次数:2921
评分:4.80
介绍:svn中利用hooks限制上传文件大小。
正文:

脚本如下:

# Check that the author of this commit has the rights to perform
# the commit on the files and directories being modified.
#commit-access-control.pl "$REPOS" "$TXN" commit-access-control.cfg || exit 1

# All checks passed, so allow the commit.
#exit 0

#!/bin/sh
REPOS="$1"
TXN="$2"
RES="OK"
MAX_SIZE=10240000
FILTER='\.(zip|rar|o|obj|tar|gz)$'
 
# Make sure that the log message contains some text.
#SVNLOOK=/usr/bin/svnlook
SVNLOOK=/opt/CollabNet_Subversion/bin/svnlook

$SVNLOOK log -t "$TXN" "$REPOS" | egrep  "[^[:space:]]+" >/dev/null || unset RES 
if [ "$RES" != "OK" ]
then
echo "You must input some comments for you commit" >&2
exit 1
fi

files=$($SVNLOOK changed -t $TXN $REPOS |awk '{print $2}')

for f in $files
do
#check file type
if echo $f|tr A-Z a-z|grep -Eq $FILTER
then
echo "File $f is not allow ($FILTER) file" >&2
exit 1
fi

#check file size
filesize=$($SVNLOOK cat -t $TXN $REPOS $f|wc -c)
if [ "$filesize" -gt "$MAX_SIZE" ]
then
echo "File $f is too large(must <=$MAX_SIZE)" >&2
exit 1
fi
done

# All checks passed, so allow the commit.
exit 0

来自:http://www.51testing.com/html/43/482843-862526.html


评论 [发表评论]
账号 密码 还没帐号呢,现在注册一个?

免责声明:好库网所展示的信息由买卖双方自行提供,其真实性、准确性和合法性由信息发布人负责。好库网不提供任何保证,并不承担任何法律责任。