00001
00002
00003
00004
00005
00006
00007
00008 #include "rmCollOld.h"
00009 #include "rmColl.h"
00010 #include "objMetaOpr.h"
00011 #include "specColl.h"
00012 #include "icatHighLevelRoutines.h"
00013 #include "openCollection.h"
00014 #include "readCollection.h"
00015 #include "closeCollection.h"
00016 #include "dataObjUnlink.h"
00017 #include "rsApiHandler.h"
00018
00019 int
00020 rsRmColl (rsComm_t *rsComm, collInp_t *rmCollInp,
00021 collOprStat_t **collOprStat)
00022 {
00023 int status;
00024 ruleExecInfo_t rei;
00025 collInfo_t collInfo;
00026 rodsServerHost_t *rodsServerHost = NULL;
00027 specCollCache_t *specCollCache = NULL;
00028
00029 resolveLinkedPath (rsComm, rmCollInp->collName, &specCollCache,
00030 &rmCollInp->condInput);
00031 status = getAndConnRcatHost (rsComm, MASTER_RCAT,
00032 rmCollInp->collName, &rodsServerHost);
00033
00034 if (status < 0 || NULL == rodsServerHost ) {
00035 return (status);
00036 } else if (rodsServerHost->rcatEnabled == REMOTE_ICAT) {
00037 int retval;
00038 retval = _rcRmColl (rodsServerHost->conn, rmCollInp, collOprStat);
00039 status = svrSendZoneCollOprStat (rsComm, rodsServerHost->conn,
00040 *collOprStat, retval);
00041 return status;
00042 }
00043
00044 initReiWithCollInp (&rei, rsComm, rmCollInp, &collInfo);
00045
00046 status = applyRule ("acPreprocForRmColl", NULL, &rei, NO_SAVE_REI);
00047
00048 if (status < 0) {
00049 if (rei.status < 0) {
00050 status = rei.status;
00051 }
00052 rodsLog (LOG_ERROR,
00053 "rsRmColl:acPreprocForRmColl error for %s,stat=%d",
00054 rmCollInp->collName, status);
00055 return status;
00056 }
00057
00058 if (collOprStat != NULL)
00059 *collOprStat = NULL;
00060 if (getValByKey (&rmCollInp->condInput, RECURSIVE_OPR__KW) == NULL) {
00061 status = _rsRmColl (rsComm, rmCollInp, collOprStat);
00062 } else {
00063 if (isTrashPath (rmCollInp->collName) == False &&
00064 getValByKey (&rmCollInp->condInput, FORCE_FLAG_KW) != NULL) {
00065 rodsLog (LOG_NOTICE,
00066 "rsRmColl: Recursively removing %s.",
00067 rmCollInp->collName);
00068 }
00069 status = _rsRmCollRecur (rsComm, rmCollInp, collOprStat);
00070 }
00071 rei.status = status;
00072 rei.status = applyRule ("acPostProcForRmColl", NULL, &rei,
00073 NO_SAVE_REI);
00074
00075 if (rei.status < 0) {
00076 rodsLog (LOG_ERROR,
00077 "rsRmColl:acPostProcForRmColl error for %s,stat=%d",
00078 rmCollInp->collName, status);
00079 }
00080
00081 return status;
00082 }
00083
00084 int
00085 _rsRmColl (rsComm_t *rsComm, collInp_t *rmCollInp,
00086 collOprStat_t **collOprStat)
00087 {
00088 int status;
00089 dataObjInfo_t *dataObjInfo = NULL;
00090
00091 if (getValByKey (&rmCollInp->condInput, UNREG_COLL_KW) != NULL) {
00092 status = svrUnregColl (rsComm, rmCollInp);
00093 } else {
00094
00095 #if 0
00096 dataObjInp_t dataObjInp;
00097 memset (&dataObjInp, 0, sizeof (dataObjInp));
00098 rstrcpy (dataObjInp.objPath, rmCollInp->collName, MAX_NAME_LEN);
00099 #endif
00100 status = resolvePathInSpecColl (rsComm, rmCollInp->collName,
00101 WRITE_COLL_PERM, 0, &dataObjInfo);
00102 if (status < 0 && status != CAT_NO_ROWS_FOUND) {
00103 return status;
00104 } else if (status == COLL_OBJ_T && dataObjInfo->specColl != NULL) {
00105 if (dataObjInfo->specColl->collClass == LINKED_COLL) {
00106 rstrcpy (rmCollInp->collName, dataObjInfo->objPath,
00107 MAX_NAME_LEN);
00108 status = svrUnregColl (rsComm, rmCollInp);
00109 } else {
00110 status = l3Rmdir (rsComm, dataObjInfo);
00111 }
00112 freeDataObjInfo (dataObjInfo);
00113 } else {
00114 status = svrUnregColl (rsComm, rmCollInp);
00115 }
00116 }
00117 if (status >= 0 && collOprStat != NULL) {
00118 *collOprStat = (collOprStat_t*)malloc (sizeof (collOprStat_t));
00119 memset (*collOprStat, 0, sizeof (collOprStat_t));
00120 (*collOprStat)->filesCnt = 1;
00121 (*collOprStat)->totalFileCnt = 1;
00122 rstrcpy ((*collOprStat)->lastObjPath, rmCollInp->collName,
00123 MAX_NAME_LEN);
00124 }
00125 return (status);
00126 }
00127
00128 int
00129 _rsRmCollRecur (rsComm_t *rsComm, collInp_t *rmCollInp,
00130 collOprStat_t **collOprStat)
00131 {
00132 int status;
00133 ruleExecInfo_t rei;
00134 int trashPolicy;
00135 dataObjInfo_t *dataObjInfo = NULL;
00136 #if 0
00137 dataObjInp_t dataObjInp;
00138
00139 memset (&dataObjInp, 0, sizeof (dataObjInp));
00140 rstrcpy (dataObjInp.objPath, rmCollInp->collName, MAX_NAME_LEN);
00141 #endif
00142
00143 status = resolvePathInSpecColl (rsComm, rmCollInp->collName,
00144 WRITE_COLL_PERM, 0, &dataObjInfo);
00145
00146 if (status < 0 && status != CAT_NO_ROWS_FOUND) {
00147 return status;
00148 }
00149 if (status == COLL_OBJ_T && dataObjInfo->specColl != NULL &&
00150 dataObjInfo->specColl->collClass == LINKED_COLL) {
00151 rstrcpy (rmCollInp->collName, dataObjInfo->objPath,
00152 MAX_NAME_LEN);
00153 free (dataObjInfo->specColl);
00154 dataObjInfo->specColl = NULL;
00155 }
00156 if (status != COLL_OBJ_T || dataObjInfo->specColl == NULL) {
00157
00158 if (rmCollInp->oprType != UNREG_OPR &&
00159 getValByKey (&rmCollInp->condInput, FORCE_FLAG_KW) == NULL &&
00160 getValByKey (&rmCollInp->condInput, IRODS_RMTRASH_KW) == NULL &&
00161 getValByKey (&rmCollInp->condInput, IRODS_ADMIN_RMTRASH_KW) == NULL) {
00162 initReiWithDataObjInp (&rei, rsComm, NULL);
00163 status = applyRule ("acTrashPolicy", NULL, &rei, NO_SAVE_REI);
00164 trashPolicy = rei.status;
00165 if (trashPolicy != NO_TRASH_CAN) {
00166 status = rsMvCollToTrash (rsComm, rmCollInp);
00167 if (status >= 0 && collOprStat != NULL) {
00168 if (*collOprStat == NULL) {
00169 *collOprStat = (collOprStat_t*)malloc (sizeof (collOprStat_t));
00170 memset (*collOprStat, 0, sizeof (collOprStat_t));
00171 }
00172 (*collOprStat)->filesCnt = 1;
00173 (*collOprStat)->totalFileCnt = 1;
00174 rstrcpy ((*collOprStat)->lastObjPath, rmCollInp->collName,
00175 MAX_NAME_LEN);
00176 }
00177 return status;
00178 }
00179 }
00180 }
00181
00182 status = _rsPhyRmColl (rsComm, rmCollInp, dataObjInfo, collOprStat);
00183
00184 if (dataObjInfo != NULL) freeDataObjInfo (dataObjInfo);
00185 return (status);
00186 }
00187
00188 int
00189 _rsPhyRmColl (rsComm_t *rsComm, collInp_t *rmCollInp,
00190 dataObjInfo_t *dataObjInfo, collOprStat_t **collOprStat)
00191 {
00192
00193 char *tmpValue;
00194 int status;
00195 collInp_t openCollInp;
00196 collEnt_t *collEnt;
00197 int handleInx;
00198 dataObjInp_t dataObjInp;
00199 collInp_t tmpCollInp;
00200 int rmtrashFlag =0;
00201 int savedStatus = 0;
00202 int fileCntPerStatOut = FILE_CNT_PER_STAT_OUT;
00203 int entCnt = 0;
00204
00205 memset (&openCollInp, 0, sizeof (openCollInp));
00206 rstrcpy (openCollInp.collName, rmCollInp->collName, MAX_NAME_LEN);
00207
00208 openCollInp.flags = 0;
00209 handleInx = rsOpenCollection (rsComm, &openCollInp);
00210 if (handleInx < 0) {
00211 rodsLog (LOG_ERROR,
00212 "_rsPhyRmColl: rsOpenCollection of %s error. status = %d",
00213 openCollInp.collName, handleInx);
00214 return (handleInx);
00215 }
00216
00217 memset (&dataObjInp, 0, sizeof (dataObjInp));
00218 memset (&tmpCollInp, 0, sizeof (tmpCollInp));
00219
00220 dataObjInp.oprType = tmpCollInp.oprType = rmCollInp->oprType;
00221
00222 if ((tmpValue = getValByKey (&rmCollInp->condInput, AGE_KW)) != NULL) {
00223 if (CollHandle[handleInx].rodsObjStat != NULL) {
00224
00225
00226
00227 int ageLimit = atoi (tmpValue) * 60;
00228 int modifyTime =
00229 atoi (CollHandle[handleInx].rodsObjStat->modifyTime);
00230 if ((time (0) - modifyTime) < ageLimit) {
00231 rsCloseCollection (rsComm, &handleInx);
00232 return 0;
00233 }
00234 }
00235 addKeyVal (&dataObjInp.condInput, AGE_KW, tmpValue);
00236 addKeyVal (&tmpCollInp.condInput, AGE_KW, tmpValue);
00237 }
00238 addKeyVal (&dataObjInp.condInput, FORCE_FLAG_KW, "");
00239 addKeyVal (&tmpCollInp.condInput, FORCE_FLAG_KW, "");
00240
00241 if ((tmpValue = getValByKey (&rmCollInp->condInput, AGE_KW)) != NULL) {
00242 addKeyVal (&dataObjInp.condInput, AGE_KW, tmpValue);
00243 addKeyVal (&tmpCollInp.condInput, AGE_KW, tmpValue);
00244 }
00245
00246 if (collOprStat != NULL && *collOprStat == NULL) {
00247 *collOprStat = (collOprStat_t*)malloc (sizeof (collOprStat_t));
00248 memset (*collOprStat, 0, sizeof (collOprStat_t));
00249 }
00250
00251
00252
00253 if (getValByKey (&rmCollInp->condInput, IRODS_ADMIN_RMTRASH_KW) != NULL) {
00254 if (isTrashPath (rmCollInp->collName) == False) {
00255 return (SYS_INVALID_FILE_PATH);
00256 }
00257 if (rsComm->clientUser.authInfo.authFlag != LOCAL_PRIV_USER_AUTH) {
00258 return(CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
00259 }
00260 addKeyVal (&tmpCollInp.condInput, IRODS_ADMIN_RMTRASH_KW, "");
00261 addKeyVal (&dataObjInp.condInput, IRODS_ADMIN_RMTRASH_KW, "");
00262 rmtrashFlag = 2;
00263 } else if (getValByKey (&rmCollInp->condInput, IRODS_RMTRASH_KW) != NULL) {
00264 if (isTrashPath (rmCollInp->collName) == False) {
00265 return (SYS_INVALID_FILE_PATH);
00266 }
00267 addKeyVal (&tmpCollInp.condInput, IRODS_RMTRASH_KW, "");
00268 addKeyVal (&dataObjInp.condInput, IRODS_RMTRASH_KW, "");
00269 rmtrashFlag = 1;
00270 }
00271
00272
00273 if (getValByKey (&rmCollInp->condInput, EMPTY_BUNDLE_ONLY_KW) != NULL) {
00274 addKeyVal (&tmpCollInp.condInput, EMPTY_BUNDLE_ONLY_KW, "");
00275 addKeyVal (&dataObjInp.condInput, EMPTY_BUNDLE_ONLY_KW, "");
00276 }
00277
00278 while ((status = rsReadCollection (rsComm, &handleInx, &collEnt)) >= 0) {
00279 if (entCnt == 0) {
00280 entCnt ++;
00281
00282 if (isHomeColl (rmCollInp->collName))
00283 return (CANT_RM_NON_EMPTY_HOME_COLL);
00284 }
00285 if (collEnt->objType == DATA_OBJ_T) {
00286 snprintf (dataObjInp.objPath, MAX_NAME_LEN, "%s/%s",
00287 collEnt->collName, collEnt->dataName);
00288
00289 status = rsDataObjUnlink (rsComm, &dataObjInp);
00290 if (status < 0) {
00291 rodsLog (LOG_ERROR,
00292 "_rsPhyRmColl:rsDataObjUnlink failed for %s. stat = %d",
00293 dataObjInp.objPath, status);
00294
00295 savedStatus = status;
00296 } else if (collOprStat != NULL) {
00297 (*collOprStat)->filesCnt ++;
00298 if ((*collOprStat)->filesCnt >= fileCntPerStatOut) {
00299 rstrcpy ((*collOprStat)->lastObjPath, dataObjInp.objPath,
00300 MAX_NAME_LEN);
00301 status = svrSendCollOprStat (rsComm, *collOprStat);
00302 if (status < 0) {
00303 rodsLogError (LOG_ERROR, status,
00304 "_rsPhyRmColl: svrSendCollOprStat failed for %s. status = %d",
00305 rmCollInp->collName, status);
00306 *collOprStat = NULL;
00307 savedStatus = status;
00308 break;
00309 }
00310 *collOprStat = (collOprStat_t*)malloc (sizeof (collOprStat_t));
00311 memset (*collOprStat, 0, sizeof (collOprStat_t));
00312 }
00313 }
00314 } else if (collEnt->objType == COLL_OBJ_T) {
00315 if (strcmp (collEnt->collName, rmCollInp->collName) == 0)
00316 continue;
00317 rstrcpy (tmpCollInp.collName, collEnt->collName, MAX_NAME_LEN);
00318 if (collEnt->specColl.collClass != NO_SPEC_COLL) {
00319 if (strcmp (collEnt->collName, collEnt->specColl.collection)
00320 == 0) continue;
00321 }
00322 status = _rsRmCollRecur (rsComm, &tmpCollInp, collOprStat);
00323 }
00324 if (status < 0) savedStatus = status;
00325 free (collEnt);
00326 }
00327 rsCloseCollection (rsComm, &handleInx);
00328
00329 if( ( rmtrashFlag > 0 && ( isTrashHome (rmCollInp->collName) > 0 ||
00330 isOrphanPath (rmCollInp->collName) == is_ORPHAN_HOME ) ) ||
00331 ( isBundlePath (rmCollInp->collName) == True &&
00332 getValByKey (&rmCollInp->condInput, EMPTY_BUNDLE_ONLY_KW) != NULL )) {
00333
00334 status = 0;
00335 } else {
00336 if (dataObjInfo != NULL && dataObjInfo->specColl != NULL) {
00337 if (dataObjInfo->specColl->collClass == LINKED_COLL) {
00338 rstrcpy (rmCollInp->collName, dataObjInfo->objPath,
00339 MAX_NAME_LEN);
00340 status = svrUnregColl (rsComm, rmCollInp);
00341 } else {
00342 status = l3Rmdir (rsComm, dataObjInfo);
00343 }
00344 } else {
00345 status = svrUnregColl (rsComm, rmCollInp);
00346 if (status < 0) savedStatus = status;
00347 }
00348 }
00349 clearKeyVal (&tmpCollInp.condInput);
00350 clearKeyVal (&dataObjInp.condInput);
00351
00352 return (savedStatus);
00353 }
00354
00355 int
00356 svrUnregColl (rsComm_t *rsComm, collInp_t *rmCollInp)
00357 {
00358 int status;
00359 #ifdef RODS_CAT
00360 collInfo_t collInfo;
00361 #endif
00362 rodsServerHost_t *rodsServerHost = NULL;
00363
00364 status = getAndConnRcatHost (rsComm, MASTER_RCAT, rmCollInp->collName,
00365 &rodsServerHost);
00366 if (status < 0 || NULL == rodsServerHost ) {
00367 return(status);
00368 }
00369
00370 if (rodsServerHost->localFlag == LOCAL_HOST) {
00371 #ifdef RODS_CAT
00372 memset (&collInfo, 0, sizeof (collInfo));
00373 rstrcpy (collInfo.collName, rmCollInp->collName, MAX_NAME_LEN);
00374 if (getValByKey (&rmCollInp->condInput, IRODS_ADMIN_RMTRASH_KW)
00375 != NULL) {
00376 status = chlDelCollByAdmin (rsComm, &collInfo);
00377 if (status >= 0) {
00378 chlCommit(rsComm);
00379 }
00380 } else {
00381 status = chlDelColl (rsComm, &collInfo);
00382 }
00383
00384 #else
00385 status = SYS_NO_RCAT_SERVER_ERR;
00386 #endif
00387 } else {
00388 collOprStat_t *collOprStat = NULL;;
00389 addKeyVal (&rmCollInp->condInput, UNREG_COLL_KW, "");
00390 status = _rcRmColl (rodsServerHost->conn, rmCollInp, &collOprStat);
00391 if (collOprStat != NULL) free (collOprStat);
00392 }
00393
00394 return status;
00395 }
00396
00397 #ifdef COMPAT_201
00398 int
00399 rsRmColl201 (rsComm_t *rsComm, collInp201_t *rmCollInp,
00400 collOprStat_t **collOprStat)
00401 {
00402 collInp_t collInp;
00403 int status;
00404
00405 collInp201ToCollInp (rmCollInp, &collInp);
00406
00407 status = rsRmColl (rsComm, &collInp, collOprStat);
00408
00409 return status;
00410 }
00411 #endif
00412