00001
00002
00003
00004
00005
00006
00007
00008 #include "collCreate.h"
00009 #include "rodsLog.h"
00010 #include "regColl.h"
00011 #include "icatDefines.h"
00012 #include "fileMkdir.h"
00013 #include "subStructFileMkdir.h"
00014 #include "rsGlobalExtern.h"
00015 #include "rcGlobalExtern.h"
00016 #include "objMetaOpr.h"
00017 #include "collection.h"
00018 #include "specColl.h"
00019 #include "physPath.h"
00020
00021
00022
00023 #include "eirods_resource_backport.h"
00024 #include "eirods_hierarchy_parser.h"
00025
00026
00027
00028
00029 eirods::error validate_collection_path(
00030 const std::string& _path ) {
00031
00032
00033 std::stringstream msg;
00034 msg << "a valid zone name does not appear at the root of the collection path [";
00035 msg << _path;
00036 msg << "]";
00037 eirods::error ret_val = ERROR( SYS_INVALID_INPUT_PARAM, msg.str() );
00038
00039
00040
00041
00042 zoneInfo_t* zone_info = ZoneInfoHead;
00043 while( zone_info ) {
00044
00045
00046 std::string zone_name( "/" );
00047 zone_name += zone_info->zoneName;
00048
00049
00050
00051
00052 size_t pos = _path.find( zone_name );
00053 if( 0 == pos ) {
00054 ret_val = SUCCESS();
00055 zone_info = 0;
00056 } else {
00057 zone_info = zone_info->next;
00058
00059 }
00060
00061 }
00062
00063 return ret_val;
00064
00065 }
00066
00067
00068 int
00069 rsCollCreate (rsComm_t *rsComm, collInp_t *collCreateInp)
00070 {
00071 int status;
00072 rodsServerHost_t *rodsServerHost = NULL;
00073 ruleExecInfo_t rei;
00074 collInfo_t collInfo;
00075 specCollCache_t *specCollCache = NULL;
00076 #ifdef RODS_CAT
00077 dataObjInfo_t *dataObjInfo = NULL;
00078 #endif
00079
00080 eirods::error ret = validate_collection_path( collCreateInp->collName );
00081 if( !ret.ok() ) {
00082 eirods::log( ret );
00083 return SYS_INVALID_INPUT_PARAM;
00084 }
00085
00086 resolveLinkedPath (rsComm, collCreateInp->collName, &specCollCache,
00087 &collCreateInp->condInput);
00088 status = getAndConnRcatHost (rsComm, MASTER_RCAT, collCreateInp->collName,
00089 &rodsServerHost);
00090 if (status < 0 || rodsServerHost == NULL ) {
00091 return(status);
00092 }
00093
00094 if (rodsServerHost->localFlag == LOCAL_HOST) {
00095 initReiWithCollInp (&rei, rsComm, collCreateInp, &collInfo);
00096
00097 status = applyRule ("acPreprocForCollCreate", NULL, &rei, NO_SAVE_REI);
00098
00099 if (status < 0) {
00100 if (rei.status < 0) {
00101 status = rei.status;
00102 }
00103 rodsLog (LOG_ERROR,
00104 "rsCollCreate:acPreprocForCollCreate error for %s,stat=%d",
00105 collCreateInp->collName, status);
00106 return status;
00107 }
00108
00109 if (getValByKey (&collCreateInp->condInput, RECURSIVE_OPR__KW) !=
00110 NULL) {
00111 status = rsMkCollR (rsComm, "/", collCreateInp->collName);
00112 return (status);
00113 }
00114 #ifdef RODS_CAT
00115
00116
00117
00118
00119 status = resolvePathInSpecColl (rsComm, collCreateInp->collName,
00120 WRITE_COLL_PERM, 0, &dataObjInfo);
00121 if (status >= 0) {
00122 freeDataObjInfo (dataObjInfo);
00123 if (status == COLL_OBJ_T) {
00124 return (0);
00125 } else if (status == DATA_OBJ_T) {
00126 return (USER_INPUT_PATH_ERR);
00127 }
00128 } else if (status == SYS_SPEC_COLL_OBJ_NOT_EXIST) {
00129
00130
00131 if (dataObjInfo != NULL && dataObjInfo->specColl != NULL &&
00132 dataObjInfo->specColl->collClass == LINKED_COLL) {
00133
00134 return SYS_COLL_LINK_PATH_ERR;
00135 } else {
00136 status = l3Mkdir (rsComm, dataObjInfo);
00137 }
00138 freeDataObjInfo (dataObjInfo);
00139 return (status);
00140 } else {
00141 if (isColl (rsComm, collCreateInp->collName, NULL) >= 0) {
00142 return CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME;
00143 }
00144 status = _rsRegColl (rsComm, collCreateInp);
00145 }
00146 rei.status = status;
00147 if (status >= 0) {
00148 rei.status = applyRule ("acPostProcForCollCreate", NULL, &rei,
00149 NO_SAVE_REI);
00150
00151 if (rei.status < 0) {
00152 rodsLog (LOG_ERROR,
00153 "rsCollCreate:acPostProcForCollCreate error for %s,stat=%d",
00154 collCreateInp->collName, status);
00155 }
00156 }
00157
00158 #else
00159 status = SYS_NO_RCAT_SERVER_ERR;
00160 #endif
00161 } else {
00162 status = rcCollCreate (rodsServerHost->conn, collCreateInp);
00163 }
00164
00165 return (status);
00166 }
00167
00168 int
00169 l3Mkdir (rsComm_t *rsComm, dataObjInfo_t *dataObjInfo)
00170 {
00171
00172 fileMkdirInp_t fileMkdirInp;
00173 int status;
00174
00175
00176
00177 std::string location;
00178 eirods::error ret = eirods::get_loc_for_hier_string( dataObjInfo->rescHier, location );
00179 if( !ret.ok() ) {
00180 eirods::log( PASSMSG( "l3Mkdir - failed in get_loc_for_hier_String", ret ) );
00181 return -1;
00182 }
00183
00184 if (getStructFileType (dataObjInfo->specColl) >= 0) {
00185 subFile_t subFile;
00186 memset (&subFile, 0, sizeof (subFile));
00187 rstrcpy (subFile.subFilePath, dataObjInfo->subPath, MAX_NAME_LEN);
00188 subFile.mode = getDefDirMode ();
00189
00190 rstrcpy (subFile.addr.hostAddr, location.c_str(), NAME_LEN );
00191 subFile.specColl = dataObjInfo->specColl;
00192 status = rsSubStructFileMkdir (rsComm, &subFile);
00193 } else {
00194 #if 0 // JMC legacy resource
00195 rescTypeInx = dataObjInfo->rescInfo->rescTypeInx;
00196
00197 switch (RescTypeDef[rescTypeInx].rescCat) {
00198 case FILE_CAT:
00199 #endif // JMC legacy resource
00200 memset (&fileMkdirInp, 0, sizeof (fileMkdirInp));
00201 fileMkdirInp.fileType = static_cast< fileDriverType_t >( -1 );
00202 rstrcpy (fileMkdirInp.dirName, dataObjInfo->filePath, MAX_NAME_LEN);
00203 rstrcpy (fileMkdirInp.rescHier, dataObjInfo->rescHier, MAX_NAME_LEN);
00204 rstrcpy (fileMkdirInp.addr.hostAddr, location.c_str(), NAME_LEN);
00205 fileMkdirInp.mode = getDefDirMode ();
00206 status = rsFileMkdir (rsComm, &fileMkdirInp);
00207 #if 0 // JMC legacy resource
00208 break;
00209
00210 default:
00211 rodsLog (LOG_NOTICE,
00212 "l3Mkdir: rescCat type %d is not recognized",
00213 RescTypeDef[rescTypeInx].rescCat);
00214 status = SYS_INVALID_RESC_TYPE;
00215 break;
00216 }
00217 #endif // JMC legacy resource
00218 }
00219 return (status);
00220 }
00221
00222 #ifdef COMPAT_201
00223 int
00224 rsCollCreate201 (rsComm_t *rsComm, collInp201_t *collCreateInp)
00225 {
00226 collInp_t collInp;
00227 int status;
00228
00229 collInp201ToCollInp (collCreateInp, &collInp);
00230
00231 status = rsCollCreate (rsComm, &collInp);
00232
00233 return status;
00234 }
00235 #endif
00236