00001
00002
00003
00004
00005
00006 #include "collCreate.h"
00007 #include "rodsLog.h"
00008 #include "regColl.h"
00009 #include "icatDefines.h"
00010 #include "fileMkdir.h"
00011 #include "subStructFileMkdir.h"
00012 #include "rsGlobalExtern.h"
00013 #include "rcGlobalExtern.h"
00014 #include "objMetaOpr.h"
00015 #include "collection.h"
00016 #include "specColl.h"
00017 #include "physPath.h"
00018
00019 int
00020 rsCollCreate (rsComm_t *rsComm, collInp_t *collCreateInp)
00021 {
00022 int status;
00023 rodsServerHost_t *rodsServerHost = NULL;
00024 ruleExecInfo_t rei;
00025 collInfo_t collInfo;
00026 specCollCache_t *specCollCache = NULL;
00027 #ifdef RODS_CAT
00028 dataObjInfo_t *dataObjInfo = NULL;
00029 #endif
00030
00031 resolveLinkedPath (rsComm, collCreateInp->collName, &specCollCache,
00032 &collCreateInp->condInput);
00033 status = getAndConnRcatHost (rsComm, MASTER_RCAT, collCreateInp->collName,
00034 &rodsServerHost);
00035 if (status < 0 || rodsServerHost == NULL ) {
00036 return(status);
00037 }
00038
00039 if (rodsServerHost->localFlag == LOCAL_HOST) {
00040 initReiWithCollInp (&rei, rsComm, collCreateInp, &collInfo);
00041
00042 status = applyRule ("acPreprocForCollCreate", NULL, &rei, NO_SAVE_REI);
00043
00044 if (status < 0) {
00045 if (rei.status < 0) {
00046 status = rei.status;
00047 }
00048 rodsLog (LOG_ERROR,
00049 "rsCollCreate:acPreprocForCollCreate error for %s,stat=%d",
00050 collCreateInp->collName, status);
00051 return status;
00052 }
00053
00054 if (getValByKey (&collCreateInp->condInput, RECURSIVE_OPR__KW) !=
00055 NULL) {
00056 status = rsMkCollR (rsComm, "/", collCreateInp->collName);
00057 return (status);
00058 }
00059 #ifdef RODS_CAT
00060
00061
00062
00063
00064 status = resolvePathInSpecColl (rsComm, collCreateInp->collName,
00065 WRITE_COLL_PERM, 0, &dataObjInfo);
00066 if (status >= 0) {
00067 freeDataObjInfo (dataObjInfo);
00068 if (status == COLL_OBJ_T) {
00069 return (0);
00070 } else if (status == DATA_OBJ_T) {
00071 return (USER_INPUT_PATH_ERR);
00072 }
00073 } else if (status == SYS_SPEC_COLL_OBJ_NOT_EXIST) {
00074
00075
00076 if (dataObjInfo != NULL && dataObjInfo->specColl != NULL &&
00077 dataObjInfo->specColl->collClass == LINKED_COLL) {
00078
00079 return SYS_COLL_LINK_PATH_ERR;
00080 } else {
00081 status = l3Mkdir (rsComm, dataObjInfo);
00082 }
00083 freeDataObjInfo (dataObjInfo);
00084 return (status);
00085 } else {
00086 if (isColl (rsComm, collCreateInp->collName, NULL) >= 0)
00087 return CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME;
00088 status = _rsRegColl (rsComm, collCreateInp);
00089 }
00090 rei.status = status;
00091 if (status >= 0) {
00092 rei.status = applyRule ("acPostProcForCollCreate", NULL, &rei,
00093 NO_SAVE_REI);
00094
00095 if (rei.status < 0) {
00096 rodsLog (LOG_ERROR,
00097 "rsCollCreate:acPostProcForCollCreate error for %s,stat=%d",
00098 collCreateInp->collName, status);
00099 }
00100 }
00101
00102 #else
00103 status = SYS_NO_RCAT_SERVER_ERR;
00104 #endif
00105 } else {
00106 status = rcCollCreate (rodsServerHost->conn, collCreateInp);
00107 }
00108
00109 return (status);
00110 }
00111
00112 int
00113 l3Mkdir (rsComm_t *rsComm, dataObjInfo_t *dataObjInfo)
00114 {
00115 int rescTypeInx;
00116 fileMkdirInp_t fileMkdirInp;
00117 int status;
00118
00119 if (getStructFileType (dataObjInfo->specColl) >= 0) {
00120 subFile_t subFile;
00121 memset (&subFile, 0, sizeof (subFile));
00122 rstrcpy (subFile.subFilePath, dataObjInfo->subPath,
00123 MAX_NAME_LEN);
00124 subFile.mode = getDefDirMode ();
00125 rstrcpy (subFile.addr.hostAddr, dataObjInfo->rescInfo->rescLoc,
00126 NAME_LEN);
00127 subFile.specColl = dataObjInfo->specColl;
00128 status = rsSubStructFileMkdir (rsComm, &subFile);
00129 } else {
00130 rescTypeInx = dataObjInfo->rescInfo->rescTypeInx;
00131
00132 switch (RescTypeDef[rescTypeInx].rescCat) {
00133 case FILE_CAT:
00134 memset (&fileMkdirInp, 0, sizeof (fileMkdirInp));
00135 fileMkdirInp.fileType = (fileDriverType_t)RescTypeDef[rescTypeInx].driverType;
00136 rstrcpy (fileMkdirInp.dirName, dataObjInfo->filePath,
00137 MAX_NAME_LEN);
00138 rstrcpy (fileMkdirInp.addr.hostAddr,
00139 dataObjInfo->rescInfo->rescLoc, NAME_LEN);
00140 fileMkdirInp.mode = getDefDirMode ();
00141 status = rsFileMkdir (rsComm, &fileMkdirInp);
00142 break;
00143
00144 default:
00145 rodsLog (LOG_NOTICE,
00146 "l3Mkdir: rescCat type %d is not recognized",
00147 RescTypeDef[rescTypeInx].rescCat);
00148 status = SYS_INVALID_RESC_TYPE;
00149 break;
00150 }
00151 }
00152 return (status);
00153 }
00154
00155 #ifdef COMPAT_201
00156 int
00157 rsCollCreate201 (rsComm_t *rsComm, collInp201_t *collCreateInp)
00158 {
00159 collInp_t collInp;
00160 int status;
00161
00162 collInp201ToCollInp (collCreateInp, &collInp);
00163
00164 status = rsCollCreate (rsComm, &collInp);
00165
00166 return status;
00167 }
00168 #endif
00169