17

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.

mbyrne215
  • 2,304
  • 4
  • 21
  • 16
  • Just added a more generic command line. I will review your comment/question tomorrow morning if you have any. – VonC Dec 15 '08 at 22:47

9 Answers9

22

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".

Sternerson
  • 155
  • 1
  • 7
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 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 Dec 15 '08 at 22:56
  • @Sven: the edit looks good. If you have tested it, I thank you for this enhancement. – VonC Aug 10 '11 at 16:30
  • The subsequent times that I run the command, it runs very slow to the point of timing out. Do you have any idea why it might be? – TNV Jul 24 '15 at 20:57
  • @TDN Not really: it depends on the nature of the view, and the network between the client and the view server. – VonC Jul 24 '15 at 21:10
  • @VonC The first time I ran the command, I ran it directly from the command window and it works fine. The subsequent times, I ran it from a NAnt script using and that's when the issue occurs. It seems like the process cannot exit out. – TNV Jul 27 '15 at 16:43
  • 1
    @TDN can you try and wrap that command in a `cmd /C` call? `cmd /C "..."`. Also in a script, you would need to enable delayed expansion, and use `%%i` instead of `%i`. – VonC Jul 27 '15 at 16:53
  • I ended up calling your commands from a batch file, using %%i instead of %i and it worked! Thanks @VonC!!! – TNV Jul 27 '15 at 21:48
  • And how to list only hijacked files – Akash das Feb 16 '23 at 13:22
  • @Akashdas A [simple `grep`](https://www.ibm.com/support/pages/identifying-hijacked-files-snapshot-view) should be enough. – VonC Feb 16 '23 at 14:13
6

Under windows DOS prompt:

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

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
  • 22,772
  • 3
  • 20
  • 21
3

I've always used:

ct lsprivate  | xargs rm
Paul Tomblin
  • 179,021
  • 58
  • 319
  • 408
  • 1
    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 Dec 28 '08 at 16:56
  • 1
    Ever wonder why a 4 year old post would suddenly attract a downvote with no explanation of why it's being downvoted? I do. – Paul Tomblin Jun 08 '12 at 15:12
  • It does puzzle me on those occasions, fortunately fairly rare, when it happens. It irritates too, but I decided there was nothing worthwhile that I can do about unexplained drive-by down-votes unless there is someone on a down-voting spree targeting me (which hasn't happened yet, either). – Jonathan Leffler Jun 08 '12 at 15:22
  • I get below error "csh: The argument list was too long. (The C shell has no limit, but the Windows NT kernel does impose a limit of 32,282 characters.)" – user875036 Oct 18 '12 at 11:47
2

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
  • 730,956
  • 141
  • 904
  • 1,278
1

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
  • 2,304
  • 4
  • 21
  • 16
1

In pure windows you can do this:

for /F "delims=" %i IN ('ct lsprivate') DO rm -rf "%i"
Sam Mackrill
  • 4,004
  • 8
  • 35
  • 55
1
  1. From the CLI To list the view private files executed the below command

    for /F "usebackq delims=" %i in (`cleartool lspriv -s ^| find /V "Rule:" ^| find /V "hijacked" ^| find /V "eclipsed"`) do @echo "%i"
    
  2. From the CLI executed below comand to delete the view private files

    for /F "usebackq delims=" %i in (`cleartool lspriv -s ^| find /V "Rule:" ^| find /V "hijacked" ^| find /V "eclipsed"`) do del /F "%i"
    
  3. Synchronizing the view with the project:
    From the project explorer select the stream properties, go to the view tab, select the view properties then click the "synchronize with the project"

sjngm
  • 12,423
  • 14
  • 84
  • 114
Vas
  • 11
  • 1
0

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 Dec 15 '08 at 22:34