Announcement

Collapse
No announcement yet.

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

Collapse
X
  • 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 pre-commit.sh in hooks directory.
    2) Modify the file named pre-commit.sh as follows:
    #!/bin/bash

    REPOS="$1"
    TXN="$2"

    SVNLOOK="C:/Program Files/VisualSVN Server/bin/svnlook"
    #SVNLOOK=/usr/bin/svnlook
    MAX_SIZE=512000

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

    # check check
    #if [[ $files =~ "project_nuli" ]];then
    for f in $files
    do
    # 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
    done
    #fi
    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!
    Yours
    yipianlvye
    June 30, 2018

  • #2
    On Linux the name of the file must be exactly "pre-commit" (not "pre-commit.sh"). 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.

    Comment


    • #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.

      Comment


      • #4
        Now I meet another question.
        Another repository named SW.
        URL: https://10.7.0.84:8443/svn/SW/软件事业部/01项目区/01工程项目/2017/甘肃掌上操作票专家系统项目/03.Code/3.2.Trunk/P70
        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.

        Comment


        • #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.

          Comment


          • #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!

            Comment


            • #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.

              Comment

              Working...
              X