I\'m looking for a command line to remove all view-private files and directories from a ClearCase view on Windows. I have Cygwin available as well.
The script avail
A few remarks:
ct lsprivate
is great for dynamic views, not snapshot viewsct ls -rec -view_only
as well as ct lsprivate
also list your checked-out files... I am not sure you want to delete those...For listing private files (only private ones, not hijacked ones you may want to keep), you need to have a command that:
(bonus) does not depend on external shell commands
for /F "usebackq delims=" %i in (`cleartool ls -r ^| find /V "Rule:" ^| find /V "hijacked" ^| find /V "eclipsed" ^| find /V "-->"`) do @echo "%i"
That lists all your private files (skipping the hijacked/eclipsed/checked-out or non-private ones as well as symlinks) in a pure Windows way (no external shell dependency needed).
Replace @echo "%i"
by del /F "%i"
and they are gone.
Note the double quotes around %i, in order to display/remove properly files with spaces in their name.
Also note the absence of the cleartool parameter -nxn, as symlinks would otherwise be indistinguishable and view-private files are not being decorated anyway.
In order to also get rid of private directories, first run the command with rmdir /S /Q "%i"
and then with del /F "%i"
.
what about use the of cygpath command instead of sed?
you can found more info about cygpath.exe here:
link text
a way to link cygpath.exe with other programs is to use xargs.
example: processA | xargs cygpath -u > my-path-in-unix-format.txt
I ended up using this command in Cygwin:
cleartool ls -recurse -view_only | sed -e 's:\\:/:g' | xargs rm -r
The sed is necessary to change the Windows-style paths output by cleartool into Unix-style paths. There's probably a more efficient command out there. This one throws a lot of errors, because it deletes the directory, and then any previously found view-private files underneath that directory will be not found by rm. But you get the right result in the end.
EDIT: VonC points out that this only works with dynamic ClearCase views
On Unix (dynamic views), one very effective technique for removing view private files is to drop the view. Preserve the cspec first. Also make sure there are no checkouts in the view. Then remove it and recreate a new one (same name, same cspec, same storage, but no private files until you create them).
# With the view to be cleaned as your current view...
ct pwv -s > /tmp/viewname
viewname=$(</tmp/viewname)
ct catcs > /tmp/$viewname.cs
ct lsview -cvi | awk '{print $3;}' > /tmp/$viewname.vws
# The next line is the first dangerous line!
# It cancels all outstanding checkouts and removes the modified files
ct lsco -cvi -s -avo 2>/dev/null | xargs ct unco -rm # Or: xargs ct ci -nc
exit # Terminate the session in the view
viewname=$(</tmp/viewname)
rm /tmp/viewname
# The next line is the second dangerous line
ct rmview -tag $viewname
ct mkview -tag $viewname $(</tmp/$viewname.vws)
ct setcs -tag $viewname /tmp/$viewname.cs
rm /tmp/$viewname.cs
All view private files are gone - and you've minimized your disk usage.
If you're lucky enough to only work with a single VOB, you can omit the '-avo
' (all VOBs) option. The '2>/dev/null
' redirection loses errors from inaccessible VOBs - I have more than 100 visible but inaccessible VOBs in my environment, apart from the dozen or so accessible ones that I really use.
Note that if you were packaging this as a 'rebuild.view
' script, you'd take the viewname as an argument (working from outside the view - it would not be the current view), and you could then do the cleanup inside the view, use a different 'lsview' option to get the details needed, and generally get away from the temporary storage in /tmp (though you'll need to cache the cspec somewhere).
One other point to note - you would want to ensure that you've done a manual cleanup before letting the automatic loose. There should be no checkouts, for example. Alternatively, write the script to refuse to drop the view if there are any checkouts.
Under windows DOS prompt:
for /f "delims=" %f in ('cleartool lspriv -s -do -oth ^| sort /r') do @del /f /q "%f"
In pure windows you can do this:
for /F "delims=" %i IN ('ct lsprivate') DO rm -rf "%i"