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