[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1533
  • Last Modified:

Using Javacvs to interact with CVS from Java programming. Problem in remove file.


Hi All,

I am using JavaCvs (cvs client library - NetBeans ) in my java application to communicate with CVS repository. My Add, update, checkout, checkin operations seems to be working fine. But when I remove a file using RemoveCommand, the file seems to be removed. But If i upload another file with the same name into the same directory path , for some reason instead of uploading the new file its  getting back (recovering) the previous file. I don't know why its doing that. Below is the example to illustrate the problem better.

1) Added a file A.txt using AddCommand to CVS.  (Say file A.txt's content A#).

2) Viewed the file A.txt. It showed the content A#

3) Removed the file using RemoveCommand followed by CommitCommnad from CVS.

4) Modified the file A.txt (Say file A.txt's content B#) in my local dir.

5) Added the file A.txt to CVS using AddCommand.

6) Viewed the file A.txt. It showed the content A# instead of B#. Its not adding the new file instead its considering (recovering) the old file it seems.

I did the above operations from Java program using netbean's javacvs api. I don't gave any local working folder, as i am using cvs to store some documents.

I don't know why its behaving that way. Please help me resolve this issue.

Thanks in advance.

Here is my code for removeing the file from cvs.

                  c = new PServerConnection();

                  c.setUserName(username);
                  c.setEncodedPassword(passwd);
                  c.setHostName(host);
                  c.setRepository(reppath);  
                  c.verify();
                  c.open();

                  RPCvsClient client = new RPCvsClient(c, new RPAdminHandler());
                  client.getEventManager().addCVSListener(new BasicListener());
                  client.setRepositoryFullPath(directoryPath);
                  Entry ent = new Entry();
                  ent.setDirectory(false);
                  ent.setName(fileName);
                  ent.setRevision("1");
                  ByteArrayOutputStream streamForCVS = null;
                  client.setEntry(null, ent);

                  ent.setFileStream(streamForCVS);
                  client.setLocalPath(repPath()+"/"+directoryPath);
                  
                  StatusCommand command = new StatusCommand();
                  
                  GlobalOptions globalOptions = new GlobalOptions();
                  client.executeCommand(command, globalOptions);
                  StatusBuilder sb = (StatusBuilder) command.getBuilder();
                  StatusInformation si = sb.getStatusInformation();
                  if ( si != null )
                  {
                        
                        
                        
                  }
                  String repositoryVersionOfFileToBeDeleted = si.getRepositoryRevision();
                  
                  c.close();
                  
                  
                  c.open();
                  

                  client.setRepositoryFullPath(directoryPath);
                  ent = new Entry();
                  ByteArrayOutputStream stream = null;
                  ent.setDirectory(false);
                  ent.setName(fileName);      
                  ent.setRelativePath(directoryPath);      
                  ent.setFileStream(stream);
                  client.setLocalPath(reppath+"/"+directoryPath);      
                  ent.setOptions("-kb");
                  
                  client.setEntry(null, ent);      
                  
                  ent.setFileStream(stream);
                  
                  RemoveCommand removeCommand = new RemoveCommand();
                  removeCommand.setIgnoreLocallyExistingFiles(true);
                  
                  
                  globalOptions = new GlobalOptions();
                  client.executeCommand(removeCommand, globalOptions);
                  c.close();

                  
                  //      Now commit the delete
                  
                  c.open();
                  client = new RPCvsClient(c, new RPAdminHandler());
                  client.getEventManager().addCVSListener(new BasicListener());
                  client.setRepositoryFullPath(directoryPath);
                  ent = new Entry();
                  stream = new ByteArrayOutputStream();      //      faking out the file
                  ent.setDirectory(false);
                  ent.setName(fileName);
                  ent.setRelativePath(directoryPath);      
                  ent.setRevision("-"+repositoryVersionOfFileToBeDeleted);
                  ent.setFileStream(stream);
                  client.setLocalPath(reppath+"/"+directoryPath);      
                  client.setEntry(null, ent);      //      no need to set the file. hence set to null.
                  
                  CommitCommand commitCommand = new CommitCommand();
                  commitCommand.setDeleteCommit(true);
                  commitCommand.setForceCommit(true);
                  
                  commitCommand.setMessage(logMessage);
                  
                  globalOptions = new GlobalOptions();
                  client.setCommand(commitCommand);
                  client.executeCommand(commitCommand, globalOptions);
                  
                  c.close();






0
shilpa_rajith
Asked:
shilpa_rajith
  • 2
3 Solutions
 
objectsCommented:
Where do you remove the local copy?
Also could be related to the remove, remove the file for the repository, but not removing the history.
0
 
aozarovCommented:
Never used this API but based on command line CVS don't you need to call
client.executeCommand() with CommitCommand
after you called client.executeCommand(removeCommand, globalOptions) ?
0
 
shilpa_rajithAuthor Commented:

Thanks for the response.

Hi Objects,

In my application the users will upload their documents. Behind the scene I am storing the documents in CVS. So when the users upload their documents,  the application will add them to CVS. When the user wants to view them, then the app will get it from CVS and show them. Basically its kind of document management. So i don't have a local copy as such here. OR i don't know if i am missing something here.

How do i remove the file from History ??


Hi aozarov,

I am calling client.executeCommand() with CommitCommand after RemoveCommand. You can find that at the botton of my code.


Thanks in advance.

0
 
aozarovCommented:
>> I am calling client.executeCommand() with CommitCommand after RemoveCommand. You can find that at the botton of my code.
As I said, I never dealt with this api but should you do that before you close the client ( your call c.close(); right after the remove)?

>> How do i remove the file from History ??
You can do that, when using cvs client, via the admin command:
C:\java-temp>c:\cygwin\bin\cvs -H admin
Usage: cvs admin [options] files...
 -o range   Delete (outdate) specified range of revisions...
But I don't think this is your problem.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now