nucm-logo

NUCM-2.0 Documentation
Interface: Collection: nc_replaceversion


[Versioning | Collection | Query]

[nc_add | nc_remove | nc_rename | nc_replaceversion | nc_copy]

Signature

int  nc_replaceversion(const char*  target,
                       const char*  t_cwd,
                       const char*  version,
		       int  forced)

Functionality

Replaces the current version of the artifact determined by the parameters target and t_cwd in the collection in the workspace with the version determined by the parameter version. If the artifact has been opened, it is also replaced in the workspace. If the artifact is a collection, all members of the collection are closed. If the artifact is a collection and one or more of its members are initiated, the replacement does not succeed unless the replacement is forced. A replacement is forced if the value of the parameter forced is 1, a replacement is not forced if the value of the parameter forced is 0. The collection in which the version of the artifact is replaced has to be initiated.

Return Values

0: everything went ok
-1: an error occurred

NdbErrno Codes

NdbOk :everything went ok
NdbUnknown:the path does not represent a NUCM artifact
NdbLonely : no collection present in the workspace in which the artifact can be replaced
NdbNotInit: the collection in which to replace the artifact is not initiated
NdbInitiated: the artifact is a collection and one or more of its members is initiated and the remove is not forced
NdbConnect :the server is down or not reachable
NdbComm :a communication error occurred
NdbProtocol:a failure occurred in the NUCM protocol
NdbNotAvail:service is not available

Example

Assuming a repository is filled with projects, and in particular contains a project "my_project" that contains the artifacts ".login" and ".cshrc". Furthermore, a workspace has been created earlier in which "my_project" and its artifacts have been opened:
   /home/bigtime/andre/workspace/my_project/.login
					    .cshrc
To change the version of ".login" to be version "3" in the collection "my_project", the following code fragment can be used:
   #include "nc.h"
   
   char  version[MAX_VERSION_LENGTH + 1];

   nc_initiatechange("my_project",
		     "/home/bigtime/andre/workspace");
   nc_version("my_project/.login",
	      "/home/bigtime/andre/workspace",
	      version);
   if (strcmp(version, "3") != 0) {
      nc_replaceversion("my_project/.login",
			"/home/bigtime/andre/workspace",
			"3",
			1);
   }
   nc_commitchangeandreplace("my_project",
	                     "/home/bigtime/andre/workspace");
The workspace now looks as follows:
   /home/bigtime/andre/workspace/my_project/.login
					    .cshrc
It should be noted that ".login" and ".cshrc" did not need to have been opened to be renamed. In addition, the code fragment can be rewritten as follows:
   nc_initiatechange("my_project",
		     "/home/bigtime/andre/workspace");
   nc_replaceversion("my_project/.login",
		     "/home/bigtime/andre/workspace",
		     "3",
	  	     1);
   nc_commitchangeandreplace("my_project",
	                     "/home/bigtime/andre/workspace");
as nc_replaceversion already checks whether the current version of an artifact is the requested version and won't take any action if it is.

[Top | Quick Index] [Concepts | Interface]

SERL <serl.cs.colorado.edu>