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 int
00027 rsCollCreate (rsComm_t *rsComm, collInp_t *collCreateInp)
00028 {
00029 int status;
00030 rodsServerHost_t *rodsServerHost = NULL;
00031 ruleExecInfo_t rei;
00032 collInfo_t collInfo;
00033 specCollCache_t *specCollCache = NULL;
00034 #ifdef RODS_CAT
00035 dataObjInfo_t *dataObjInfo = NULL;
00036 #endif
00037
00038 resolveLinkedPath (rsComm, collCreateInp->collName, &specCollCache,
00039 &collCreateInp->condInput);
00040 status = getAndConnRcatHost (rsComm, MASTER_RCAT, collCreateInp->collName,
00041 &rodsServerHost);
00042 if (status < 0 || rodsServerHost == NULL ) {
00043 return(status);
00044 }
00045
00046 if (rodsServerHost->localFlag == LOCAL_HOST) {
00047 initReiWithCollInp (&rei, rsComm, collCreateInp, &collInfo);
00048
00049 status = applyRule ("acPreprocForCollCreate", NULL, &rei, NO_SAVE_REI);
00050
00051 if (status < 0) {
00052 if (rei.status < 0) {
00053 status = rei.status;
00054 }
00055 rodsLog (LOG_ERROR,
00056 "rsCollCreate:acPreprocForCollCreate error for %s,stat=%d",
00057 collCreateInp->collName, status);
00058 return status;
00059 }
00060
00061 if (getValByKey (&collCreateInp->condInput, RECURSIVE_OPR__KW) !=
00062 NULL) {
00063 status = rsMkCollR (rsComm, "/", collCreateInp->collName);
00064 return (status);
00065 }
00066 #ifdef RODS_CAT
00067
00068
00069
00070
00071 status = resolvePathInSpecColl (rsComm, collCreateInp->collName,
00072 WRITE_COLL_PERM, 0, &dataObjInfo);
00073 if (status >= 0) {
00074 freeDataObjInfo (dataObjInfo);
00075 if (status == COLL_OBJ_T) {
00076 return (0);
00077 } else if (status == DATA_OBJ_T) {
00078 return (USER_INPUT_PATH_ERR);
00079 }
00080 } else if (status == SYS_SPEC_COLL_OBJ_NOT_EXIST) {
00081
00082
00083 if (dataObjInfo != NULL && dataObjInfo->specColl != NULL &&
00084 dataObjInfo->specColl->collClass == LINKED_COLL) {
00085
00086 return SYS_COLL_LINK_PATH_ERR;
00087 } else {
00088 status = l3Mkdir (rsComm, dataObjInfo);
00089 }
00090 freeDataObjInfo (dataObjInfo);
00091 return (status);
00092 } else {
00093 if (isColl (rsComm, collCreateInp->collName, NULL) >= 0) {
00094 return CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME;
00095 }
00096 status = _rsRegColl (rsComm, collCreateInp);
00097 }
00098 rei.status = status;
00099 if (status >= 0) {
00100 rei.status = applyRule ("acPostProcForCollCreate", NULL, &rei,
00101 NO_SAVE_REI);
00102
00103 if (rei.status < 0) {
00104 rodsLog (LOG_ERROR,
00105 "rsCollCreate:acPostProcForCollCreate error for %s,stat=%d",
00106 collCreateInp->collName, status);
00107 }
00108 }
00109
00110 #else
00111 status = SYS_NO_RCAT_SERVER_ERR;
00112 #endif
00113 } else {
00114 status = rcCollCreate (rodsServerHost->conn, collCreateInp);
00115 }
00116
00117 return (status);
00118 }
00119
00120 int
00121 l3Mkdir (rsComm_t *rsComm, dataObjInfo_t *dataObjInfo)
00122 {
00123 int rescTypeInx;
00124 fileMkdirInp_t fileMkdirInp;
00125 int status;
00126
00127
00128
00129 std::string location;
00130 eirods::error ret = eirods::get_loc_for_hier_string( dataObjInfo->rescHier, location );
00131 if( !ret.ok() ) {
00132 eirods::log( PASSMSG( "l3Mkdir - failed in get_loc_for_hier_String", ret ) );
00133 return -1;
00134 }
00135
00136 if (getStructFileType (dataObjInfo->specColl) >= 0) {
00137 subFile_t subFile;
00138 memset (&subFile, 0, sizeof (subFile));
00139 rstrcpy (subFile.subFilePath, dataObjInfo->subPath, MAX_NAME_LEN);
00140 subFile.mode = getDefDirMode ();
00141
00142 rstrcpy (subFile.addr.hostAddr, location.c_str(), NAME_LEN );
00143 subFile.specColl = dataObjInfo->specColl;
00144 status = rsSubStructFileMkdir (rsComm, &subFile);
00145 } else {
00146 #if 0 // JMC legacy resource
00147 rescTypeInx = dataObjInfo->rescInfo->rescTypeInx;
00148
00149 switch (RescTypeDef[rescTypeInx].rescCat) {
00150 case FILE_CAT:
00151 #endif // JMC legacy resource
00152 memset (&fileMkdirInp, 0, sizeof (fileMkdirInp));
00153 fileMkdirInp.fileType = static_cast< fileDriverType_t >( -1 );
00154 rstrcpy (fileMkdirInp.dirName, dataObjInfo->filePath, MAX_NAME_LEN);
00155 rstrcpy (fileMkdirInp.rescHier, dataObjInfo->rescHier, MAX_NAME_LEN);
00156 rstrcpy (fileMkdirInp.addr.hostAddr, location.c_str(), NAME_LEN);
00157 fileMkdirInp.mode = getDefDirMode ();
00158 status = rsFileMkdir (rsComm, &fileMkdirInp);
00159 #if 0 // JMC legacy resource
00160 break;
00161
00162 default:
00163 rodsLog (LOG_NOTICE,
00164 "l3Mkdir: rescCat type %d is not recognized",
00165 RescTypeDef[rescTypeInx].rescCat);
00166 status = SYS_INVALID_RESC_TYPE;
00167 break;
00168 }
00169 #endif // JMC legacy resource
00170 }
00171 return (status);
00172 }
00173
00174 #ifdef COMPAT_201
00175 int
00176 rsCollCreate201 (rsComm_t *rsComm, collInp201_t *collCreateInp)
00177 {
00178 collInp_t collInp;
00179 int status;
00180
00181 collInp201ToCollInp (collCreateInp, &collInp);
00182
00183 status = rsCollCreate (rsComm, &collInp);
00184
00185 return status;
00186 }
00187 #endif
00188