That the real pain point with the lock mechanism: if you unlock (which you need to do if you want to perform a cleartool protect -chown), you are loosing the list of users you excluded from a given lock.
A starting point to script that kind of operation is this IBM document "How to list locked VOBs":
Windows: for /F %v in ('cleartool lsvob -short') do cleartool lslock vob:%vUnix: for i incleartool lsvob -short -host ; do cleartool lslock vob:$i; doneLeave me as a comment the Os on which you will perform those operations, and I will complete this answer with a script.
For instance, a quick DOS script chown_locked.cmd would be:
@ECHO offSETLOCAL ENABLEDELAYEDEXPANSIONdoskey ct=cleartool $*set ucmObject=%1 & REM #project:aProject@\aPVob or stream:aStream@\aPVobset anOldUser=%2 & REM #previous owner of the streamsset anOldUser=%anOldUser:~0,-1%set lsstreamCmd=ct lsstream -in %ucmObject% -fmt "%%Xn %%[locked]p %%u\n"for /F "tokens=1-3" %%a in ( ' %lsstreamCmd% ') do ( rem echo '%%a' rem echo '%%b' rem echo '%%c' if "%%b" EQU "locked" ( if "%%c" EQU "%anOldUser%" ( call:chown %%a %USERNAME% ) else ( echo.ignore locked %%a because not owned by %anOldUser%, but by '%%c' ) ) else ( echo.ignore unlocked %%a ))goto end:chown ucmObject -- chown on a ucm object:: if lock, will restore the nusers lock exception list:: -- streamName [in] name of the UCM object:: -- newOwner [in] name of new owner SETLOCAL ENABLEDELAYEDEXPANSIONset ucmObject=%~1set newOwner=%~2set cmd=ct lslock %ucmObject%for /F "tokens=4*" %%a in ( ' %cmd% ^| find "Locked except for users:" ') do set lslock=%%bset lslock=%lslock:~0,-1%rem echo lslock '%lslock%'if "%lslock%" NEQ "~0,-1" goto lslockecho.chown locked '%ucmObject%%' for '%newOwner%'ct protect -chown %newOwner%2 %ucmObject% & goto endchown:lslockset lslock2=%lslock: =,%rem echo lslock2 '%lslock2%'echo.chown locked '%ucmObject%' for '%newOwner%' while retaining '%lslock2%'ct unlock %ucmObject%ct protect -chown %newOwner% %ucmObject%ct lock -nusers %lslock2% %ucmObject%:endchown( ENDLOCAL)EXIT /b:end( ENDLOCAL)Call it on a project, or a stream (with sub-streams) within a project, like so:
chown_locked.cmd project:myProject@\aPVobName aPreviousOwnerchown_locked.cmd stream:aStream@\aPVobName aPreviousOwnerIt will protect any sub-stream to the current user if said sub-streams are:
lockedlocked with the right owner (the previous one who has left)If a sub-stream is locked with a -nusers list of excluded users (excluded from the lock), this list is saved before the unlock, and restore when locking the stream again.
Of course, it will only work if the current user is ClearCase administrator (i.e. is in the same group than the ClearCase_albd user): only this king of user can do a chown on a ClearCase object.
No comments:
Post a Comment