00001
00002
00003
00004
00005
00006
00007 #include "collection.h"
00008 #include "specColl.h"
00009 #include "genQuery.h"
00010 #include "rodsClient.h"
00011
00012
00013
00014
00015
00016
00017
00018
00019 int
00020 checkCollAccessPerm (rsComm_t *rsComm, char *collection, char *accessPerm)
00021 {
00022 char accStr[LONG_NAME_LEN];
00023 char condStr[MAX_NAME_LEN];
00024 genQueryInp_t genQueryInp;
00025 genQueryOut_t *genQueryOut = NULL;
00026 int status;
00027
00028 if (collection == NULL || accessPerm == NULL) {
00029 return SYS_INTERNAL_NULL_INPUT_ERR;
00030 }
00031
00032 memset (&genQueryInp, 0, sizeof (genQueryInp));
00033
00034 snprintf (accStr, LONG_NAME_LEN, "%s", rsComm->clientUser.userName);
00035 addKeyVal (&genQueryInp.condInput, USER_NAME_CLIENT_KW, accStr);
00036
00037 snprintf (accStr, LONG_NAME_LEN, "%s", rsComm->clientUser.rodsZone);
00038 addKeyVal (&genQueryInp.condInput, RODS_ZONE_CLIENT_KW, accStr);
00039
00040 snprintf (accStr, LONG_NAME_LEN, "%s", accessPerm);
00041 addKeyVal (&genQueryInp.condInput, ACCESS_PERMISSION_KW, accStr);
00042
00043 snprintf (condStr, MAX_NAME_LEN, "='%s'", collection);
00044 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, condStr);
00045
00046 addInxIval (&genQueryInp.selectInp, COL_COLL_ID, 1);
00047
00048 genQueryInp.maxRows = MAX_SQL_ROWS;
00049
00050 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00051
00052 clearGenQueryInp (&genQueryInp);
00053 if (status >= 0) {
00054 freeGenQueryOut (&genQueryOut);
00055 }
00056
00057 return (status);
00058 }
00059
00060 int
00061 rsQueryDataObjInCollReCur (rsComm_t *rsComm, char *collection,
00062 genQueryInp_t *genQueryInp, genQueryOut_t **genQueryOut, char *accessPerm,
00063 int singleFlag)
00064 {
00065 char collQCond[MAX_NAME_LEN*2];
00066 int status;
00067 char accStr[LONG_NAME_LEN];
00068
00069 if (collection == NULL || genQueryOut == NULL) {
00070 return (USER__NULL_INPUT_ERR);
00071 }
00072
00073 memset (genQueryInp, 0, sizeof (genQueryInp_t));
00074
00075 genAllInCollQCond (collection, collQCond);
00076
00077 addInxVal (&genQueryInp->sqlCondInp, COL_COLL_NAME, collQCond);
00078
00079 addInxIval (&genQueryInp->selectInp, COL_D_DATA_ID, 1);
00080 addInxIval (&genQueryInp->selectInp, COL_COLL_NAME, 1);
00081 addInxIval (&genQueryInp->selectInp, COL_DATA_NAME, 1);
00082 addInxIval (&genQueryInp->selectInp, COL_D_RESC_HIER, 1);
00083 if (singleFlag == 0) {
00084 addInxIval (&genQueryInp->selectInp, COL_DATA_REPL_NUM, 1);
00085 addInxIval (&genQueryInp->selectInp, COL_D_RESC_NAME, 1);
00086 addInxIval (&genQueryInp->selectInp, COL_D_DATA_PATH, 1);
00087 }
00088
00089 if (accessPerm != NULL) {
00090 snprintf (accStr, LONG_NAME_LEN, "%s", rsComm->clientUser.userName);
00091 addKeyVal (&genQueryInp->condInput, USER_NAME_CLIENT_KW, accStr);
00092
00093 snprintf (accStr, LONG_NAME_LEN, "%s", rsComm->clientUser.rodsZone);
00094 addKeyVal (&genQueryInp->condInput, RODS_ZONE_CLIENT_KW, accStr);
00095
00096 snprintf (accStr, LONG_NAME_LEN, "%s", accessPerm);
00097 addKeyVal (&genQueryInp->condInput, ACCESS_PERMISSION_KW, accStr);
00098
00099 genQueryInp->maxRows = 1;
00100 status = rsGenQuery (rsComm, genQueryInp, genQueryOut);
00101 rmKeyVal (&genQueryInp->condInput, USER_NAME_CLIENT_KW);
00102 rmKeyVal (&genQueryInp->condInput, RODS_ZONE_CLIENT_KW);
00103 rmKeyVal (&genQueryInp->condInput, ACCESS_PERMISSION_KW);
00104 } else {
00105 genQueryInp->maxRows = MAX_SQL_ROWS;
00106 status = rsGenQuery (rsComm, genQueryInp, genQueryOut);
00107 }
00108
00109
00110 return (status);
00111
00112 }
00113
00114 int
00115 rsQueryCollInColl (rsComm_t *rsComm, char *collection,
00116 genQueryInp_t *genQueryInp, genQueryOut_t **genQueryOut)
00117 {
00118 char collQCond[MAX_NAME_LEN];
00119 int status;
00120
00121 if (collection == NULL || genQueryOut == NULL) {
00122 return (USER__NULL_INPUT_ERR);
00123 }
00124
00125 memset (genQueryInp, 0, sizeof (genQueryInp_t));
00126
00127 snprintf (collQCond, MAX_NAME_LEN, "='%s'", collection);
00128
00129 addInxVal (&genQueryInp->sqlCondInp, COL_COLL_PARENT_NAME, collQCond);
00130
00131 addInxIval (&genQueryInp->selectInp, COL_COLL_NAME, 1);
00132
00133 genQueryInp->maxRows = MAX_SQL_ROWS;
00134
00135 status = rsGenQuery (rsComm, genQueryInp, genQueryOut);
00136
00137 return (status);
00138 }
00139
00140 int
00141 isCollEmpty (rsComm_t *rsComm, char *collection)
00142 {
00143 collInp_t openCollInp;
00144 collEnt_t *collEnt;
00145 int handleInx;
00146 int entCnt = 0;
00147
00148 if (rsComm == NULL || collection == NULL) {
00149 rodsLog (LOG_ERROR,
00150 "isCollEmpty: Input rsComm or collection is NULL");
00151 return True;
00152 }
00153
00154 memset (&openCollInp, 0, sizeof (openCollInp));
00155 rstrcpy (openCollInp.collName, collection, MAX_NAME_LEN);
00156
00157 openCollInp.flags = 0;
00158 handleInx = rsOpenCollection (rsComm, &openCollInp);
00159 if (handleInx < 0) {
00160 rodsLog (LOG_ERROR,
00161 "isCollEmpty: rsOpenCollection of %s error. status = %d",
00162 openCollInp.collName, handleInx);
00163 return (True);
00164 }
00165
00166 while (rsReadCollection (rsComm, &handleInx, &collEnt) >= 0) {
00167 entCnt++;
00168 free (collEnt);
00169 }
00170
00171 rsCloseCollection (rsComm, &handleInx);
00172
00173 if (entCnt > 0)
00174 return False;
00175 else
00176 return True;
00177 }
00178
00179
00180
00181 int
00182 collStat (rsComm_t *rsComm, dataObjInp_t *dataObjInp,
00183 rodsObjStat_t **rodsObjStatOut)
00184 {
00185 genQueryInp_t genQueryInp;
00186 genQueryOut_t *genQueryOut = NULL;
00187 int status;
00188 char condStr[MAX_NAME_LEN];
00189 sqlResult_t *dataId;
00190 sqlResult_t *ownerName;
00191 sqlResult_t *ownerZone;
00192 sqlResult_t *createTime;
00193 sqlResult_t *modifyTime;
00194 sqlResult_t *collType;
00195 sqlResult_t *collInfo1;
00196 sqlResult_t *collInfo2;
00197
00198
00199 memset (&genQueryInp, 0, sizeof (genQueryInp));
00200
00201 snprintf (condStr, MAX_NAME_LEN, "='%s'", dataObjInp->objPath);
00202 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, condStr);
00203
00204 addInxIval (&genQueryInp.selectInp, COL_COLL_ID, 1);
00205
00206 addInxIval (&genQueryInp.selectInp, COL_COLL_NAME, 1);
00207 addInxIval (&genQueryInp.selectInp, COL_COLL_OWNER_NAME, 1);
00208 addInxIval (&genQueryInp.selectInp, COL_COLL_OWNER_ZONE, 1);
00209 addInxIval (&genQueryInp.selectInp, COL_COLL_CREATE_TIME, 1);
00210 addInxIval (&genQueryInp.selectInp, COL_COLL_MODIFY_TIME, 1);
00211
00212 addInxIval (&genQueryInp.selectInp, COL_COLL_TYPE, 1);
00213 addInxIval (&genQueryInp.selectInp, COL_COLL_INFO1, 1);
00214 addInxIval (&genQueryInp.selectInp, COL_COLL_INFO2, 1);
00215
00216 genQueryInp.maxRows = MAX_SQL_ROWS;
00217
00218 status = rsGenQuery (rsComm, &genQueryInp, &genQueryOut);
00219 if (status >= 0) {
00220 *rodsObjStatOut = (rodsObjStat_t *) malloc (sizeof (rodsObjStat_t));
00221 memset (*rodsObjStatOut, 0, sizeof (rodsObjStat_t));
00222 (*rodsObjStatOut)->objType = COLL_OBJ_T;
00223 status = (int)COLL_OBJ_T;
00224 if ((dataId = getSqlResultByInx (genQueryOut,
00225 COL_COLL_ID)) == NULL) {
00226 rodsLog (LOG_ERROR,
00227 "_rsObjStat: getSqlResultByInx for COL_COLL_ID failed");
00228 return (UNMATCHED_KEY_OR_INDEX);
00229 } else if ((ownerName = getSqlResultByInx (genQueryOut,
00230 COL_COLL_OWNER_NAME)) == NULL) {
00231 rodsLog (LOG_ERROR,
00232 "_rsObjStat:getSqlResultByInx for COL_COLL_OWNER_NAME failed");
00233 return (UNMATCHED_KEY_OR_INDEX);
00234 } else if ((ownerZone = getSqlResultByInx (genQueryOut,
00235 COL_COLL_OWNER_ZONE)) == NULL) {
00236 rodsLog (LOG_ERROR,
00237 "_rsObjStat:getSqlResultByInx for COL_COLL_OWNER_ZONE failed");
00238 return (UNMATCHED_KEY_OR_INDEX);
00239 } else if ((createTime = getSqlResultByInx (genQueryOut,
00240 COL_COLL_CREATE_TIME)) == NULL) {
00241 rodsLog (LOG_ERROR,
00242 "_rsObjStat:getSqlResultByInx for COL_COLL_CREATE_TIME failed");
00243 return (UNMATCHED_KEY_OR_INDEX);
00244 } else if ((modifyTime = getSqlResultByInx (genQueryOut,
00245 COL_COLL_MODIFY_TIME)) == NULL) {
00246 rodsLog (LOG_ERROR,
00247 "_rsObjStat:getSqlResultByInx for COL_COLL_MODIFY_TIME failed");
00248 return (UNMATCHED_KEY_OR_INDEX);
00249 } else if ((collType = getSqlResultByInx (genQueryOut,
00250 COL_COLL_TYPE)) == NULL) {
00251 rodsLog (LOG_ERROR,
00252 "_rsObjStat:getSqlResultByInx for COL_COLL_TYPE failed");
00253 return (UNMATCHED_KEY_OR_INDEX);
00254 } else if ((collInfo1 = getSqlResultByInx (genQueryOut,
00255 COL_COLL_INFO1)) == NULL) {
00256 rodsLog (LOG_ERROR,
00257 "_rsObjStat:getSqlResultByInx for COL_COLL_INFO1 failed");
00258 return (UNMATCHED_KEY_OR_INDEX);
00259 } else if ((collInfo2 = getSqlResultByInx (genQueryOut,
00260 COL_COLL_INFO2)) == NULL) {
00261 rodsLog (LOG_ERROR,
00262 "_rsObjStat:getSqlResultByInx for COL_COLL_INFO2 failed");
00263 return (UNMATCHED_KEY_OR_INDEX);
00264 } else {
00265 rstrcpy ((*rodsObjStatOut)->dataId, dataId->value, NAME_LEN);
00266 rstrcpy ((*rodsObjStatOut)->ownerName, ownerName->value,
00267 NAME_LEN);
00268 rstrcpy ((*rodsObjStatOut)->ownerZone, ownerZone->value,
00269 NAME_LEN);
00270 rstrcpy ((*rodsObjStatOut)->createTime, createTime->value,
00271 NAME_LEN);
00272 rstrcpy ((*rodsObjStatOut)->modifyTime, modifyTime->value,
00273 NAME_LEN);
00274
00275 if (strlen (collType->value) > 0) {
00276 specCollCache_t *specCollCache;
00277
00278 if ((specCollCache =
00279 matchSpecCollCache (dataObjInp->objPath)) != NULL) {
00280 replSpecColl (&specCollCache->specColl,
00281 &(*rodsObjStatOut)->specColl);
00282 } else {
00283 status = queueSpecCollCache (rsComm, genQueryOut,
00284 dataObjInp->objPath);
00285 if (status < 0) return (status);
00286 replSpecColl (&SpecCollCacheHead->specColl,
00287 &(*rodsObjStatOut)->specColl);
00288 }
00289 }
00290 }
00291 }
00292 clearGenQueryInp (&genQueryInp);
00293 freeGenQueryOut (&genQueryOut);
00294
00295 return (status);
00296 }
00297
00298
00299
00300
00301
00302 int
00303 collStatAllKinds (rsComm_t *rsComm, dataObjInp_t *dataObjInp,
00304 rodsObjStat_t **rodsObjStatOut)
00305 {
00306 int status;
00307
00308 *rodsObjStatOut = NULL;
00309 addKeyVal (&dataObjInp->condInput, SEL_OBJ_TYPE_KW, "collection");
00310 status = _rsObjStat (rsComm, dataObjInp, rodsObjStatOut);
00311 rmKeyVal (&dataObjInp->condInput, SEL_OBJ_TYPE_KW);
00312 if (status >= 0) {
00313 if ((*rodsObjStatOut)->objType != COLL_OBJ_T) {
00314 status = OBJ_PATH_DOES_NOT_EXIST;
00315 }
00316 }
00317 if (status < 0 && *rodsObjStatOut != NULL) {
00318 freeRodsObjStat (*rodsObjStatOut);
00319 *rodsObjStatOut = NULL;
00320 }
00321 return status;
00322 }
00323
00324
00325
00326 int
00327 rsMkCollR (rsComm_t *rsComm, const char *startColl, const char *destColl)
00328 {
00329 int status;
00330 int startLen;
00331 int pathLen, tmpLen;
00332 char tmpPath[MAX_NAME_LEN];
00333
00334 startLen = strlen (startColl);
00335 pathLen = strlen (destColl);
00336
00337 rstrcpy (tmpPath, destColl, MAX_NAME_LEN);
00338
00339 tmpLen = pathLen;
00340
00341 while (tmpLen > startLen) {
00342 if (isCollAllKinds (rsComm, tmpPath, NULL) >= 0) {
00343 break;
00344 }
00345
00346
00347
00348 while (tmpLen && tmpPath[tmpLen] != '/')
00349 tmpLen --;
00350 tmpPath[tmpLen] = '\0';
00351 }
00352
00353
00354 while (tmpLen < pathLen) {
00355 collInp_t collCreateInp;
00356
00357
00358 tmpPath[tmpLen] = '/';
00359 memset (&collCreateInp, 0, sizeof (collCreateInp));
00360 rstrcpy (collCreateInp.collName, tmpPath, MAX_NAME_LEN);
00361 status = rsCollCreate (rsComm, &collCreateInp);
00362
00363 if (status == CAT_NAME_EXISTS_AS_DATAOBJ && isTrashPath (tmpPath)) {
00364
00365 dataObjCopyInp_t dataObjRenameInp;
00366 memset (&dataObjRenameInp, 0, sizeof (dataObjRenameInp));
00367
00368 dataObjRenameInp.srcDataObjInp.oprType =
00369 dataObjRenameInp.destDataObjInp.oprType = RENAME_DATA_OBJ;
00370 rstrcpy (dataObjRenameInp.srcDataObjInp.objPath, tmpPath,
00371 MAX_NAME_LEN);
00372 rstrcpy (dataObjRenameInp.destDataObjInp.objPath, tmpPath,
00373 MAX_NAME_LEN);
00374 appendRandomToPath (dataObjRenameInp.destDataObjInp.objPath);
00375
00376 status = rsDataObjRename (rsComm, &dataObjRenameInp);
00377 if (status >= 0) {
00378 status = rsCollCreate (rsComm, &collCreateInp);
00379 }
00380 }
00381
00382 clearKeyVal (&collCreateInp.condInput);
00383 if (status < 0) {
00384
00385
00386 if (status == CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME) {
00387 rodsLog (LOG_DEBUG,
00388 "rsMkCollR: rsCollCreate - coll %s already exist.stat = %d",
00389 tmpPath, status);
00390 status = 0;
00391 } else {
00392 rodsLog (LOG_ERROR,
00393 "rsMkCollR: rsCollCreate failed for %s, status =%d",
00394 tmpPath, status);
00395 }
00396
00397 return status;
00398 }
00399 while (tmpLen && tmpPath[tmpLen] != '\0')
00400 tmpLen ++;
00401 }
00402 return 0;
00403 }
00404