00001
00002
00003
00004
00005
00006 #include "chkObjPermAndStat.h"
00007 #include "apiHeaderAll.h"
00008 #include "icatHighLevelRoutines.h"
00009 #include "icatHighLevelRoutines.h"
00010 int
00011 saveCollEntForChkColl (collEnt_t *collEnt);
00012 int
00013 freeCollEntForChkColl (collEnt_t *collEnt);
00014
00015 int
00016 rsChkObjPermAndStat (rsComm_t *rsComm,
00017 chkObjPermAndStat_t *chkObjPermAndStatInp)
00018 {
00019 int status;
00020 rodsServerHost_t *rodsServerHost = NULL;
00021
00022 status = getAndConnRcatHost (rsComm, SLAVE_RCAT,
00023 chkObjPermAndStatInp->objPath, &rodsServerHost);
00024 if (status < 0 || rodsServerHost == NULL ) {
00025 return(status);
00026 }
00027 if (rodsServerHost->localFlag == LOCAL_HOST) {
00028 #ifdef RODS_CAT
00029 status = _rsChkObjPermAndStat (rsComm, chkObjPermAndStatInp);
00030 #else
00031 status = SYS_NO_RCAT_SERVER_ERR;
00032 #endif
00033 } else {
00034 status = rcChkObjPermAndStat (rodsServerHost->conn,
00035 chkObjPermAndStatInp);
00036 }
00037
00038 return (status);
00039 }
00040
00041 int
00042 _rsChkObjPermAndStat (rsComm_t *rsComm,
00043 chkObjPermAndStat_t *chkObjPermAndStatInp)
00044 {
00045 #ifdef RODS_CAT
00046 int status;
00047
00048 if ((chkObjPermAndStatInp->flags & CHK_COLL_FOR_BUNDLE_OPR) != 0) {
00049 status = chkCollForBundleOpr (rsComm, chkObjPermAndStatInp);
00050 } else {
00051 rodsLog (LOG_ERROR,
00052 "_rsChkObjPermAndStat: rsChkObjPermAndStat of %s error. flags = %d",
00053 chkObjPermAndStatInp->objPath, chkObjPermAndStatInp->flags);
00054 return SYS_OPR_FLAG_NOT_SUPPORT;
00055 }
00056 return status;
00057 #else
00058 return (SYS_NO_RCAT_SERVER_ERR);
00059 #endif
00060 }
00061
00062
00063 int
00064 chkCollForBundleOpr (rsComm_t *rsComm,
00065 chkObjPermAndStat_t *chkObjPermAndStatInp)
00066 {
00067 #ifdef RODS_CAT
00068 int status;
00069 collInp_t openCollInp;
00070 collEnt_t *collEnt = NULL;
00071 collEnt_t *curCollEnt = NULL;
00072 int handleInx;
00073 int curCopyGood = False;
00074 char *resource;
00075 char *resc_hier;
00076 rodsLong_t myId;
00077 char myPath[MAX_NAME_LEN];
00078
00079 if ((resource = getValByKey (&chkObjPermAndStatInp->condInput,
00080 RESC_NAME_KW)) == NULL) {
00081 rodsLog (LOG_ERROR,
00082 "chkCollForBundleOpr: RESC_NAME_KW not specified for %s",
00083 chkObjPermAndStatInp->objPath);
00084 return SYS_INVALID_RESC_INPUT;
00085 }
00086
00087 if ((resc_hier = getValByKey (&chkObjPermAndStatInp->condInput,
00088 RESC_HIER_STR_KW)) == NULL) {
00089 rodsLog (LOG_ERROR,
00090 "chkCollForBundleOpr: RESC_HIER_STR_KW not specified for %s",
00091 chkObjPermAndStatInp->objPath);
00092 return SYS_INVALID_RESC_INPUT;
00093 }
00094
00095 memset (&openCollInp, 0, sizeof (openCollInp));
00096 rstrcpy (openCollInp.collName, chkObjPermAndStatInp->objPath, MAX_NAME_LEN);
00097 openCollInp.flags =
00098 RECUR_QUERY_FG | LONG_METADATA_FG | NO_TRIM_REPL_FG;
00099 handleInx = rsOpenCollection (rsComm, &openCollInp);
00100 if (handleInx < 0) {
00101 rodsLog (LOG_ERROR,
00102 "chkCollForBundleOpr: rsOpenCollection of %s error. status = %d",
00103 openCollInp.collName, handleInx);
00104 return (handleInx);
00105 }
00106 while ((status = rsReadCollection (rsComm, &handleInx, &collEnt)) >= 0) {
00107 if (collEnt->specColl.collClass != NO_SPEC_COLL) {
00108 if (strcmp (resource, collEnt->specColl.resource) != 0) {
00109 rodsLog (LOG_ERROR,
00110 "chkCollForBundleOpr: specColl resc %s does not match %s",
00111 collEnt->specColl.resource, resource);
00112 rsCloseCollection (rsComm, &handleInx);
00113 return SYS_COPY_NOT_EXIST_IN_RESC;
00114 }
00115
00116 myId = checkAndGetObjectId (rsComm, "-c",
00117 collEnt->specColl.collection, ACCESS_READ_OBJECT);
00118 if (myId < 0) {
00119 status = myId;
00120 rodsLog (LOG_ERROR,
00121 "chkCollForBundleOpr: no accPerm to specColl %s. status = %d",
00122 collEnt->specColl.collection, status);
00123 rsCloseCollection (rsComm, &handleInx);
00124 return status;
00125 }
00126 free (collEnt);
00127 collEnt = NULL;
00128 continue;
00129 }
00130
00131 if (collEnt->objType == DATA_OBJ_T) {
00132 if (curCollEnt == NULL) {
00133 curCollEnt = collEnt;
00134 saveCollEntForChkColl (collEnt);
00135 if (collEnt->replStatus > 0 &&
00136 strcmp (resource, collEnt->resource) == 0 &&
00137 strcmp (resc_hier, collEnt->resc_hier) == 0) {
00138 curCopyGood = True;
00139 }
00140 } else {
00141 if( strcmp (curCollEnt->dataName, collEnt->dataName) == 0 &&
00142 strcmp (curCollEnt->collName, collEnt->collName) == 0 ) {
00143 if( collEnt->replStatus > 0 &&
00144 strcmp( resource, collEnt->resource ) == 0 &&
00145 strcmp( resc_hier, collEnt->resc_hier ) == 0 ) {
00146
00147 freeCollEntForChkColl (curCollEnt);
00148 curCopyGood = True;
00149 curCollEnt = collEnt;
00150 saveCollEntForChkColl (collEnt);
00151 }
00152 } else {
00153
00154 snprintf( myPath, MAX_NAME_LEN, "%s/%s",
00155 curCollEnt->collName, curCollEnt->dataName );
00156
00157 if( curCopyGood == False ) {
00158 status = replDataObjForBundle (rsComm,
00159 curCollEnt->collName, curCollEnt->dataName,
00160 resource, curCollEnt->resc_hier, resc_hier, 0, NULL);
00161
00162 if (status < 0) {
00163 rodsLog (LOG_ERROR,
00164 "chkCollForBundleOpr: %s no good copy in %s",
00165 myPath, resource);
00166 rsCloseCollection (rsComm, &handleInx);
00167 freeCollEntForChkColl (curCollEnt);
00168 return SYS_COPY_NOT_EXIST_IN_RESC;
00169 }
00170 } else {
00171
00172 }
00173 freeCollEntForChkColl (curCollEnt);
00174 curCopyGood = False;
00175 curCollEnt = NULL;
00176
00177
00178 myId = checkAndGetObjectId (rsComm, "-d", myPath,
00179 ACCESS_READ_OBJECT);
00180 if (myId < 0 && myId != CAT_UNKNOWN_FILE) {
00181
00182 status = myId;
00183 rodsLog (LOG_ERROR,
00184 "chkCollForBundleOpr: no accPerm to %s. status = %d",
00185 myPath, status);
00186 rsCloseCollection (rsComm, &handleInx);
00187 return status;
00188 } else {
00189
00190 curCollEnt = collEnt;
00191 saveCollEntForChkColl (collEnt);
00192 collEnt = NULL;
00193 if (curCollEnt->replStatus > 0 &&
00194 strcmp (resource, curCollEnt->resource) == 0 &&
00195 strcmp (resc_hier, curCollEnt->resc_hier ) == 0) {
00196
00197 curCopyGood = True;
00198 }
00199 }
00200 }
00201 }
00202 } else {
00203 free (collEnt);
00204 }
00205 }
00206
00207
00208 if (curCollEnt != NULL) {
00209 if (curCopyGood == False) {
00210 status = replDataObjForBundle (rsComm, curCollEnt->collName,
00211 curCollEnt->dataName, resource, curCollEnt->resc_hier, resc_hier, 0, NULL);
00212 if (status < 0) {
00213 rodsLog (LOG_ERROR,
00214 "chkCollForBundleOpr:%s does not have a good copy in %s",
00215 chkObjPermAndStatInp->objPath, resource);
00216 status = SYS_COPY_NOT_EXIST_IN_RESC;
00217 }
00218 } else {
00219 freeCollEntForChkColl (curCollEnt);
00220 }
00221 } else {
00222 status = 0;
00223 }
00224
00225 rsCloseCollection (rsComm, &handleInx);
00226
00227 return (0);
00228 #else
00229 return (SYS_NO_RCAT_SERVER_ERR);
00230 #endif
00231 }
00232
00233
00234
00235
00236
00237 int
00238 saveCollEntForChkColl (collEnt_t *collEnt)
00239 {
00240 if (collEnt == NULL) return 0;
00241 if (collEnt->collName != NULL)
00242 collEnt->collName = strdup (collEnt->collName);
00243 if (collEnt->dataName != NULL)
00244 collEnt->dataName = strdup (collEnt->dataName);
00245 if (collEnt->resource != NULL)
00246 collEnt->resource = strdup (collEnt->resource);
00247 return 0;
00248 }
00249
00250 int
00251 freeCollEntForChkColl (collEnt_t *collEnt)
00252 {
00253 if (collEnt == NULL) return 0;
00254 if (collEnt->collName != NULL) free (collEnt->collName);
00255 if (collEnt->dataName != NULL) free (collEnt->dataName);
00256 if (collEnt->resource != NULL) free (collEnt->resource);
00257
00258 free (collEnt);
00259 return 0;
00260 }
00261