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