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
00067 addKeyVal(&dataObjInp->condInput, IN_REPL_KW, "");
00068
00069 eirods::error ret = eirods::resource_redirect( eirods::EIRODS_CREATE_OPERATION, rsComm,
00070 dataObjInp, hier, host, local );
00071 if( !ret.ok() ) {
00072 std::stringstream msg;
00073 msg << __FUNCTION__;
00074 msg << " :: failed in eirods::resource_redirect for [";
00075 msg << dataObjInp->objPath << "]";
00076 eirods::log( PASSMSG( msg.str(), ret ) );
00077 return ret.code();
00078 }
00079
00080
00081
00082 addKeyVal( &dataObjInp->condInput, RESC_HIER_STR_KW, hier.c_str() );
00083
00084 }
00085
00086 if (getValByKey (&dataObjInp->condInput, IRODS_ADMIN_KW) != NULL) {
00087 if (rsComm->clientUser.authInfo.authFlag < LOCAL_PRIV_USER_AUTH) {
00088 return (CAT_INSUFFICIENT_PRIVILEGE_LEVEL);
00089 }
00090 accessPerm = NULL;
00091 } else {
00092 accessPerm = ACCESS_DELETE_OBJECT;
00093 }
00094
00095 status = getDataObjInfo (rsComm, dataObjInp, &dataObjInfoHead,
00096 accessPerm, 1);
00097
00098 if (status < 0) {
00099 rodsLog (LOG_ERROR,
00100 "rsDataObjTrim: getDataObjInfo for %s", dataObjInp->objPath);
00101 return (status);
00102 }
00103 status = resolveInfoForTrim (&dataObjInfoHead, &dataObjInp->condInput);
00104
00105 if (status < 0) {
00106 return (status);
00107 }
00108
00109 if ((tmpStr = getValByKey (&dataObjInp->condInput, AGE_KW)) != NULL) {
00110 myAge = atoi (tmpStr);
00111
00112 if (myAge > 0) myTime = time (0) - myAge * 60;
00113 }
00114
00115 tmpDataObjInfo = dataObjInfoHead;
00116 while (tmpDataObjInfo != NULL) {
00117 if (myTime == 0 || atoi (tmpDataObjInfo->dataModify) <= myTime) {
00118 if (getValByKey (&dataObjInp->condInput, DRYRUN_KW) == NULL) {
00119 status = dataObjUnlinkS (rsComm, dataObjInp, tmpDataObjInfo);
00120 if (status < 0) {
00121 if (retVal == 0) {
00122 retVal = status;
00123 }
00124 } else {
00125 retVal = 1;
00126 }
00127 } else {
00128 retVal = 1;
00129 }
00130 }
00131 tmpDataObjInfo = tmpDataObjInfo->next;
00132 }
00133
00134 freeAllDataObjInfo (dataObjInfoHead);
00135
00136 return (retVal);
00137 }
00138
00139
00140 int
00141 trimDataObjInfo (rsComm_t *rsComm, dataObjInfo_t *dataObjInfo)
00142 {
00143 dataObjInp_t dataObjInp;
00144 char tmpStr[NAME_LEN];
00145 int status;
00146
00147 bzero (&dataObjInp, sizeof (dataObjInp));
00148 rstrcpy (dataObjInp.objPath, dataObjInfo->objPath, MAX_NAME_LEN);
00149 snprintf (tmpStr, NAME_LEN, "1");
00150 addKeyVal (&dataObjInp.condInput, COPIES_KW, tmpStr);
00151 addKeyVal (&dataObjInp.condInput, RESC_NAME_KW,
00152 dataObjInfo->rescInfo->rescName);
00153 status = rsDataObjTrim (rsComm, &dataObjInp);
00154 clearKeyVal (&dataObjInp.condInput);
00155 if (status < 0) {
00156 rodsLogError (LOG_ERROR, status,
00157 "trimDataObjInfo: rsDataObjTrim of %s error", dataObjInfo->objPath);
00158 }
00159 return status;
00160 }
00161