●SVN用shell脚本限制上传文件的大小及类型●解决方案 ●●SVN用shell脚本限制上传文件的大小及类型●● 请问怎么用shell脚本来限制上传文件的大小及类型?
SVN在上传过程中会触发pre-commit脚本 急! ------解决方案-------------------- 楼主的需求和我的一个需求有点类似,我想控制每次commit进去的代码行数。于是吃完饭,写了这个hook,楼主看看,应该基本上够需求了。 为什么CSDN插入代码没有Shell呢?
#!/bin/sh # repot && transaction arguments REPOS="$1" TXN="$2" # svnlook command SVNLOOK=/usr/local/bin/svnlook # file filter: we only allow commit .c && .h files. FILTER='\.(c|h)$' # max file size in bytes after commit. MAX_SIZE=102400 # 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" >> /dev/stderr 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)" >> /dev/stderr 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)" >> /dev/stderr exit 1 fi done exit 0 |
|
来自: bananarlily > 《IT》