00001
00002
00003
00004
00005
00006
00007
00008 #include "dataObjUnlink.h"
00009 #include "rodsLog.h"
00010 #include "icatDefines.h"
00011 #include "fileUnlink.h"
00012 #include "unregDataObj.h"
00013 #include "objMetaOpr.h"
00014 #include "dataObjOpr.h"
00015 #include "specColl.h"
00016 #include "resource.h"
00017 #include "rsGlobalExtern.h"
00018 #include "rcGlobalExtern.h"
00019 #include "reGlobalsExtern.h"
00020 #include "reDefines.h"
00021 #include "rmCollOld.h"
00022 #include "rmColl.h"
00023 #include "dataObjRename.h"
00024 #include "subStructFileUnlink.h"
00025 #include "modDataObjMeta.h"
00026 #include "phyBundleColl.h"
00027 #include "dataObjRepl.h"
00028 #include "regDataObj.h"
00029 #include "physPath.h"
00030
00031
00032
00033 #include "eirods_resource_backport.h"
00034 #include "eirods_resource_redirect.h"
00035 #include "eirods_hierarchy_parser.h"
00036
00037 int
00038 rsDataObjUnlink (rsComm_t *rsComm, dataObjInp_t *dataObjUnlinkInp)
00039 {
00040 int status;
00041 ruleExecInfo_t rei;
00042 int trashPolicy;
00043 dataObjInfo_t *dataObjInfoHead = NULL;
00044 rodsServerHost_t *rodsServerHost = NULL;
00045 int rmTrashFlag = 0;
00046 specCollCache_t *specCollCache = NULL;
00047
00048 resolveLinkedPath (rsComm, dataObjUnlinkInp->objPath, &specCollCache,
00049 &dataObjUnlinkInp->condInput);
00050 status = getAndConnRcatHost (rsComm, MASTER_RCAT,
00051 dataObjUnlinkInp->objPath, &rodsServerHost);
00052
00053 if (status < 0 || NULL == rodsServerHost ) {
00054 return (status);
00055 } else if (rodsServerHost->rcatEnabled == REMOTE_ICAT) {
00056 rcDataObjUnlink (rodsServerHost->conn, dataObjUnlinkInp);
00057 return status;
00058 }
00059
00060 #ifdef COMMENT
00061
00062
00063
00064
00065 int local = LOCAL_HOST;
00066 std::string hier;
00067 char* hier_keyword = getValByKey( &dataObjUnlinkInp->condInput, RESC_HIER_STR_KW );
00068 if( hier_keyword == NULL ) {
00069 rodsServerHost_t* host = 0;
00070 eirods::error ret = eirods::resource_redirect( eirods::EIRODS_OPEN_OPERATION, rsComm,
00071 dataObjUnlinkInp, hier, host, local );
00072 if( !ret.ok() ) {
00073 std::stringstream msg;
00074 msg << "rsDataObjUnlink :: failed in eirods::resource_redirect for [";
00075 msg << dataObjUnlinkInp->objPath << "]";
00076 eirods::log( PASSMSG( msg.str(), ret ) );
00077 return ret.code();
00078 }
00079
00080
00081
00082
00083 addKeyVal( &dataObjUnlinkInp->condInput, RESC_HIER_STR_KW, hier.c_str() );
00084
00085 }
00086
00087 if( LOCAL_HOST != local ) {
00088 rodsLog( LOG_NOTICE, "%s - resource_redirect requested remote server for [%s], hier string [%s]",
00089 __FUNCTION__, dataObjUnlinkInp->objPath, hier.c_str() );
00090 }
00091 #endif
00092
00093 if (getValByKey (
00094 &dataObjUnlinkInp->condInput, IRODS_ADMIN_RMTRASH_KW) != NULL ||
00095 getValByKey (
00096 &dataObjUnlinkInp->condInput, IRODS_RMTRASH_KW) != NULL) {
00097 if (isTrashPath (dataObjUnlinkInp->objPath) == False) {
00098 return (SYS_INVALID_FILE_PATH);
00099 }
00100 rmTrashFlag = 1;
00101 }
00102
00103 dataObjUnlinkInp->openFlags = O_WRONLY;
00104 status = getDataObjInfoIncSpecColl (rsComm, dataObjUnlinkInp,
00105 &dataObjInfoHead);
00106
00107 if (status < 0) {
00108 char* sys_error;
00109 char* rods_error = rodsErrorName(status, &sys_error);
00110 std::stringstream msg;
00111 msg << __FUNCTION__;
00112 msg << " - Failed to get data objects.";
00113 msg << " - " << rods_error << " " << sys_error;
00114 eirods::error result = ERROR(status, msg.str());
00115 eirods::log(result);
00116 return (status);
00117 }
00118
00119 if (rmTrashFlag == 1) {
00120 char *tmpAge;
00121 int ageLimit;
00122 if ((tmpAge = getValByKey (&dataObjUnlinkInp->condInput, AGE_KW))
00123 != NULL) {
00124 ageLimit = atoi (tmpAge) * 60;
00125 if ((time (0) - atoi (dataObjInfoHead->dataModify)) < ageLimit) {
00126
00127 freeAllDataObjInfo (dataObjInfoHead);
00128 return 0;
00129 }
00130 }
00131 }
00132
00133 if (dataObjUnlinkInp->oprType == UNREG_OPR ||
00134 getValByKey (&dataObjUnlinkInp->condInput, FORCE_FLAG_KW) != NULL ||
00135 getValByKey (&dataObjUnlinkInp->condInput, REPL_NUM_KW) != NULL ||
00136 dataObjInfoHead->specColl != NULL || rmTrashFlag == 1) {
00137 status = _rsDataObjUnlink (rsComm, dataObjUnlinkInp, &dataObjInfoHead);
00138 } else {
00139 initReiWithDataObjInp (&rei, rsComm, dataObjUnlinkInp);
00140 status = applyRule ("acTrashPolicy", NULL, &rei, NO_SAVE_REI);
00141 trashPolicy = rei.status;
00142
00143 if (trashPolicy != NO_TRASH_CAN) {
00144 status = rsMvDataObjToTrash (rsComm, dataObjUnlinkInp,
00145 &dataObjInfoHead);
00146 freeAllDataObjInfo (dataObjInfoHead);
00147 return status;
00148 } else {
00149 status = _rsDataObjUnlink (rsComm, dataObjUnlinkInp,
00150 &dataObjInfoHead);
00151 }
00152 }
00153
00154 initReiWithDataObjInp (&rei, rsComm, dataObjUnlinkInp);
00155 rei.doi = dataObjInfoHead;
00156 rei.status = status;
00157 rei.status = applyRule ("acPostProcForDelete", NULL, &rei, NO_SAVE_REI);
00158
00159 if (rei.status < 0) {
00160 rodsLog (LOG_NOTICE,
00161 "rsDataObjUnlink: acPostProcForDelete error for %s. status = %d",
00162 dataObjUnlinkInp->objPath, rei.status);
00163 }
00164
00165
00166 freeAllDataObjInfo (dataObjInfoHead);
00167
00168 return (status);
00169 }
00170
00171 int
00172 _rsDataObjUnlink (rsComm_t *rsComm, dataObjInp_t *dataObjUnlinkInp,
00173 dataObjInfo_t **dataObjInfoHead)
00174 {
00175 int status;
00176 int retVal = 0;
00177 dataObjInfo_t *tmpDataObjInfo, *myDataObjInfoHead;
00178
00179 status = chkPreProcDeleteRule (rsComm, dataObjUnlinkInp, *dataObjInfoHead);
00180 if (status < 0) return status;
00181
00182
00183 myDataObjInfoHead = *dataObjInfoHead;
00184 if (strstr (myDataObjInfoHead->dataType, BUNDLE_STR) != NULL) {
00185 int numSubfiles;
00186 if (rsComm->proxyUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
00187 return CAT_INSUFFICIENT_PRIVILEGE_LEVEL;
00188 }
00189 if (getValByKey (&dataObjUnlinkInp->condInput, REPL_NUM_KW) != NULL) {
00190 return SYS_CANT_MV_BUNDLE_DATA_BY_COPY;
00191 }
00192
00193
00194
00195 numSubfiles = getNumSubfilesInBunfileObj (rsComm, myDataObjInfoHead->objPath);
00196 if (numSubfiles > 0) {
00197 if (getValByKey (&dataObjUnlinkInp->condInput, EMPTY_BUNDLE_ONLY_KW) != NULL) {
00198
00199 return 0;
00200 } else {
00201 status = _unbunAndStageBunfileObj (rsComm, dataObjInfoHead, NULL, 1);
00202 if (status < 0) {
00203
00204
00205 if (getErrno (status) != EEXIST && getIrodsErrno (status) != SYS_TAR_STRUCT_FILE_EXTRACT_ERR) {
00206 rodsLogError( LOG_ERROR, status, "_rsDataObjUnlink:_unbunAndStageBunfileObj err for %s",
00207 myDataObjInfoHead->objPath);
00208 return (status);
00209 }
00210 }
00211
00212 *dataObjInfoHead = NULL;
00213 status = getDataObjInfoIncSpecColl (rsComm, dataObjUnlinkInp, dataObjInfoHead );
00214
00215 if (status < 0) return (status);
00216 }
00217 }
00218 }
00219
00220
00221 char* rescHier = getValByKey(&dataObjUnlinkInp->condInput, RESC_HIER_STR_KW);
00222
00223 tmpDataObjInfo = *dataObjInfoHead;
00224 while (tmpDataObjInfo != NULL) {
00225 status = dataObjUnlinkS (rsComm, dataObjUnlinkInp, tmpDataObjInfo);
00226 if (status < 0) {
00227 if (retVal == 0) {
00228 retVal = status;
00229 }
00230 }
00231 if (dataObjUnlinkInp->specColl != NULL)
00232 break;
00233 tmpDataObjInfo = tmpDataObjInfo->next;
00234 }
00235
00236 if ((*dataObjInfoHead)->specColl == NULL)
00237 resolveDataObjReplStatus (rsComm, dataObjUnlinkInp);
00238
00239 return (retVal);
00240 }
00241
00242
00243
00244
00245 int
00246 resolveDataObjReplStatus (rsComm_t *rsComm, dataObjInp_t *dataObjUnlinkInp)
00247 {
00248 int status;
00249 dataObjInfo_t *dataObjInfoHead = NULL;
00250 dataObjInfo_t *newestDataObjInfo = NULL;
00251 dataObjInfo_t *tmpDataObjInfo;
00252
00253 if (getValByKey (&dataObjUnlinkInp->condInput, RESC_NAME_KW) == NULL &&
00254 getValByKey (&dataObjUnlinkInp->condInput, REPL_NUM_KW) == NULL) {
00255 return 0;
00256 }
00257 status = getDataObjInfo (rsComm, dataObjUnlinkInp,
00258 &dataObjInfoHead, ACCESS_DELETE_OBJECT, 1);
00259
00260 if (status < 0) return status;
00261
00262 tmpDataObjInfo = dataObjInfoHead;
00263 while (tmpDataObjInfo != NULL) {
00264 if (tmpDataObjInfo->replStatus == 0) {
00265 if (newestDataObjInfo == NULL) {
00266 newestDataObjInfo = tmpDataObjInfo;
00267 } else if (atoi (tmpDataObjInfo->dataModify) >
00268 atoi (newestDataObjInfo->dataModify)) {
00269 newestDataObjInfo = tmpDataObjInfo;
00270 }
00271 } else {
00272 newestDataObjInfo = NULL;
00273 break;
00274 }
00275 tmpDataObjInfo = tmpDataObjInfo->next;
00276 }
00277
00278
00279 if (newestDataObjInfo != NULL) {
00280 keyValPair_t regParam;
00281 char tmpStr[MAX_NAME_LEN];
00282 modDataObjMeta_t modDataObjMetaInp;
00283
00284 memset (®Param, 0, sizeof (regParam));
00285 memset (&modDataObjMetaInp, 0, sizeof (modDataObjMetaInp));
00286 snprintf (tmpStr, MAX_NAME_LEN, "%d", NEWLY_CREATED_COPY);
00287 addKeyVal (®Param, REPL_STATUS_KW, tmpStr);
00288 modDataObjMetaInp.dataObjInfo = newestDataObjInfo;
00289 modDataObjMetaInp.regParam = ®Param;
00290
00291 status = rsModDataObjMeta (rsComm, &modDataObjMetaInp);
00292
00293 clearKeyVal (®Param);
00294 }
00295 freeAllDataObjInfo (dataObjInfoHead);
00296 return (status);
00297 }
00298
00299 int
00300 dataObjUnlinkS (rsComm_t *rsComm, dataObjInp_t *dataObjUnlinkInp,
00301 dataObjInfo_t *dataObjInfo)
00302 {
00303 int status;
00304 unregDataObj_t unregDataObjInp;
00305
00306 if( dataObjInfo->specColl == NULL ) {
00307 if( dataObjUnlinkInp->oprType == UNREG_OPR &&
00308 rsComm->clientUser.authInfo.authFlag != LOCAL_PRIV_USER_AUTH ) {
00309 ruleExecInfo_t rei;
00310
00311 initReiWithDataObjInp (&rei, rsComm, dataObjUnlinkInp);
00312 rei.doi = dataObjInfo;
00313 rei.status = DO_CHK_PATH_PERM;
00314
00315 applyRule ("acSetChkFilePathPerm", NULL, &rei, NO_SAVE_REI);
00316 if (rei.status != NO_CHK_PATH_PERM) {
00317 char *outVaultPath;
00318 rodsServerHost_t *rodsServerHost;
00319 status = resolveHostByRescInfo (dataObjInfo->rescInfo,
00320 &rodsServerHost);
00321 if (status < 0) return status;
00322
00323 status = matchVaultPath (rsComm, dataObjInfo->filePath, rodsServerHost, &outVaultPath);
00324 if (status != 0) {
00325
00326 rodsLog (LOG_DEBUG,
00327 "dataObjUnlinkS: unregistering in vault file %s",
00328 dataObjInfo->filePath);
00329 return CANT_UNREG_IN_VAULT_FILE;
00330 }
00331 }
00332 }
00333
00334 unregDataObjInp.dataObjInfo = dataObjInfo;
00335 unregDataObjInp.condInput = &dataObjUnlinkInp->condInput;
00336 status = rsUnregDataObj (rsComm, &unregDataObjInp);
00337
00338 if (status < 0) {
00339 rodsLog (LOG_NOTICE,
00340 "dataObjUnlinkS: rsUnregDataObj error for %s. status = %d",
00341 dataObjUnlinkInp->objPath, status);
00342 return status;
00343 }
00344 }
00345
00346 if (dataObjUnlinkInp->oprType != UNREG_OPR) {
00347
00348
00349 char* in_pdmo = getValByKey(&dataObjUnlinkInp->condInput, IN_PDMO_KW);
00350 if(in_pdmo != NULL) {
00351 dataObjInfo->in_pdmo = 1;
00352 } else {
00353 dataObjInfo->in_pdmo = 0;
00354 }
00355
00356 status = l3Unlink (rsComm, dataObjInfo);
00357 if (status < 0) {
00358 int myError = getErrno (status);
00359 rodsLog (LOG_NOTICE,
00360 "dataObjUnlinkS: l3Unlink error for %s. status = %d",
00361 dataObjUnlinkInp->objPath, status);
00362
00363 if (myError != ENOENT && myError != EACCES) {
00364 char orphanPath[MAX_NAME_LEN];
00365 int status1 = 0;
00366 rodsLog (LOG_NOTICE,
00367 "dataObjUnlinkS: orphan file %s", dataObjInfo->filePath);
00368 while (1) {
00369 if (isOrphanPath (dataObjUnlinkInp->objPath) ==
00370 NOT_ORPHAN_PATH) {
00371
00372 status1 = rsMkOrphanPath (rsComm, dataObjInfo->objPath,
00373 orphanPath);
00374 if (status1 < 0) break;
00375
00376 rstrcpy (dataObjInfo->objPath, orphanPath,MAX_NAME_LEN);
00377 }
00378 status1 = svrRegDataObj (rsComm, dataObjInfo);
00379 if (status1 == CAT_NAME_EXISTS_AS_DATAOBJ ||
00380 status1 == CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME) {
00381 continue;
00382 } else if (status1 < 0) {
00383 rodsLogError (LOG_ERROR, status1,
00384 "dataObjUnlinkS: svrRegDataObj of orphan %s error",
00385 dataObjInfo->objPath);
00386 }
00387 break;
00388 }
00389 return (status);
00390 } else {
00391 status = 0;
00392 }
00393 }
00394 }
00395
00396 return (status);
00397 }
00398
00399 int
00400 l3Unlink (rsComm_t *rsComm, dataObjInfo_t *dataObjInfo)
00401 {
00402 fileUnlinkInp_t fileUnlinkInp;
00403 int status;
00404
00405
00406
00407 std::string resc_class;
00408 eirods::error prop_err = eirods::get_resource_property<std::string>( dataObjInfo->rescInfo->rescName, "class", resc_class );
00409 if( prop_err.ok() ) {
00410 if( resc_class == "bundle" ) {
00411 return 0;
00412 }
00413 } else {
00414 std::stringstream msg;
00415 msg << "failed to get proprty [class] for resource [";
00416 msg << dataObjInfo->rescInfo->rescName;
00417 msg << "]";
00418 eirods::log( PASSMSG( msg.str(), prop_err ) );
00419 return -1;
00420 }
00421
00422
00423
00424
00425 std::string location;
00426 eirods::error ret = eirods::get_loc_for_hier_string( dataObjInfo->rescHier, location );
00427 if( !ret.ok() ) {
00428 eirods::log( PASSMSG( "failed in get_loc_for_hier_String", ret ) );
00429 return -1;
00430 }
00431
00432
00433 if (dataObjInfo->rescInfo->rescStatus == INT_RESC_STATUS_DOWN)
00434 return SYS_RESC_IS_DOWN;
00435
00436 if (getStructFileType (dataObjInfo->specColl) >= 0) {
00437 subFile_t subFile;
00438 memset (&subFile, 0, sizeof (subFile));
00439 rstrcpy ( subFile.subFilePath, dataObjInfo->subPath,MAX_NAME_LEN);
00440 rstrcpy ( subFile.addr.hostAddr, location.c_str(), NAME_LEN );
00441 subFile.specColl = dataObjInfo->specColl;
00442 status = rsSubStructFileUnlink (rsComm, &subFile);
00443 } else {
00444 #if 0 // JMC - legacy resource
00445 rescTypeInx = dataObjInfo->rescInfo->rescTypeInx;
00446 switch (RescTypeDef[rescTypeInx].rescCat) {
00447 case FILE_CAT:
00448 #endif // JMC - legacy resource
00449 memset (&fileUnlinkInp, 0, sizeof (fileUnlinkInp));
00450 fileUnlinkInp.fileType = static_cast< fileDriverType_t >( -1 );
00451 rstrcpy (fileUnlinkInp.fileName, dataObjInfo->filePath, MAX_NAME_LEN);
00452 rstrcpy (fileUnlinkInp.rescHier, dataObjInfo->rescHier, MAX_NAME_LEN);
00453 rstrcpy (fileUnlinkInp.addr.hostAddr, location.c_str(), NAME_LEN);
00454 rstrcpy (fileUnlinkInp.objPath, dataObjInfo->objPath, MAX_NAME_LEN);
00455 fileUnlinkInp.in_pdmo = dataObjInfo->in_pdmo;
00456 status = rsFileUnlink (rsComm, &fileUnlinkInp);
00457 #if 0 // JMC - legacy resource
00458 break;
00459
00460 default:
00461 rodsLog (LOG_NOTICE,
00462 "l3Unlink: rescCat type %d is not recognized",
00463 RescTypeDef[rescTypeInx].rescCat);
00464 status = SYS_INVALID_RESC_TYPE;
00465 break;
00466 }
00467 #endif // JMC - legacy resource
00468 }
00469 return (status);
00470 }
00471
00472 int
00473 rsMvDataObjToTrash (rsComm_t *rsComm, dataObjInp_t *dataObjInp,
00474 dataObjInfo_t **dataObjInfoHead)
00475 {
00476 int status;
00477 char trashPath[MAX_NAME_LEN];
00478 dataObjCopyInp_t dataObjRenameInp;
00479
00480 if (strstr ((*dataObjInfoHead)->dataType, BUNDLE_STR) != NULL) {
00481 return SYS_CANT_MV_BUNDLE_DATA_TO_TRASH;
00482 }
00483
00484 if (getValByKey (&dataObjInp->condInput, DATA_ACCESS_KW) == NULL) {
00485 addKeyVal (&dataObjInp->condInput, DATA_ACCESS_KW,
00486 ACCESS_DELETE_OBJECT);
00487 }
00488
00489 status = getDataObjInfo (rsComm, dataObjInp, dataObjInfoHead,
00490 ACCESS_DELETE_OBJECT, 0);
00491 if (status < 0) {
00492 rodsLog (LOG_NOTICE,
00493 "rsMvDataObjToTrash: getDataObjInfo error for %s. status = %d",
00494 dataObjInp->objPath, status);
00495 return (status);
00496 }
00497
00498 status = chkPreProcDeleteRule (rsComm, dataObjInp, *dataObjInfoHead);
00499 if (status < 0) return status;
00500
00501
00502 status = rsMkTrashPath (rsComm, dataObjInp->objPath, trashPath);
00503
00504 if (status < 0) {
00505 return (status);
00506 }
00507
00508 memset (&dataObjRenameInp, 0, sizeof (dataObjRenameInp));
00509
00510 dataObjRenameInp.srcDataObjInp.oprType =
00511 dataObjRenameInp.destDataObjInp.oprType = RENAME_DATA_OBJ;
00512
00513 rstrcpy (dataObjRenameInp.destDataObjInp.objPath, trashPath, MAX_NAME_LEN);
00514 rstrcpy (dataObjRenameInp.srcDataObjInp.objPath, dataObjInp->objPath,
00515 MAX_NAME_LEN);
00516
00517 status = rsDataObjRename (rsComm, &dataObjRenameInp);
00518
00519 while (status == CAT_NAME_EXISTS_AS_DATAOBJ ||
00520 status == CAT_NAME_EXISTS_AS_COLLECTION ||
00521 status == SYS_PHY_PATH_INUSE ||
00522 getErrno (status) == EISDIR) {
00523 appendRandomToPath (dataObjRenameInp.destDataObjInp.objPath);
00524 status = rsDataObjRename (rsComm, &dataObjRenameInp);
00525 }
00526 if (status < 0) {
00527 rodsLog (LOG_ERROR,
00528 "rsMvDataObjToTrash: rcDataObjRename error for %s, status = %d",
00529 dataObjRenameInp.destDataObjInp.objPath, status);
00530 return (status);
00531 }
00532 return (status);
00533 }
00534
00535 int
00536 chkPreProcDeleteRule (rsComm_t *rsComm, dataObjInp_t *dataObjUnlinkInp,
00537 dataObjInfo_t *dataObjInfoHead)
00538 {
00539 dataObjInfo_t *tmpDataObjInfo;
00540 ruleExecInfo_t rei;
00541 int status = 0;
00542
00543 initReiWithDataObjInp (&rei, rsComm, dataObjUnlinkInp);
00544 tmpDataObjInfo = dataObjInfoHead;
00545 while (tmpDataObjInfo != NULL) {
00546
00547 rei.doi = tmpDataObjInfo;
00548
00549 status = applyRule ("acDataDeletePolicy", NULL, &rei, NO_SAVE_REI);
00550
00551 if (status < 0 && status != NO_MORE_RULES_ERR &&
00552 status != SYS_DELETE_DISALLOWED) {
00553 rodsLog (LOG_ERROR,
00554 "chkPreProcDeleteRule: acDataDeletePolicy err for %s. stat = %d",
00555 dataObjUnlinkInp->objPath, status);
00556 return (status);
00557 }
00558
00559 if (rei.status == SYS_DELETE_DISALLOWED) {
00560 rodsLog (LOG_ERROR,
00561 "chkPreProcDeleteRule:acDataDeletePolicy disallowed delete of %s",
00562 dataObjUnlinkInp->objPath);
00563 return (rei.status);
00564 }
00565 tmpDataObjInfo = tmpDataObjInfo->next;
00566 }
00567 return status;
00568 }