Can I prevent from users to delete files from the server using TortoiseSVN and RapidSVN?

2.8k Views Asked by At

When a user is using TortoiseSVN and RapidSVN, he sees the files as they are on the server, and thus has the ability to delete them. I want to prevent that. Maybe to block the option to delete?

To clarify, I want the only way a file will be deleted from a server is that a user deletes it from his local drive, and then commits it to the server. I want to restrict the ability of any user to delete directly from the server.

2

There are 2 best solutions below

0
On

Prevent deletions by adding pre-commit hook. In windows this can be done by adding "pre-commit.bat" in "Your_SVN_repository\hooks\" with content as follows.

@echo off
::
:: Stops commits that have deleted/renamed/moved files/folders.
::

setlocal

rem Subversion sends through the path to the repository and transaction id
set REPOS=%1
set TXN=%2

rem check for an delete command in commit
svnlook changed %REPOS% -t %TXN% | findstr /i /m /b D > nul

if %errorlevel% gtr 0  exit 0 else (goto err)

:err
echo. 1>&2
echo Your commit includes files/folder deleted or renamed from repository 1>&2
echo Deletion/Rename is not allowed from repository>&2
echo Please revert the deletion/rename changes 1>&2
exit 1

2
On

Trying to prevent anything on the client side is, as always, inherently insecure. Your users could always use a different client.

So you need to manage the access rights on the server side (in the repository itself). Unfortunately, as far as I know, SVN natively supports only "read" and "write" access levels. Giving someone "write" access means that the user is not only able to modify existing files, but also to add new files and to delete existing ones.

You might be able to add this functionality via a pre-commit hook.