[31] | 1 | #!/bin/sh |
---|
| 2 | |
---|
| 3 | # PRE-UNLOCK HOOK |
---|
| 4 | # |
---|
| 5 | # The pre-unlock hook is invoked before an exclusive lock is |
---|
| 6 | # destroyed. Subversion runs this hook by invoking a program |
---|
| 7 | # (script, executable, binary, etc.) named 'pre-unlock' (for which |
---|
| 8 | # this file is a template), with the following ordered arguments: |
---|
| 9 | # |
---|
| 10 | # [1] REPOS-PATH (the path to this repository) |
---|
| 11 | # [2] PATH (the path in the repository about to be unlocked) |
---|
| 12 | # [3] USER (the user destroying the lock) |
---|
| 13 | # [4] TOKEN (the lock token to be destroyed) |
---|
| 14 | # [5] BREAK-UNLOCK (1 if the user is breaking the lock, else 0) |
---|
| 15 | # |
---|
| 16 | # The default working directory for the invocation is undefined, so |
---|
| 17 | # the program should set one explicitly if it cares. |
---|
| 18 | # |
---|
| 19 | # If the hook program exits with success, the lock is destroyed; but |
---|
| 20 | # if it exits with failure (non-zero), the unlock action is aborted |
---|
| 21 | # and STDERR is returned to the client. |
---|
| 22 | |
---|
| 23 | # On a Unix system, the normal procedure is to have 'pre-unlock' |
---|
| 24 | # invoke other programs to do the real work, though it may do the |
---|
| 25 | # work itself too. |
---|
| 26 | # |
---|
| 27 | # Note that 'pre-unlock' must be executable by the user(s) who will |
---|
| 28 | # invoke it (typically the user httpd runs as), and that user must |
---|
| 29 | # have filesystem-level permission to access the repository. |
---|
| 30 | # |
---|
| 31 | # On a Windows system, you should name the hook program |
---|
| 32 | # 'pre-unlock.bat' or 'pre-unlock.exe', |
---|
| 33 | # but the basic idea is the same. |
---|
| 34 | # |
---|
| 35 | # Here is an example hook script, for a Unix /bin/sh interpreter: |
---|
| 36 | |
---|
| 37 | REPOS="$1" |
---|
| 38 | PATH="$2" |
---|
| 39 | USER="$3" |
---|
| 40 | |
---|
| 41 | # If a lock is owned by a different person, don't allow it be broken. |
---|
| 42 | # (Maybe this script could send email to the lock owner?) |
---|
| 43 | |
---|
| 44 | SVNLOOK=/usr/local/bin/svnlook |
---|
| 45 | GREP=/bin/grep |
---|
| 46 | SED=/bin/sed |
---|
| 47 | |
---|
| 48 | LOCK_OWNER=`$SVNLOOK lock "$REPOS" "$PATH" | \ |
---|
| 49 | $GREP '^Owner: ' | $SED 's/Owner: //'` |
---|
| 50 | |
---|
| 51 | # If we get no result from svnlook, there's no lock, return success: |
---|
| 52 | if [ "$LOCK_OWNER" = "" ]; then |
---|
| 53 | exit 0 |
---|
| 54 | fi |
---|
| 55 | |
---|
| 56 | # If the person unlocking matches the lock's owner, return success: |
---|
| 57 | if [ "$LOCK_OWNER" = "$USER" ]; then |
---|
| 58 | exit 0 |
---|
| 59 | fi |
---|
| 60 | |
---|
| 61 | # Otherwise, we've got an owner mismatch, so return failure: |
---|
| 62 | echo "Error: $PATH locked by ${LOCK_OWNER}." 1>&2 |
---|
| 63 | exit 1 |
---|