int dataObjUnlinkS (rsComm_t *rsComm, dataObjInp_t *dataObjUnlinkInp, dataObjInfo_t *dataObjInfo) { int status; unregDataObj_t unregDataObjInp; if (dataObjInfo->specColl == NULL) { if (dataObjUnlinkInp->oprType == UNREG_OPR && rsComm->clientUser.authInfo.authFlag != LOCAL_PRIV_USER_AUTH) { ruleExecInfo_t rei; initReiWithDataObjInp (&rei, rsComm, dataObjUnlinkInp); rei.doi = dataObjInfo; rei.status = DO_CHK_PATH_PERM; /* default */ applyRule ("acSetChkFilePathPerm", NULL, &rei, NO_SAVE_REI); if (rei.status != NO_CHK_PATH_PERM) { char *outVaultPath; rodsServerHost_t *rodsServerHost; status = resolveHostByRescInfo (dataObjInfo->rescInfo, &rodsServerHost); if (status < 0) return status; /* unregistering but not an admin user */ status = matchVaultPath (rsComm, dataObjInfo->filePath, rodsServerHost, &outVaultPath); if (status != 0) { /* in the vault */ rodsLog (LOG_DEBUG, "dataObjUnlinkS: unregistering in vault file %s", dataObjInfo->filePath); return CANT_UNREG_IN_VAULT_FILE; } } #if 0 /* don't need this since we are doing orphan */ } else if (RescTypeDef[dataObjInfo->rescInfo->rescTypeInx].driverType == WOS_FILE_TYPE && dataObjUnlinkInp->oprType != UNREG_OPR) { /* WOS_FILE_TYPE, unlink first before unreg because orphan files * cannot be reclaimed */ status = l3Unlink (rsComm, dataObjInfo); if (status < 0) { rodsLog (LOG_NOTICE, "dataObjUnlinkS: l3Unlink error for WOS file %s. status = %d", dataObjUnlinkInp->objPath, status); return status; } unregDataObjInp.dataObjInfo = dataObjInfo; unregDataObjInp.condInput = &dataObjUnlinkInp->condInput; status = rsUnregDataObj (rsComm, &unregDataObjInp); if (status < 0) { rodsLog (LOG_NOTICE, "dataObjUnlinkS: rsUnregDataObj error for %s. status = %d", dataObjUnlinkInp->objPath, status); } return status; #endif } unregDataObjInp.dataObjInfo = dataObjInfo; unregDataObjInp.condInput = &dataObjUnlinkInp->condInput; status = rsUnregDataObj (rsComm, &unregDataObjInp); if (status < 0) { rodsLog (LOG_NOTICE, "dataObjUnlinkS: rsUnregDataObj error for %s. status = %d", dataObjUnlinkInp->objPath, status); return status; } } if (dataObjUnlinkInp->oprType != UNREG_OPR) { status = l3Unlink (rsComm, dataObjInfo); if (status < 0) { int myError = getErrno (status); rodsLog (LOG_NOTICE, "dataObjUnlinkS: l3Unlink error for %s. status = %d", dataObjUnlinkInp->objPath, status); /* allow ENOENT to go on and unregister */ if (myError != ENOENT && myError != EACCES) { char orphanPath[MAX_NAME_LEN]; int status1 = 0; rodsLog (LOG_NOTICE, "dataObjUnlinkS: orphan file %s", dataObjInfo->filePath); while (1) { if (isOrphanPath (dataObjUnlinkInp->objPath) == NOT_ORPHAN_PATH) { /* don't rename orphan path */ status1 = rsMkOrphanPath (rsComm, dataObjInfo->objPath, orphanPath); if (status1 < 0) break; /* reg the orphan path */ rstrcpy (dataObjInfo->objPath, orphanPath,MAX_NAME_LEN); } status1 = svrRegDataObj (rsComm, dataObjInfo); if (status1 == CAT_NAME_EXISTS_AS_DATAOBJ || status1 == CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME) { continue; } else if (status1 < 0) { rodsLogError (LOG_ERROR, status1, "dataObjUnlinkS: svrRegDataObj of orphan %s error", dataObjInfo->objPath); } break; } return (status); } else { status = 0; } } } return (status); }
int dataObjUnlinkS( rsComm_t *rsComm, dataObjInp_t *dataObjUnlinkInp, dataObjInfo_t *dataObjInfo ) { int status = 0; unregDataObj_t unregDataObjInp; if ( dataObjInfo->specColl == NULL ) { if ( dataObjUnlinkInp->oprType == UNREG_OPR && rsComm->clientUser.authInfo.authFlag != LOCAL_PRIV_USER_AUTH ) { ruleExecInfo_t rei; initReiWithDataObjInp( &rei, rsComm, dataObjUnlinkInp ); rei.doi = dataObjInfo; rei.status = DO_CHK_PATH_PERM; /* default */ // JMC - backport 4758 // make resource properties available as rule session variables rei.condInputData = (keyValPair_t *)malloc(sizeof(keyValPair_t)); memset(rei.condInputData, 0, sizeof(keyValPair_t)); irods::get_resc_properties_as_kvp(rei.doi->rescHier, rei.condInputData); applyRule( "acSetChkFilePathPerm", NULL, &rei, NO_SAVE_REI ); if ( rei.status != NO_CHK_PATH_PERM ) { // =-=-=-=-=-=-=- // extract the host location from the resource hierarchy std::string location; irods::error ret = irods::get_loc_for_hier_string( dataObjInfo->rescHier, location ); if ( !ret.ok() ) { irods::log( PASSMSG( "dataObjUnlinkS - failed in get_loc_for_hier_string", ret ) ); return ret.code(); } rodsHostAddr_t addr; rodsServerHost_t *rodsServerHost = 0; memset( &addr, 0, sizeof( addr ) ); rstrcpy( addr.hostAddr, location.c_str(), NAME_LEN ); int remoteFlag = resolveHost( &addr, &rodsServerHost ); if ( remoteFlag < 0 ) { // error condition? } /* unregistering but not an admin user */ std::string out_path; ret = resc_mgr.validate_vault_path( dataObjInfo->filePath, rodsServerHost, out_path ); if ( !ret.ok() ) { /* in the vault */ std::stringstream msg; msg << "unregistering a data object which is in a vault ["; msg << dataObjInfo->filePath << "]"; irods::log( PASSMSG( msg.str(), ret ) ); return CANT_UNREG_IN_VAULT_FILE; } } } unregDataObjInp.dataObjInfo = dataObjInfo; unregDataObjInp.condInput = &dataObjUnlinkInp->condInput; status = rsUnregDataObj( rsComm, &unregDataObjInp ); if ( status < 0 ) { rodsLog( LOG_NOTICE, "dataObjUnlinkS: rsUnregDataObj error for %s. status = %d", dataObjUnlinkInp->objPath, status ); return status; } } if ( dataObjUnlinkInp->oprType != UNREG_OPR ) { // Set the in_pdmo flag char* in_pdmo = getValByKey( &dataObjUnlinkInp->condInput, IN_PDMO_KW ); if ( in_pdmo != NULL ) { rstrcpy( dataObjInfo->in_pdmo, in_pdmo, MAX_NAME_LEN ); } else { dataObjInfo->in_pdmo[0] = '\0'; } status = l3Unlink( rsComm, dataObjInfo ); if ( status < 0 ) { int myError = getErrno( status ); rodsLog( LOG_NOTICE, "dataObjUnlinkS: l3Unlink error for %s. status = %d", dataObjUnlinkInp->objPath, status ); /* allow ENOENT to go on and unregister */ if ( myError != ENOENT && myError != EACCES ) { char orphanPath[MAX_NAME_LEN]; int status1 = 0; rodsLog( LOG_NOTICE, "dataObjUnlinkS: orphan file %s", dataObjInfo->filePath ); while ( 1 ) { if ( isOrphanPath( dataObjUnlinkInp->objPath ) == NOT_ORPHAN_PATH ) { /* don't rename orphan path */ status1 = rsMkOrphanPath( rsComm, dataObjInfo->objPath, orphanPath ); if ( status1 < 0 ) { break; } /* reg the orphan path */ rstrcpy( dataObjInfo->objPath, orphanPath, MAX_NAME_LEN ); } status1 = svrRegDataObj( rsComm, dataObjInfo ); if ( status1 == CAT_NAME_EXISTS_AS_DATAOBJ || status1 == CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME ) { continue; } else if ( status1 < 0 ) { rodsLogError( LOG_ERROR, status1, "dataObjUnlinkS: svrRegDataObj of orphan %s error", dataObjInfo->objPath ); } break; } return status; } else { status = 0; } } } return status; }