Command line to delete all ClearCase view-private files

33,355

Solution 1

A few remarks:

  • ct lsprivate is great for dynamic views, not snapshot views
  • ct 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:

  • takes into account spaces in name
  • does not list checkouts or hijacked or eclipsed files or symlinks
  • works for both snapshot and dynamic views
  • (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".

Solution 2

Under windows DOS prompt:

for /f "delims=" %f in ('cleartool lspriv -s -do -oth ^| sort /r') do @del /f /q "%f"

Solution 3

I know that there is probably a better way but I always seem to come back to this one:

ct lspriv | grep -v checkedout | xargs rm -rf

Solution 4

I've always used:

ct lsprivate  | xargs rm

Solution 5

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.

Share:
33,355
mbyrne215
Author by

mbyrne215

Updated on September 14, 2020

Comments

  • mbyrne215
    mbyrne215 over 3 years

    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 available at this article is not quite what I want, since I'm working with a large number of files and want to delete them all without having to select each one.