irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

rmtrashUtil.cpp
Go to the documentation of this file.
1 
3 #ifndef windows_platform
4 #include <sys/time.h>
5 #endif
6 #include "rodsPath.h"
7 #include "rodsErrorTable.h"
8 #include "miscUtil.h"
9 #include "rodsLog.h"
10 #include "rmtrashUtil.h"
11 #include "rcGlobalExtern.h"
12 
13 int
14 rmtrashUtil( rcComm_t *conn, rodsArguments_t *myRodsArgs,
15  rodsPathInp_t *rodsPathInp ) {
16  int i = 0;
17  int status = 0;
18  int savedStatus = 0;
19  collInp_t collInp;
20  dataObjInp_t dataObjInp;
21 
22 
23  if ( rodsPathInp == NULL ) {
24  return USER__NULL_INPUT_ERR;
25  }
26 
27  initCondForRmtrash( myRodsArgs, &dataObjInp, &collInp );
28 
29  if ( rodsPathInp->numSrc <= 0 ) {
30  char trashPath[MAX_NAME_LEN];
31  char *myZoneName;
32  char myZoneType[MAX_NAME_LEN];
33 
34  if ( myRodsArgs->zoneName != NULL ) {
35  myZoneName = myRodsArgs->zoneName;
36  }
37  else {
38  myZoneName = conn->clientUser.rodsZone;
39  }
40  if ( myRodsArgs->admin == True ) {
41  if ( myRodsArgs->user == True ) {
42  snprintf( trashPath, MAX_NAME_LEN, "/%s/trash/home/%s",
43  myZoneName, myRodsArgs->userString );
44  }
45  else if ( myRodsArgs->orphan == True ) {
46  snprintf( trashPath, MAX_NAME_LEN, "/%s/trash/orphan",
47  myZoneName );
48  }
49  else {
50  snprintf( trashPath, MAX_NAME_LEN, "/%s/trash/home",
51  myZoneName );
52  }
53  }
54  else {
55  int remoteFlag = 0;
56  status = getZoneType( conn, myZoneName, conn->clientUser.rodsZone,
57  myZoneType );
58  if ( status >= 0 ) {
59  if ( strcmp( myZoneType, "remote" ) == 0 ) {
60  remoteFlag = 1;
61  }
62  }
63  if ( remoteFlag == 0 ) {
64  snprintf( trashPath, MAX_NAME_LEN, "/%s/trash/home/%s",
65  myZoneName, conn->clientUser.userName );
66  }
67  else {
68  snprintf( trashPath, MAX_NAME_LEN, "/%s/trash/home/%s#%s",
69  myZoneName, conn->clientUser.userName,
70  conn->clientUser.rodsZone );
71  }
72  }
73  addSrcInPath( rodsPathInp, trashPath );
74  rstrcpy( rodsPathInp->srcPath[0].outPath, trashPath, MAX_NAME_LEN );
75  rodsPathInp->srcPath[0].objType = COLL_OBJ_T;
76  }
77 
78  for ( i = 0; i < rodsPathInp->numSrc; i++ ) {
79  if ( rodsPathInp->srcPath[i].objType == UNKNOWN_OBJ_T ) {
80  getRodsObjType( conn, &rodsPathInp->srcPath[i] );
81  if ( rodsPathInp->srcPath[i].objState == NOT_EXIST_ST ) {
83  "rmtrashUtil: srcPath %s does not exist",
84  rodsPathInp->srcPath[i].outPath );
85  savedStatus = USER_INPUT_PATH_ERR;
86  continue;
87  }
88  }
89 
90  if ( rodsPathInp->srcPath[i].objType == DATA_OBJ_T ) {
91  status = rmtrashDataObjUtil( conn, rodsPathInp->srcPath[i].outPath,
92  myRodsArgs, &dataObjInp );
93  }
94  else if ( rodsPathInp->srcPath[i].objType == COLL_OBJ_T ) {
95  status = rmtrashCollUtil( conn, rodsPathInp->srcPath[i].outPath,
96  myRodsArgs, &collInp );
97  }
98  else {
99  /* should not be here */
101  "rmtrashUtil: invalid rmtrash objType %d for %s",
102  rodsPathInp->srcPath[i].objType, rodsPathInp->srcPath[i].outPath );
103  return USER_INPUT_PATH_ERR;
104  }
105  /* XXXX may need to return a global status */
106  if ( status < 0 ) {
108  "rmtrashUtil: rmtrash error for %s, status = %d",
109  rodsPathInp->srcPath[i].outPath, status );
110  savedStatus = status;
111  }
112  }
113  if ( savedStatus < 0 ) {
114  return savedStatus;
115  }
116  else if ( status == CAT_NO_ROWS_FOUND ) {
117  return 0;
118  }
119  else {
120  return status;
121  }
122 }
123 
124 int
125 rmtrashDataObjUtil( rcComm_t *conn, char *srcPath,
126  rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp ) {
127  int status = 0;
128  struct timeval startTime, endTime;
129 
130  if ( srcPath == NULL ) {
132  "rmtrashDataObjUtil: NULL srcPath input" );
133  return USER__NULL_INPUT_ERR;
134  }
135 
136  if ( rodsArgs->verbose == True ) {
137  ( void ) gettimeofday( &startTime, ( struct timezone * )0 );
138  }
139 
140  rstrcpy( dataObjInp->objPath, srcPath, MAX_NAME_LEN );
141 
142  status = rcDataObjUnlink( conn, dataObjInp );
143 
144  if ( status >= 0 && rodsArgs->verbose == True ) {
145  ( void ) gettimeofday( &endTime, ( struct timezone * )0 );
146  printTiming( conn, dataObjInp->objPath, -1, NULL,
147  &startTime, &endTime );
148  }
149 
150  return status;
151 }
152 
153 int
155  dataObjInp_t *dataObjInp, collInp_t *collInp ) {
156  char tmpStr[NAME_LEN];
157 
158  if ( dataObjInp == NULL ) {
160  "initCondForRmtrash: NULL dataObjInp input" );
161  return USER__NULL_INPUT_ERR;
162  }
163 
164  memset( dataObjInp, 0, sizeof( dataObjInp_t ) );
165  memset( collInp, 0, sizeof( collInp_t ) );
166 
167  if ( rodsArgs == NULL ) {
168  return 0;
169  }
170 
171  addKeyVal( &dataObjInp->condInput, FORCE_FLAG_KW, "" );
172  addKeyVal( &collInp->condInput, FORCE_FLAG_KW, "" );
173 
174  addKeyVal( &dataObjInp->condInput, RECURSIVE_OPR__KW, "" );
175  addKeyVal( &collInp->condInput, RECURSIVE_OPR__KW, "" );
176 
177  if ( rodsArgs->admin == True ) {
178  addKeyVal( &dataObjInp->condInput, ADMIN_RMTRASH_KW, "" );
179  addKeyVal( &collInp->condInput, ADMIN_RMTRASH_KW, "" );
180  }
181  else {
182  addKeyVal( &dataObjInp->condInput, RMTRASH_KW, "" );
183  addKeyVal( &collInp->condInput, RMTRASH_KW, "" );
184  }
185 
186  if ( rodsArgs->zone == True ) {
187  addKeyVal( &collInp->condInput, ZONE_KW, rodsArgs->zoneName );
188  addKeyVal( &dataObjInp->condInput, ZONE_KW, rodsArgs->zoneName );
189  }
190 
191  if ( rodsArgs->age == True ) {
192  snprintf( tmpStr, NAME_LEN, "%d", rodsArgs->agevalue );
193  addKeyVal( &collInp->condInput, AGE_KW, tmpStr );
194  addKeyVal( &dataObjInp->condInput, AGE_KW, tmpStr );
195  }
196 
197  seedRandom();
198 
199  return 0;
200 }
201 
202 int
203 rmtrashCollUtil( rcComm_t *conn, char *srcColl,
204  rodsArguments_t *rodsArgs, collInp_t *collInp ) {
205  int status;
206 
207  if ( srcColl == NULL ) {
209  "rmtrashCollUtil: NULL srcColl input" );
210  return USER__NULL_INPUT_ERR;
211  }
212 
213  rstrcpy( collInp->collName, srcColl, MAX_NAME_LEN );
214  status = rcRmColl( conn, collInp, rodsArgs->verbose );
215 
216  return status;
217 }
218 
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
DataObjInp::objPath
char objPath[(1024+64)]
Definition: dataObjInpOut.h:66
rcComm_t
Definition: rcConnect.h:95
NULL
#define NULL
Definition: rodsDef.h:70
True
#define True
Definition: parseCommandLine.h:11
addKeyVal
int addKeyVal(keyValPair_t *condInput, const char *keyWord, const char *value)
Definition: rcMisc.cpp:789
rodsPath.h
rodsArguments_t
Definition: parseCommandLine.h:14
CollInp
Definition: dataObjInpOut.h:157
rodsArguments_t::orphan
int orphan
Definition: parseCommandLine.h:77
getZoneType
int getZoneType(rcComm_t *conn, char *icatZone, char *inZoneName, char *outZoneType)
Definition: miscUtil.cpp:1869
userInfo_t::userName
char userName[64]
Definition: rodsUser.h:66
UNKNOWN_OBJ_T
@ UNKNOWN_OBJ_T
Definition: rodsType.h:37
rmtrashUtil.h
rmtrashCollUtil
int rmtrashCollUtil(rcComm_t *conn, char *srcColl, rodsArguments_t *rodsArgs, collInp_t *collInp)
Definition: rmtrashUtil.cpp:203
RodsPathInp
Definition: rodsPath.h:33
rodsArguments_t::zoneName
char * zoneName
Definition: parseCommandLine.h:111
rodsArguments_t::verbose
int verbose
Definition: parseCommandLine.h:107
rmtrashUtil
int rmtrashUtil(rcComm_t *conn, rodsArguments_t *myRodsArgs, rodsPathInp_t *rodsPathInp)
Definition: rmtrashUtil.cpp:14
rodsArguments_t::zone
int zone
Definition: parseCommandLine.h:110
RodsPath::objState
objStat_t objState
Definition: rodsPath.h:20
rmtrashDataObjUtil
int rmtrashDataObjUtil(rcComm_t *conn, char *srcPath, rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp)
Definition: rmtrashUtil.cpp:125
rcGlobalExtern.h
RodsPathInp::srcPath
rodsPath_t * srcPath
Definition: rodsPath.h:35
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
RodsPath::objType
objType_t objType
Definition: rodsPath.h:19
RECURSIVE_OPR__KW
#define RECURSIVE_OPR__KW
Definition: rodsKeyWdDef.h:66
COLL_OBJ_T
@ COLL_OBJ_T
Definition: rodsType.h:39
rodsArguments_t::admin
int admin
Definition: parseCommandLine.h:20
rodsArguments_t::age
int age
Definition: parseCommandLine.h:16
rcComm_t::clientUser
userInfo_t clientUser
Definition: rcConnect.h:104
DataObjInp
Definition: dataObjInpOut.h:65
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
RMTRASH_KW
#define RMTRASH_KW
Definition: rodsKeyWdDef.h:65
CollInp::condInput
keyValPair_t condInput
Definition: dataObjInpOut.h:161
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
userInfo_t::rodsZone
char rodsZone[64]
Definition: rodsUser.h:67
rodsLog.h
rcRmColl
int rcRmColl(rcComm_t *conn, collInp_t *rmCollInp, int vFlag)
Definition: rcRmColl.cpp:79
AGE_KW
#define AGE_KW
Definition: rodsKeyWdDef.h:221
DATA_OBJ_T
@ DATA_OBJ_T
Definition: rodsType.h:38
RodsPath::outPath
char outPath[(1024+64)]
Definition: rodsPath.h:24
rodsArguments_t::userString
char * userString
Definition: parseCommandLine.h:105
printTiming
int printTiming(rcComm_t *conn, char *objPath, rodsLong_t fileSize, char *localFile, struct timeval *startTime, struct timeval *endTime)
Definition: miscUtil.cpp:396
FORCE_FLAG_KW
#define FORCE_FLAG_KW
Definition: rodsKeyWdDef.h:13
CAT_NO_ROWS_FOUND
@ CAT_NO_ROWS_FOUND
Definition: rodsErrorTable.h:423
seedRandom
unsigned int seedRandom()
Definition: rcMisc.cpp:3586
rodsArguments_t::agevalue
int agevalue
Definition: parseCommandLine.h:17
rodsLogError
void rodsLogError(int level, int errCode, char *formatStr,...)
Definition: rodsLog.cpp:422
rcDataObjUnlink
int rcDataObjUnlink(rcComm_t *conn, dataObjInp_t *dataObjUnlinkInp)
Definition: rcDataObjUnlink.cpp:63
RodsPathInp::numSrc
int numSrc
Definition: rodsPath.h:34
CollInp::collName
char collName[(1024+64)]
Definition: dataObjInpOut.h:158
ZONE_KW
#define ZONE_KW
Definition: rodsKeyWdDef.h:80
rodsErrorTable.h
miscUtil.h
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
DataObjInp::condInput
keyValPair_t condInput
Definition: dataObjInpOut.h:74
initCondForRmtrash
int initCondForRmtrash(rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp, collInp_t *collInp)
Definition: rmtrashUtil.cpp:154
NOT_EXIST_ST
@ NOT_EXIST_ST
Definition: rodsType.h:48
NAME_LEN
#define NAME_LEN
Definition: rodsDef.h:55
rodsArguments_t::user
int user
Definition: parseCommandLine.h:104
addSrcInPath
int addSrcInPath(rodsPathInp_t *rodsPathInp, const char *inPath)
Definition: rodsPath.cpp:261
getRodsObjType
int getRodsObjType(rcComm_t *conn, rodsPath_t *rodsPath)
Definition: miscUtil.cpp:200
USER_INPUT_PATH_ERR
@ USER_INPUT_PATH_ERR
Definition: rodsErrorTable.h:248
ADMIN_RMTRASH_KW
#define ADMIN_RMTRASH_KW
Definition: rodsKeyWdDef.h:63
USER__NULL_INPUT_ERR
@ USER__NULL_INPUT_ERR
Definition: rodsErrorTable.h:247