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)  

trimUtil.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 "rodsLog.h"
9 #include "miscUtil.h"
10 #include "trimUtil.h"
11 #include "rcGlobalExtern.h"
12 
14 int TotalTrimmed = 0;
15 
16 int
17 trimUtil( rcComm_t *conn, rodsEnv *myRodsEnv, rodsArguments_t *myRodsArgs,
18  rodsPathInp_t *rodsPathInp ) {
19  if ( rodsPathInp == NULL ) {
20  return USER__NULL_INPUT_ERR;
21  }
22 
23  dataObjInp_t dataObjInp;
24  initCondForTrim( myRodsArgs, &dataObjInp );
25 
26  if ( myRodsArgs->dryrun == True ) {
27  printf( "====== This is a DRYRUN ======\n" );
28  }
29  int savedStatus = 0;
30  for ( int i = 0; i < rodsPathInp->numSrc; i++ ) {
31  if ( rodsPathInp->srcPath[i].objType == UNKNOWN_OBJ_T ) {
32  getRodsObjType( conn, &rodsPathInp->srcPath[i] );
33  if ( rodsPathInp->srcPath[i].objState == NOT_EXIST_ST ) {
35  "trimUtil: srcPath %s does not exist",
36  rodsPathInp->srcPath[i].outPath );
37  savedStatus = USER_INPUT_PATH_ERR;
38  continue;
39  }
40  }
41  int status = 0;
42  if ( rodsPathInp->srcPath[i].objType == DATA_OBJ_T ) {
43  rmKeyVal( &dataObjInp.condInput, TRANSLATED_PATH_KW );
44  status = trimDataObjUtil( conn, rodsPathInp->srcPath[i].outPath,
45  myRodsArgs, &dataObjInp );
46  }
47  else if ( rodsPathInp->srcPath[i].objType == COLL_OBJ_T ) {
48  addKeyVal( &dataObjInp.condInput, TRANSLATED_PATH_KW, "" );
49  status = trimCollUtil( conn, rodsPathInp->srcPath[i].outPath,
50  myRodsEnv, myRodsArgs, &dataObjInp );
51  }
52  else {
53  /* should not be here */
55  "trimUtil: invalid trim objType %d for %s",
56  rodsPathInp->srcPath[i].objType, rodsPathInp->srcPath[i].outPath );
57  return USER_INPUT_PATH_ERR;
58  }
59  /* XXXX may need to return a global status */
60  if ( status < 0 &&
63  "trimUtil: trim error for %s. ",
64  rodsPathInp->srcPath[i].outPath );
65  savedStatus = status;
66  }
67  }
68  printf(
69  "Total size trimmed = %-.3f MB. Number of files trimmed = %d.\n",
70  ( float ) TotalSizeTrimmed / 1048576.0, TotalTrimmed );
71  return savedStatus;
72 }
73 
74 int
75 trimDataObjUtil( rcComm_t *conn, char *srcPath,
76  rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp ) {
77  int status = 0;
78  rodsObjStat_t *rodsObjStatOut = NULL;
79 
80  if ( srcPath == NULL ) {
82  "trimDataObjUtil: NULL srcPath input" );
83  return USER__NULL_INPUT_ERR;
84  }
85 
86  rstrcpy( dataObjInp->objPath, srcPath, MAX_NAME_LEN );
87 
88  status = rcDataObjTrim( conn, dataObjInp );
89 
90  if ( status < 0 ) {
91  return status;
92  }
93 
94 
95  if ( status >= 0 && rodsArgs->verbose == True ) {
96  char myDir[MAX_NAME_LEN], myFile[MAX_NAME_LEN];
97  splitPathByKey( srcPath, myDir, MAX_NAME_LEN, myFile, MAX_NAME_LEN, '/' );
98  if ( status > 0 ) {
99  printf( "%s - a copy trimmed\n", myFile );
100  }
101  else {
102  printf( "%s - No copy trimmed\n", myFile );
103  }
104  }
105 
106  if ( status > 0 ) {
107  const int objStatus = rcObjStat(conn, dataObjInp, &rodsObjStatOut);
108  if ( objStatus < 0) {
109  return objStatus;
110  }
111  if ( objStatus == DATA_OBJ_T) {
112  TotalSizeTrimmed += rodsObjStatOut->objSize;
113  TotalTrimmed++;
114  } else {
115  rodsLog( LOG_ERROR, "trimDataObjUtil: invalid object");
116  return INVALID_OBJECT_TYPE;
117  }
118  }
119  return status;
120 }
121 
122 int
124  dataObjInp_t *dataObjInp ) {
125  char tmpStr[NAME_LEN];
126 
127  if ( dataObjInp == NULL ) {
129  "initCondForTrim: NULL dataObjInp input" );
130  return USER__NULL_INPUT_ERR;
131  }
132 
133  memset( dataObjInp, 0, sizeof( dataObjInp_t ) );
134 
135  if ( rodsArgs == NULL ) {
136  return 0;
137  }
138 
139  if ( rodsArgs->number == True ) {
140  snprintf( tmpStr, NAME_LEN, "%d", rodsArgs->numberValue );
141  addKeyVal( &dataObjInp->condInput, COPIES_KW, tmpStr );
142  }
143 
144  if ( rodsArgs->admin == True ) {
145  addKeyVal( &dataObjInp->condInput, ADMIN_KW, "" );
146  }
147 
148  if ( rodsArgs->replNum == True ) {
149  addKeyVal( &dataObjInp->condInput, REPL_NUM_KW,
150  rodsArgs->replNumValue );
151  }
152 
153  if ( rodsArgs->srcResc == True ) {
154  addKeyVal( &dataObjInp->condInput, RESC_NAME_KW,
155  rodsArgs->srcRescString );
156  }
157 
158  if ( rodsArgs->age == True ) {
159  snprintf( tmpStr, NAME_LEN, "%d", rodsArgs->agevalue );
160  addKeyVal( &dataObjInp->condInput, AGE_KW, tmpStr );
161  }
162 
163  if ( rodsArgs->dryrun == True ) {
164  addKeyVal( &dataObjInp->condInput, DRYRUN_KW, "" );
165  }
166 
167  // See rmUtil
168  if (rodsArgs->unmount == True) {
169  dataObjInp->oprType = UNREG_OPR;
170  }
171 
172  return 0;
173 }
174 
175 int
176 trimCollUtil( rcComm_t *conn, char *srcColl, rodsEnv *myRodsEnv,
177  rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp ) {
178  int status;
179  int savedStatus = 0;
180  char srcChildPath[MAX_NAME_LEN];
181  collHandle_t collHandle;
182  collEnt_t collEnt;
183 
184  if ( srcColl == NULL ) {
186  "trimCollUtil: NULL srcColl input" );
187  return USER__NULL_INPUT_ERR;
188  }
189 
190  if ( rodsArgs->recursive != True ) {
192  "trimCollUtil: -r option must be used for getting %s collection",
193  srcColl );
194  return USER_INPUT_OPTION_ERR;
195  }
196 
197  if ( rodsArgs->verbose == True ) {
198  fprintf( stdout, "C- %s:\n", srcColl );
199  }
200 
201  status = rclOpenCollection( conn, srcColl, 0, &collHandle );
202 
203  if ( status < 0 ) {
205  "trimCollUtil: rclOpenCollection of %s error. status = %d",
206  srcColl, status );
207  return status;
208  }
209  if ( collHandle.rodsObjStat->specColl != NULL &&
210  collHandle.rodsObjStat->specColl->collClass != LINKED_COLL ) {
211  /* no trim for mounted coll */
212  rclCloseCollection( &collHandle );
213  return 0;
214  }
215  while ( ( status = rclReadCollection( conn, &collHandle, &collEnt ) ) >= 0 ) {
216  if ( collEnt.objType == DATA_OBJ_T ) {
217  snprintf( srcChildPath, MAX_NAME_LEN, "%s/%s",
218  collEnt.collName, collEnt.dataName );
219  int status = trimDataObjUtil( conn, srcChildPath, rodsArgs,
220  dataObjInp );
221  if ( status < 0 ) {
223  "trimCollUtil: trimDataObjUtil failed for %s. status = %d",
224  srcChildPath, status );
225  /* need to set global error here */
226  savedStatus = status;
227  }
228  }
229  else if ( collEnt.objType == COLL_OBJ_T ) {
230  dataObjInp_t childDataObjInp;
231  childDataObjInp = *dataObjInp;
232  if ( collEnt.specColl.collClass != NO_SPEC_COLL ) {
233  childDataObjInp.specColl = &collEnt.specColl;
234  }
235  else {
236  childDataObjInp.specColl = NULL;
237  }
238  int status = trimCollUtil( conn, collEnt.collName, myRodsEnv,
239  rodsArgs, &childDataObjInp );
240  if ( status < 0 && status != CAT_NO_ROWS_FOUND ) {
241  return status;
242  }
243  }
244  }
245  rclCloseCollection( &collHandle );
246 
247  if ( savedStatus < 0 ) {
248  return savedStatus;
249  }
250  else if ( status == CAT_NO_ROWS_FOUND ) {
251  return 0;
252  }
253  else {
254  return status;
255  }
256 }
257 
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
DataObjInp::objPath
char objPath[(1024+64)]
Definition: dataObjInpOut.h:66
TotalTrimmed
int TotalTrimmed
Definition: trimUtil.cpp:14
RESC_NAME_KW
#define RESC_NAME_KW
Definition: rodsKeyWdDef.h:19
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
rclOpenCollection
int rclOpenCollection(rcComm_t *conn, char *collection, int flag, collHandle_t *collHandle)
Definition: miscUtil.cpp:1057
rodsArguments_t
Definition: parseCommandLine.h:14
DataObjInp::specColl
specColl_t * specColl
Definition: dataObjInpOut.h:73
rcObjStat
int rcObjStat(rcComm_t *conn, dataObjInp_t *dataObjInp, rodsObjStat_t **rodsObjStatOut)
Definition: rcObjStat.cpp:65
UNKNOWN_OBJ_T
@ UNKNOWN_OBJ_T
Definition: rodsType.h:37
RodsPathInp
Definition: rodsPath.h:33
collHandle_t
Definition: miscUtil.h:97
rodsArguments_t::verbose
int verbose
Definition: parseCommandLine.h:107
rodsArguments_t::srcRescString
char * srcRescString
Definition: parseCommandLine.h:93
CollEnt::collName
char * collName
Definition: miscUtil.h:119
RodsPath::objState
objStat_t objState
Definition: rodsPath.h:20
REPL_NUM_KW
#define REPL_NUM_KW
Definition: rodsKeyWdDef.h:30
trimCollUtil
int trimCollUtil(rcComm_t *conn, char *srcColl, rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp)
Definition: trimUtil.cpp:176
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
initCondForTrim
int initCondForTrim(rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp)
Definition: trimUtil.cpp:123
COLL_OBJ_T
@ COLL_OBJ_T
Definition: rodsType.h:39
rodsArguments_t::srcResc
int srcResc
Definition: parseCommandLine.h:92
COPIES_KW
#define COPIES_KW
Definition: rodsKeyWdDef.h:11
LINKED_COLL
@ LINKED_COLL
Definition: objInfo.h:49
rodsArguments_t::admin
int admin
Definition: parseCommandLine.h:20
TotalSizeTrimmed
rodsLong_t TotalSizeTrimmed
Definition: trimUtil.cpp:13
rclCloseCollection
int rclCloseCollection(collHandle_t *collHandle)
Definition: miscUtil.cpp:1354
rodsArguments_t::age
int age
Definition: parseCommandLine.h:16
CollEnt
Definition: miscUtil.h:113
CollEnt::specColl
specColl_t specColl
Definition: miscUtil.h:130
DRYRUN_KW
#define DRYRUN_KW
Definition: rodsKeyWdDef.h:106
DataObjInp
Definition: dataObjInpOut.h:65
rodsObjStat::objSize
rodsLong_t objSize
Definition: objStat.h:9
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
collHandle_t::rodsObjStat
rodsObjStat_t * rodsObjStat
Definition: miscUtil.h:102
rmKeyVal
int rmKeyVal(keyValPair_t *condInput, const char *keyWord)
Definition: rcMisc.cpp:710
ADMIN_KW
#define ADMIN_KW
Definition: rodsKeyWdDef.h:62
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
NO_SPEC_COLL
@ NO_SPEC_COLL
Definition: objInfo.h:46
TRANSLATED_PATH_KW
#define TRANSLATED_PATH_KW
Definition: rodsKeyWdDef.h:97
splitPathByKey
int splitPathByKey(const char *srcPath, char *dir, size_t maxDirLen, char *file, size_t maxFileLen, char key)
Definition: stringOpr.cpp:222
rodsLog.h
trimDataObjUtil
int trimDataObjUtil(rcComm_t *conn, char *srcPath, rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp)
Definition: trimUtil.cpp:75
INVALID_OBJECT_TYPE
@ INVALID_OBJECT_TYPE
Definition: rodsErrorTable.h:679
AGE_KW
#define AGE_KW
Definition: rodsKeyWdDef.h:221
rcDataObjTrim
int rcDataObjTrim(rcComm_t *conn, dataObjInp_t *dataObjInp)
Definition: rcDataObjTrim.cpp:73
DATA_OBJ_T
@ DATA_OBJ_T
Definition: rodsType.h:38
CollEnt::dataName
char * dataName
Definition: miscUtil.h:120
RodsPath::outPath
char outPath[(1024+64)]
Definition: rodsPath.h:24
rodsArguments_t::recursive
int recursive
Definition: parseCommandLine.h:85
rodsArguments_t::dryrun
int dryrun
Definition: parseCommandLine.h:35
DataObjInp::oprType
int oprType
Definition: dataObjInpOut.h:72
CAT_NO_ROWS_FOUND
@ CAT_NO_ROWS_FOUND
Definition: rodsErrorTable.h:423
UNREG_OPR
#define UNREG_OPR
Definition: dataObjInpOut.h:190
rodsArguments_t::unmount
int unmount
Definition: parseCommandLine.h:106
rodsArguments_t::agevalue
int agevalue
Definition: parseCommandLine.h:17
USER_INPUT_OPTION_ERR
@ USER_INPUT_OPTION_ERR
Definition: rodsErrorTable.h:249
rodsLogError
void rodsLogError(int level, int errCode, char *formatStr,...)
Definition: rodsLog.cpp:422
RodsPathInp::numSrc
int numSrc
Definition: rodsPath.h:34
rodsArguments_t::replNum
int replNum
Definition: parseCommandLine.h:63
trimUtil
int trimUtil(rcComm_t *conn, rodsEnv *myRodsEnv, rodsArguments_t *myRodsArgs, rodsPathInp_t *rodsPathInp)
Definition: trimUtil.cpp:17
CollEnt::objType
objType_t objType
Definition: miscUtil.h:114
rclReadCollection
int rclReadCollection(rcComm_t *conn, collHandle_t *collHandle, collEnt_t *collEnt)
Definition: miscUtil.cpp:1108
rodsObjStat
Definition: objStat.h:8
rodsErrorTable.h
rodsObjStat::specColl
specColl_t * specColl
Definition: objStat.h:18
miscUtil.h
rodsArguments_t::numberValue
int numberValue
Definition: parseCommandLine.h:69
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
DataObjInp::condInput
keyValPair_t condInput
Definition: dataObjInpOut.h:74
trimUtil.h
rodsEnv
Definition: getRodsEnv.h:8
NOT_EXIST_ST
@ NOT_EXIST_ST
Definition: rodsType.h:48
NAME_LEN
#define NAME_LEN
Definition: rodsDef.h:55
rodsArguments_t::replNumValue
char * replNumValue
Definition: parseCommandLine.h:64
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
rodsLong_t
long long rodsLong_t
Definition: rodsType.h:32
rodsArguments_t::number
int number
Definition: parseCommandLine.h:68
SpecColl::collClass
specCollClass_t collClass
Definition: objInfo.h:77
USER__NULL_INPUT_ERR
@ USER__NULL_INPUT_ERR
Definition: rodsErrorTable.h:247