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)  

rmUtil.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 "rmUtil.h"
11 #include "rcGlobalExtern.h"
12 
13 int
14 rmUtil( rcComm_t *conn, rodsArguments_t *myRodsArgs,
15  rodsPathInp_t *rodsPathInp ) {
16  if (!rodsPathInp) {
17  return USER__NULL_INPUT_ERR;
18  }
19 
20  if (True == myRodsArgs->dryrun) {
22  "%s: option --dryrun is not valid",
23  __FUNCTION__);
24  return USER_INPUT_OPTION_ERR;
25  }
26 
27  collInp_t collInp;
28  dataObjInp_t dataObjInp;
29  initCondForRm( myRodsArgs, &dataObjInp, &collInp );
30 
31  int savedStatus = 0;
32  for ( int i = 0; i < rodsPathInp->numSrc; i++ ) {
33  if ( rodsPathInp->srcPath[i].objType == UNKNOWN_OBJ_T ) {
34  getRodsObjType( conn, &rodsPathInp->srcPath[i] );
35  if ( rodsPathInp->srcPath[i].objState == NOT_EXIST_ST ) {
37  "rmUtil: srcPath %s does not exist",
38  rodsPathInp->srcPath[i].outPath );
39  savedStatus = USER_INPUT_PATH_ERR;
40  continue;
41  }
42  }
43 
44  int status = 0;
45  if ( rodsPathInp->srcPath[i].objType == DATA_OBJ_T ) {
46  status = rmDataObjUtil( conn, rodsPathInp->srcPath[i].outPath,
47  myRodsArgs, &dataObjInp );
48  }
49  else if ( rodsPathInp->srcPath[i].objType == COLL_OBJ_T ) {
50  status = rmCollUtil( conn, rodsPathInp->srcPath[i].outPath,
51  myRodsArgs, &collInp );
52  }
53  else {
54  /* should not be here */
56  "rmUtil: invalid rm objType %d for %s",
57  rodsPathInp->srcPath[i].objType, rodsPathInp->srcPath[i].outPath );
58  return USER_INPUT_PATH_ERR;
59  }
60  /* XXXX may need to return a global status */
61  if ( status < 0 &&
64  "rmUtil: rm error for %s, status = %d",
65  rodsPathInp->srcPath[i].outPath, status );
66  savedStatus = status;
67  }
68  }
69  return savedStatus;
70 }
71 
72 int
73 rmDataObjUtil( rcComm_t *conn, char *srcPath,
74  rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp ) {
75  int status;
76  struct timeval startTime, endTime;
77 
78  if ( srcPath == NULL ) {
80  "rmDataObjUtil: NULL srcPath input" );
81  return USER__NULL_INPUT_ERR;
82  }
83 
84  if ( rodsArgs->verbose == True ) {
85  ( void ) gettimeofday( &startTime, ( struct timezone * )0 );
86  }
87 
88  rstrcpy( dataObjInp->objPath, srcPath, MAX_NAME_LEN );
89 
90  status = rcDataObjUnlink( conn, dataObjInp );
91 
92  if ( status >= 0 && rodsArgs->verbose == True ) {
93  ( void ) gettimeofday( &endTime, ( struct timezone * )0 );
94  printTiming( conn, dataObjInp->objPath, -1, NULL,
95  &startTime, &endTime );
96  }
97 
98  return status;
99 }
100 
101 int
103  collInp_t *collInp ) {
104 
105 #ifdef _WIN32
106  struct _timeb timebuffer;
107 #endif
108 
109  if ( dataObjInp == NULL ) {
111  "initCondForRm: NULL dataObjInp input" );
112  return USER__NULL_INPUT_ERR;
113  }
114 
115  memset( dataObjInp, 0, sizeof( dataObjInp_t ) );
116  memset( collInp, 0, sizeof( collInp_t ) );
117 
118  if ( rodsArgs == NULL ) {
119  return 0;
120  }
121 
122  if ( rodsArgs->unmount == True ) {
123  dataObjInp->oprType = collInp->oprType = UNREG_OPR;
124  }
125 
126  if ( rodsArgs->force == True ) {
127  addKeyVal( &dataObjInp->condInput, FORCE_FLAG_KW, "" );
128  addKeyVal( &collInp->condInput, FORCE_FLAG_KW, "" );
129  }
130  // =-=-=-=-=-=-=-
131  // JMC - backport 4552
132  if ( rodsArgs->empty == True ) {
133  addKeyVal( &dataObjInp->condInput, EMPTY_BUNDLE_ONLY_KW, "" );
134  addKeyVal( &collInp->condInput, EMPTY_BUNDLE_ONLY_KW, "" );
135  }
136  // =-=-=-=-=-=-=-
137  if ( rodsArgs->replNum == True ) {
138  addKeyVal( &dataObjInp->condInput, REPL_NUM_KW,
139  rodsArgs->replNumValue );
140  if ( rodsArgs->recursive == True ) {
142  "initCondForRm: -n option is only for dataObj removal. It will be ignored for collection removal" );
143  }
144  }
145 
146  if ( rodsArgs->recursive == True ) {
147  addKeyVal( &dataObjInp->condInput, RECURSIVE_OPR__KW, "" );
148  addKeyVal( &collInp->condInput, RECURSIVE_OPR__KW, "" );
149  }
150 
151  if (True == rodsArgs->admin) {
152  addKeyVal(&dataObjInp->condInput, ADMIN_KW, "");
153  addKeyVal(&collInp->condInput, ADMIN_KW, "");
154  }
155 
156  /* XXXXX need to add -u register cond */
157 
158  dataObjInp->openFlags = O_RDONLY;
159 
160  seedRandom();
161 
162  return 0;
163 }
164 
165 int
166 rmCollUtil( rcComm_t *conn, char *srcColl,
167  rodsArguments_t *rodsArgs, collInp_t *collInp ) {
168  int status;
169 
170  if ( srcColl == NULL ) {
172  "rmCollUtil: NULL srcColl input" );
173  return USER__NULL_INPUT_ERR;
174  }
175 
176  if ( rodsArgs->recursive != True ) {
178  "rmCollUtil: -r option must be used for collection %s",
179  srcColl );
180  return USER_INPUT_OPTION_ERR;
181  }
182 
183  rstrcpy( collInp->collName, srcColl, MAX_NAME_LEN );
184  status = rcRmColl( conn, collInp, rodsArgs->verbose );
185 
186  return status;
187 }
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
DataObjInp::openFlags
int openFlags
Definition: dataObjInpOut.h:68
rodsArguments_t
Definition: parseCommandLine.h:14
CollInp
Definition: dataObjInpOut.h:157
UNKNOWN_OBJ_T
@ UNKNOWN_OBJ_T
Definition: rodsType.h:37
RodsPathInp
Definition: rodsPath.h:33
rodsArguments_t::verbose
int verbose
Definition: parseCommandLine.h:107
rodsArguments_t::empty
int empty
Definition: parseCommandLine.h:37
RodsPath::objState
objStat_t objState
Definition: rodsPath.h:20
REPL_NUM_KW
#define REPL_NUM_KW
Definition: rodsKeyWdDef.h:30
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
rmDataObjUtil
int rmDataObjUtil(rcComm_t *conn, char *srcPath, rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp)
Definition: rmUtil.cpp:73
rodsArguments_t::admin
int admin
Definition: parseCommandLine.h:20
rmUtil
int rmUtil(rcComm_t *conn, rodsArguments_t *myRodsArgs, rodsPathInp_t *rodsPathInp)
Definition: rmUtil.cpp:14
rmUtil.h
DataObjInp
Definition: dataObjInpOut.h:65
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
CollInp::condInput
keyValPair_t condInput
Definition: dataObjInpOut.h:161
ADMIN_KW
#define ADMIN_KW
Definition: rodsKeyWdDef.h:62
EMPTY_BUNDLE_ONLY_KW
#define EMPTY_BUNDLE_ONLY_KW
Definition: rodsKeyWdDef.h:111
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
rodsLog.h
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
rcRmColl
int rcRmColl(rcComm_t *conn, collInp_t *rmCollInp, int vFlag)
Definition: rcRmColl.cpp:79
rodsArguments_t::force
int force
Definition: parseCommandLine.h:38
DATA_OBJ_T
@ DATA_OBJ_T
Definition: rodsType.h:38
RodsPath::outPath
char outPath[(1024+64)]
Definition: rodsPath.h:24
printTiming
int printTiming(rcComm_t *conn, char *objPath, rodsLong_t fileSize, char *localFile, struct timeval *startTime, struct timeval *endTime)
Definition: miscUtil.cpp:396
rodsArguments_t::recursive
int recursive
Definition: parseCommandLine.h:85
FORCE_FLAG_KW
#define FORCE_FLAG_KW
Definition: rodsKeyWdDef.h:13
rodsArguments_t::dryrun
int dryrun
Definition: parseCommandLine.h:35
rmCollUtil
int rmCollUtil(rcComm_t *conn, char *srcColl, rodsArguments_t *rodsArgs, collInp_t *collInp)
Definition: rmUtil.cpp:166
DataObjInp::oprType
int oprType
Definition: dataObjInpOut.h:72
CAT_NO_ROWS_FOUND
@ CAT_NO_ROWS_FOUND
Definition: rodsErrorTable.h:423
seedRandom
unsigned int seedRandom()
Definition: rcMisc.cpp:3586
UNREG_OPR
#define UNREG_OPR
Definition: dataObjInpOut.h:190
rodsArguments_t::unmount
int unmount
Definition: parseCommandLine.h:106
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
rcDataObjUnlink
int rcDataObjUnlink(rcComm_t *conn, dataObjInp_t *dataObjUnlinkInp)
Definition: rcDataObjUnlink.cpp:63
RodsPathInp::numSrc
int numSrc
Definition: rodsPath.h:34
rodsArguments_t::replNum
int replNum
Definition: parseCommandLine.h:63
CollInp::collName
char collName[(1024+64)]
Definition: dataObjInpOut.h:158
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
NOT_EXIST_ST
@ NOT_EXIST_ST
Definition: rodsType.h:48
rodsArguments_t::replNumValue
char * replNumValue
Definition: parseCommandLine.h:64
initCondForRm
int initCondForRm(rodsArguments_t *rodsArgs, dataObjInp_t *dataObjInp, collInp_t *collInp)
Definition: rmUtil.cpp:102
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
CollInp::oprType
int oprType
Definition: dataObjInpOut.h:160
USER__NULL_INPUT_ERR
@ USER__NULL_INPUT_ERR
Definition: rodsErrorTable.h:247