00001
00002
00003
00004
00005
00006
00007 #include "dataObjTrim.h"
00008 #include "dataObjUnlink.h"
00009 #include "dataObjOpr.h"
00010 #include "rodsLog.h"
00011 #include "objMetaOpr.h"
00012 #include "specColl.h"
00013 #include "reGlobalsExtern.h"
00014 #include "reDefines.h"
00015 #include "reSysDataObjOpr.h"
00016 #include "getRemoteZoneResc.h"
00017
00018
00019 #include "eirods_resource_redirect.h"
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 int
00031 rsDataObjTrim (rsComm_t *rsComm, dataObjInp_t *dataObjInp)
00032 {
00033 int status;
00034 dataObjInfo_t *dataObjInfoHead = NULL;
00035 dataObjInfo_t *tmpDataObjInfo;
00036 char *accessPerm;
00037 int retVal = 0;
00038 int remoteFlag;
00039 rodsServerHost_t *rodsServerHost;
00040 specCollCache_t *specCollCache = NULL;
00041 int myTime = 0;
00042 char *tmpStr;
00043 int myAge;
00044
00045 resolveLinkedPath (rsComm, dataObjInp->objPath, &specCollCache,
00046 &dataObjInp->condInput);
00047 remoteFlag = getAndConnRemoteZone (rsComm, dataObjInp, &rodsServerHost,
00048 REMOTE_OPEN);
00049
00050 if (remoteFlag < 0) {
00051 return (remoteFlag);
00052 } else if (remoteFlag == REMOTE_HOST) {
00053 status = rcDataObjTrim (rodsServerHost->conn, dataObjInp);
00054 return status;
00055 }
00056
00057
00058
00059
00060
00061 std::string hier;
00062 int local = LOCAL_HOST;
00063 rodsServerHost_t* host = 0;
00064 char* hier_char = getValByKey( &dataObjInp->condInput, RESC_HIER_STR_KW );
00065 if( hier_char == NULL ) {
00066 eirods::error ret = eirods::resource_redirect( eirods::EIRODS_CREATE_OPERATION, rsComm,
00067 dataObjInp, hier, host, local );
00068 if( !ret.ok() ) {
00069 std::stringstream msg;
00070 msg << __FUNCTION__;
00071 msg << " :: failed in eirods::resource_redirect for [";
00072 msg << dataObjInp->objPath << "]";
00073 eirods::log( PASSMSG( msg.str(), ret ) );
00074 return ret.code();
00075 }
00076
00077
00078
00079 addKeyVal( &dataObjInp->condInput, RESC_HIER_STR_KW, hier.c_str() );
00080
00081 }
00082
00083 if (getValByKey (&dataObjInp->condInput, IRODS_ADMIN_KW) != NULL) {
00084 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
00085 return (CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
00086 }
00087 accessPerm = NULL;
00088 } else {
00089 accessPerm = ACCESS_DELETE_OBJECT;
00090 }
00091
00092 status = getDataObjInfo (rsComm, dataObjInp, &dataObjInfoHead,
00093 accessPerm, 1);
00094
00095 if (status < 0) {
00096 rodsLog (LOG_ERROR,
00097 "rsDataObjTrim: getDataObjInfo for %s", dataObjInp->objPath);
00098 return (status);
00099 }
00100 status = resolveInfoForTrim (&dataObjInfoHead, &dataObjInp->condInput);
00101
00102 if (status < 0) {
00103 return (status);
00104 }
00105
00106 if ((tmpStr = getValByKey (&dataObjInp->condInput, AGE_KW)) != NULL) {
00107 myAge = atoi (tmpStr);
00108
00109 if (myAge > 0) myTime = time (0) - myAge * 60;
00110 }
00111
00112 tmpDataObjInfo = dataObjInfoHead;
00113 while (tmpDataObjInfo != NULL) {
00114 if (myTime == 0 || atoi (tmpDataObjInfo->dataModify) <= myTime) {
00115 if (getValByKey (&dataObjInp->condInput, DRYRUN_KW) == NULL) {
00116 status = dataObjUnlinkS (rsComm, dataObjInp, tmpDataObjInfo);
00117 if (status < 0) {
00118 if (retVal == 0) {
00119 retVal = status;
00120 }
00121 } else {
00122 retVal = 1;
00123 }
00124 } else {
00125 retVal = 1;
00126 }
00127 }
00128 tmpDataObjInfo = tmpDataObjInfo->next;
00129 }
00130
00131 freeAllDataObjInfo (dataObjInfoHead);
00132
00133 return (retVal);
00134 }
00135
00136
00137 int
00138 trimDataObjInfo (rsComm_t *rsComm, dataObjInfo_t *dataObjInfo)
00139 {
00140 dataObjInp_t dataObjInp;
00141 char tmpStr[NAME_LEN];
00142 int status;
00143
00144 bzero (&dataObjInp, sizeof (dataObjInp));
00145 rstrcpy (dataObjInp.objPath, dataObjInfo->objPath, MAX_NAME_LEN);
00146 snprintf (tmpStr, NAME_LEN, "1");
00147 addKeyVal (&dataObjInp.condInput, COPIES_KW, tmpStr);
00148 addKeyVal (&dataObjInp.condInput, RESC_NAME_KW,
00149 dataObjInfo->rescInfo->rescName);
00150 status = rsDataObjTrim (rsComm, &dataObjInp);
00151 clearKeyVal (&dataObjInp.condInput);
00152 if (status < 0) {
00153 rodsLogError (LOG_ERROR, status,
00154 "trimDataObjInfo: rsDataObjTrim of %s error", dataObjInfo->objPath);
00155 }
00156 return status;
00157 }
00158