No announcement yet.

Using the pre-commit hook to restrict the size of the submitted file failed

  • Filter
  • Time
  • Show
Clear All
new posts

  • Using the pre-commit hook to restrict the size of the submitted file failed

    Dear Sir:
    How do you do?

    1.Environment description:
    Visual SVN Server 2.7.13, installed on Windows Server 2007 SP2 operating system.
    Now I create a version library named test. It works fine.

    2.My needs:
    I want to limit the size of the submitted files.

    3.My operation:
    1) I copy the file named pre-commit.tmpl and save it as file named in hooks directory.
    2) Modify the file named as follows:


    SVNLOOK="C:/Program Files/VisualSVN Server/bin/svnlook"

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

    # check check
    #if [[ $files =~ "project_nuli" ]];then
    for f in $files
    # 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
    exit 0
    3) Restart the SVN service

    4.actual result:
    Then I submit a 46k file, but it succeeded. The new pre-commit hook seems not to work?

    What’s wrong?
    Fervently hope expert’s advice. Your early reply will be highly appreciated.

    Thank you so much!
    June 30, 2018

  • #2
    On Linux the name of the file must be exactly "pre-commit" (not ""). I'm not an expert on Windows, but the extension that you use must be registered with Windows as an executable. If you've got ".sh" so registered then you get to move on to the next part of debugging: checking to see what happened. I normally do this by turning on the "shell echo" capability (e.g. "set -x") and then making sure that the output is redirected to some temporary file that I can evaluate later. In general, it might look like:

    set -x
    for x in 1; do
    put your code here
    done > /path/to/some/temp/file 2>&1

    Hopefully you'll then figure out what's going wrong.


    • #3
      Thank you for your reply.
      I’ve solved this problem with the help of RD engineers. They found that the script could not run, mainly because the two commands (awk and wc) under Linux did not have corresponding commands under Windows. They rewritten the script as a Windows script and the problem was solved.


      • #4
        Now I meet another question.
        Another repository named SW.
        Checkout failed, Error: missing update-report close tag

        I execute ‘svnadmin verify E:/Repos/SW’ command on the server side, and the result is as follows:
        Verified revision 63848.
        svnadmin:E140001:zlib <uncompress>:corrupt dataecompression of svndiff data failed
        It seems that the 63849 version data has been corrupted.
        Version 63849 is as follows:
        [IMG]file:///C:%5CUsers%5Cyyc%5CAppData%5CLocal%5CTemp%5Cmsohtm lclip1%5C01%5Cclip_image002.jpg[/IMG]
        If the version's data is corrupted, what can we do to fix it or remove it completely? The svnadmin dump operation also failed.


        • #5
          Use the dump and specify a range from 0-(N-1) and (N+1)-last. Then load up a new repo. This may not work if N+1 refers to N so you may need to iterate forward.

          Any working copy referring to any is the renumberred revisions will need to be discarded and re checked out (save the work outside the WC.

          Lot of pain. Repo corruption is very rare. You should look into why. Check windows error logs, etc. Prevent the issue for happening again.


          • #6
            According to your method, the following commands are successful, and I get 3 dump files:
            svnadmin dump E:\Repos\SW -r 0:63848 > G:\SW1.dump
            svnadmin dump E:\Repos\SW -r 63850:66598 --incremental > G:\SW2.dump
            svnadmin dump E:\Repos\SW -r 66600:88013 --incremental > G:\SW3.dump
            But the execution of the following command meets an error:
            svnadmin load E:\Repos\SW1 < G:\SW1.dump

            Error information is below:
            ---Committed revision 2327 >>>

            <<< Started new transaction, based on original revision 2328
            * editing path:软件事业部/01项目区/05测试库/Project1 ...svnadmin:E200020
            :Invalid svn:mergeinfo value
            svnadmin:E200020:Unable to parse reversed revision range '96798-2321'
            svnadmin:E200020:Unable to parse reversed revision range '96798-2321'

            What’s wrong?
            Hope for your suggest. Thank you so much!


            • #7
              That’s messed up meta-data. I’ve seen an old SVN bug that could have caused the issue, but I have no idea about Visual SVN. You should contact the Visual SVN folks for help.


              • #8
                The script does not get the filenames which contain blank spaces. Anyone know how to read filenames with spaces? I tryed including " ", ' ', and \ before each space.
                For example:
                It get the size of "file.pdf", but nor for "file 1.pdf". I tryed including " " to the name, like "file .pdf", 'file .pdf', "file\ .pdf"

                Maybe SVNLOOK does not get filenames with spaces and there´s nothing to do...


                • #9
                  Handling white-space within Linux scripting takes a lot of care in proper quoting. You have not shared the script so I cannot say where things went wrong.


                  • #10
                    That´s right, sorry! I forgot it

                    This is my script:

                    #files=$($SVNLOOK changed -t $TXN $REPOS | cut -d A -f2 | cut -d U -f2 | cut -c4-
                    #files=$($SVNLOOK changed -t $TXN $REPOS | cut -d A -f2 | cut -d U -f2 | cut -c4- | sed "s/^/"/;s/$/"/")
                    #files=$($SVNLOOK changed -t $TXN $REPOS | cut -d A -f2 | cut -d U -f2 | cut -c4- | sed 's/ /\\\$/g' | tr $ " ")
                    files=$($SVNLOOK changed -t $TXN $REPOS | awk '{print $2}')
                    #echo "ARCHIVOS: $REPOS $TXN $files" >> /home/user/prueba.log
                    for f in $files
                    filesize=$($SVNLOOK cat -t $TXN $REPOS $f | wc -c)
                    #echo "PRUEBA CON FILESIZE: $filesize" >> /home/user/prueba.log
                    if [ $filesize -gt $MAX_SIZE ]; then
                    echo "File $f is too large, must be lower than 250MB">&2
                    exit 1
                    exit 0

                    I tryed different ways of get results about SVNLOOK changed (commented options). As you see, I insert " " (and also can insert ' ' just changing it on my script). I also tryed with inserting \ before each space. Im checking the results of the script into log files, and I´m introducing " " and ' ' properly, but SVNLOOK cat does not get it...

                    Anyway, using the loop will be a problem if it check spaces, because it won´t get the proper file, it will get each word after each space as a different word.
                    Last edited by davidvazqueztds; Yesterday, 10:11 AM.