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