首页 > 代码库 > Svn 钩子 限制上传文件的大小及类型
Svn 钩子 限制上传文件的大小及类型
[root@svnserver hooks]# cat pre-commit #!/bin/sh # repot && transaction arguments REPOS="$1" TXN="$2" # svnlook command SVNLOOK=/usr/bin/svnlook # file filter: we only allow commit .c && .h files FILTER=‘\.(c|h)$‘ # max file size in bytes after commit. MAX_SIZE=5242880 # max change per one commit MAX_CHANGE_LINES=50 files=$($SVNLOOK changed -t $TXN $REPOS | awk ‘{print $2}‘) # check for f in $files do # check file type if echo $f|grep -Eq $FILTER;then # valid file : else echo "File $f is not a .h or .c 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 # check change lines changelines=$($SVNLOOK diff -t $TXN $REPOS $f | grep -E ‘^(\+|-)‘ | wc -l) if [ $changelines -gt $MAX_CHANGE_LINES ] ; then echo "File $f changes too much ($changelines lines, must <= $MAX_CHANGE_LINES)" >&2 exit 1 fi done exit 0
本文出自 “randolph” 博客,转载请与作者联系!
Svn 钩子 限制上传文件的大小及类型
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。