views:

5954

answers:

6

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.

+1  A: 

I've always used:

ct lsprivate  | xargs rm
Paul Tomblin
Me too, with the caveat that I run 'ct lsco -cvi -s -avo' to find any checked-out files first and I cancel those checkouts before removing the private files.
Jonathan Leffler
A: 

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

mbyrne215
A: 

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 couldn't figure out the right way to string that together with the other commands. If you can come up with it, please edit your answer to show that; hopefully it will help someone else.
mbyrne215
+7  A: 

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
  • works for both snapshot and dynamic views
  • (bonus) does not depend on external shell commands

    for /F "usebackq delims=" %i in (`cleartool ls -r -nxn ^| find /V "Rule:" ^| find /V "hijacked" ^| find /V "eclipsed"`) do @echo "%i"

That lists all your private files (skipping the hijacked/eclipsed/checked-out or non-private ones) 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.

You may need to run it a second time, with rmdir instead of del, in order to get rid of private directories.

VonC
You're right, my way was very specific to my purpose at the moment. I didn't have any checkouts, and I definitely wanted files and directories in one shot. So, a little bit of a trade-off, but generic probably beats running it twice for most uses.
mbyrne215
+1  A: 

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
Mr. Muskrat
+1  A: 

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.

Jonathan Leffler