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)  

rsRmColl.cpp
Go to the documentation of this file.
1 
3 /* rsRmColl.c
4  */
5 
6 #include "rmColl.h"
7 #include "objMetaOpr.hpp"
8 #include "specColl.hpp"
10 #include "openCollection.h"
11 #include "readCollection.h"
12 #include "closeCollection.h"
13 #include "dataObjUnlink.h"
14 #include "rsApiHandler.hpp"
15 #include "fileRmdir.h"
16 #include "collection.hpp"
17 #include "subStructFileRmdir.h"
18 #include "dataObjRename.h"
19 #include "genQuery.h"
20 #include "miscServerFunct.hpp"
21 #include "rsRmColl.hpp"
22 #include "rsOpenCollection.hpp"
23 #include "rsCloseCollection.hpp"
24 #include "rsReadCollection.hpp"
25 #include "rsDataObjUnlink.hpp"
26 #include "rsSubStructFileRmdir.hpp"
27 #include "rsFileRmdir.hpp"
28 #include "rsDataObjRename.hpp"
29 #include "rsGenQuery.hpp"
30 
33 
34 int
35 rsRmColl( rsComm_t *rsComm, collInp_t *rmCollInp,
36  collOprStat_t **collOprStat ) {
37  auto* recurse = getValByKey(&rmCollInp->condInput, RECURSIVE_OPR__KW);
38  auto* replica_number = getValByKey(&rmCollInp->condInput, REPL_NUM_KW);
39 
40  if (recurse && replica_number) {
42  }
43 
44  int status;
45  ruleExecInfo_t rei;
46  collInfo_t collInfo;
48  specCollCache_t *specCollCache = NULL;
49 
50  resolveLinkedPath( rsComm, rmCollInp->collName, &specCollCache,
51  &rmCollInp->condInput );
53  rsComm,
55  ( const char* )rmCollInp->collName,
56  &rodsServerHost );
57 
58  if ( status < 0 || NULL == rodsServerHost ) { // JMC cppcheck - nullptr
59  return status;
60  }
61  else if ( rodsServerHost->rcatEnabled == REMOTE_ICAT ) {
62  status = rcRmColl( rodsServerHost->conn, rmCollInp, 0 );
63  return status;
64  }
65 
66  initReiWithCollInp( &rei, rsComm, rmCollInp, &collInfo );
67 
68  status = applyRule( "acPreprocForRmColl", NULL, &rei, NO_SAVE_REI );
69 
70  if ( status < 0 ) {
71  if ( rei.status < 0 ) {
72  status = rei.status;
73  }
75  "rsRmColl:acPreprocForRmColl error for %s,stat=%d",
76  rmCollInp->collName, status );
78  free(rei.condInputData);
79  return status;
80  }
81 
82  if ( collOprStat != NULL ) {
83  *collOprStat = NULL;
84  }
85  if ( getValByKey( &rmCollInp->condInput, RECURSIVE_OPR__KW ) == NULL ) {
86  status = _rsRmColl( rsComm, rmCollInp, collOprStat );
87  }
88  else {
89  if ( isTrashPath( rmCollInp->collName ) == False &&
90  getValByKey( &rmCollInp->condInput, FORCE_FLAG_KW ) != NULL ) {
92  "rsRmColl: Recursively removing %s.",
93  rmCollInp->collName );
94  }
95  status = _rsRmCollRecur( rsComm, rmCollInp, collOprStat );
96  }
97  rei.status = status;
98  rei.status = applyRule( "acPostProcForRmColl", NULL, &rei,
99  NO_SAVE_REI );
100 
102  free(rei.condInputData);
103 
104  if ( rei.status < 0 ) {
106  "rsRmColl:acPostProcForRmColl error for %s,stat=%d",
107  rmCollInp->collName, status );
108  }
109 
110  return status;
111 }
112 
113 int
114 _rsRmColl( rsComm_t *rsComm, collInp_t *rmCollInp,
115  collOprStat_t **collOprStat ) {
116  int status;
117  dataObjInfo_t *dataObjInfo = NULL;
118 
119  if ( getValByKey( &rmCollInp->condInput, UNREG_COLL_KW ) != NULL ) {
120  status = svrUnregColl( rsComm, rmCollInp );
121  }
122  else {
123  /* need to check if it is spec coll */
124  status = resolvePathInSpecColl( rsComm, rmCollInp->collName,
125  WRITE_COLL_PERM, 0, &dataObjInfo );
126  if ( status < 0 && status != CAT_NO_ROWS_FOUND ) {
127  return status;
128  }
129  else if ( status == COLL_OBJ_T && dataObjInfo->specColl != NULL ) {
130  if ( dataObjInfo->specColl->collClass == LINKED_COLL ) {
131  rstrcpy( rmCollInp->collName, dataObjInfo->objPath,
132  MAX_NAME_LEN );
133  status = svrUnregColl( rsComm, rmCollInp );
134  }
135  else {
136  status = l3Rmdir( rsComm, dataObjInfo );
137  }
138  freeDataObjInfo( dataObjInfo );
139  }
140  else {
141  status = svrUnregColl( rsComm, rmCollInp );
142  }
143  }
144  if ( status >= 0 && collOprStat != NULL ) {
145  *collOprStat = ( collOprStat_t* )malloc( sizeof( collOprStat_t ) );
146  memset( *collOprStat, 0, sizeof( collOprStat_t ) );
147  ( *collOprStat )->filesCnt = 1;
148  ( *collOprStat )->totalFileCnt = 1;
149  rstrcpy( ( *collOprStat )->lastObjPath, rmCollInp->collName,
150  MAX_NAME_LEN );
151  }
152  return status;
153 }
154 
155 int
156 _rsRmCollRecur( rsComm_t *rsComm, collInp_t *rmCollInp,
157  collOprStat_t **collOprStat ) {
158  int status;
159  ruleExecInfo_t rei;
160  int trashPolicy;
161  dataObjInfo_t *dataObjInfo = NULL;
162  /* check for specColl and permission */
163  status = resolvePathInSpecColl( rsComm, rmCollInp->collName,
164  WRITE_COLL_PERM, 0, &dataObjInfo );
165 
166  if ( status < 0 && status != CAT_NO_ROWS_FOUND ) {
167  return status;
168  }
169  if ( status == COLL_OBJ_T && dataObjInfo->specColl != NULL &&
170  dataObjInfo->specColl->collClass == LINKED_COLL ) {
171  rstrcpy( rmCollInp->collName, dataObjInfo->objPath,
172  MAX_NAME_LEN );
173  free( dataObjInfo->specColl );
174  dataObjInfo->specColl = NULL;
175  }
176  if ( status != COLL_OBJ_T || dataObjInfo->specColl == NULL ) {
177  /* a normal coll */
178  if ( rmCollInp->oprType != UNREG_OPR &&
179  getValByKey( &rmCollInp->condInput, FORCE_FLAG_KW ) == NULL &&
180  getValByKey( &rmCollInp->condInput, RMTRASH_KW ) == NULL &&
181  getValByKey( &rmCollInp->condInput, ADMIN_RMTRASH_KW ) == NULL ) {
182  initReiWithDataObjInp( &rei, rsComm, NULL );
183  status = applyRule( "acTrashPolicy", NULL, &rei, NO_SAVE_REI );
185  free(rei.condInputData);
186  trashPolicy = rei.status;
187  if ( trashPolicy != NO_TRASH_CAN ) {
188  status = rsMvCollToTrash( rsComm, rmCollInp );
189  if ( status >= 0 && collOprStat != NULL ) {
190  if ( *collOprStat == NULL ) {
191  *collOprStat = ( collOprStat_t* )malloc( sizeof( collOprStat_t ) );
192  memset( *collOprStat, 0, sizeof( collOprStat_t ) );
193  }
194  ( *collOprStat )->filesCnt = 1;
195  ( *collOprStat )->totalFileCnt = 1;
196  rstrcpy( ( *collOprStat )->lastObjPath, rmCollInp->collName,
197  MAX_NAME_LEN );
198  }
199  return status;
200  }
201  }
202  }
203  /* got here. will recursively phy delete the collection */
204  status = _rsPhyRmColl( rsComm, rmCollInp, dataObjInfo, collOprStat );
205 
206  if ( dataObjInfo != NULL ) {
207  freeDataObjInfo( dataObjInfo );
208  }
209  return status;
210 }
211 
212 int
213 _rsPhyRmColl( rsComm_t *rsComm, collInp_t *rmCollInp,
214  dataObjInfo_t *dataObjInfo, collOprStat_t **collOprStat ) {
215 
216  char *tmpValue;
217  int status;
218  collInp_t openCollInp;
219  int handleInx;
220  dataObjInp_t dataObjInp;
221  collInp_t tmpCollInp;
222  int rmtrashFlag = 0;
223  int savedStatus = 0;
224  int fileCntPerStatOut = FILE_CNT_PER_STAT_OUT;
225  int entCnt = 0;
226  ruleExecInfo_t rei;
227  collInfo_t collInfo;
228 
229  memset( &openCollInp, 0, sizeof( openCollInp ) );
230  rstrcpy( openCollInp.collName, rmCollInp->collName, MAX_NAME_LEN );
231  /* cannot query recur because collection is sorted in wrong order */
232  openCollInp.flags = 0;
233  handleInx = rsOpenCollection( rsComm, &openCollInp );
234  if ( handleInx < 0 ) {
236  "_rsPhyRmColl: rsOpenCollection of %s error. status = %d",
237  openCollInp.collName, handleInx );
238  return handleInx;
239  }
240 
241  memset( &dataObjInp, 0, sizeof( dataObjInp ) );
242  memset( &tmpCollInp, 0, sizeof( tmpCollInp ) );
243  /* catch the UNREG_OPR */
244  dataObjInp.oprType = tmpCollInp.oprType = rmCollInp->oprType;
245 
246  if ( ( tmpValue = getValByKey( &rmCollInp->condInput, AGE_KW ) ) != NULL ) {
247  if ( CollHandle[handleInx].rodsObjStat != NULL ) {
248  /* when a collection is moved, the modfiyTime of the object in
249  * the collectin does not change. So, we'll depend on the
250  * modfiyTime of the collection */
251  int ageLimit = atoi( tmpValue ) * 60;
252  int modifyTime =
253  atoi( CollHandle[handleInx].rodsObjStat->modifyTime );
254  if ( ( time( 0 ) - modifyTime ) < ageLimit ) {
255  rsCloseCollection( rsComm, &handleInx );
256  return 0;
257  }
258  }
259  addKeyVal( &dataObjInp.condInput, AGE_KW, tmpValue );
260  addKeyVal( &tmpCollInp.condInput, AGE_KW, tmpValue );
261  }
262  addKeyVal( &dataObjInp.condInput, FORCE_FLAG_KW, "" );
263  addKeyVal( &tmpCollInp.condInput, FORCE_FLAG_KW, "" );
264 
265  if ( ( tmpValue = getValByKey( &rmCollInp->condInput, AGE_KW ) ) != NULL ) {
266  addKeyVal( &dataObjInp.condInput, AGE_KW, tmpValue );
267  addKeyVal( &tmpCollInp.condInput, AGE_KW, tmpValue );
268  }
269 
270  if ( collOprStat != NULL && *collOprStat == NULL ) {
271  *collOprStat = ( collOprStat_t* )malloc( sizeof( collOprStat_t ) );
272  memset( *collOprStat, 0, sizeof( collOprStat_t ) );
273  }
274 
275  if (getValByKey(&rmCollInp->condInput, ADMIN_KW)) {
278  }
279  addKeyVal(&tmpCollInp.condInput, ADMIN_KW, "");
280  addKeyVal(&dataObjInp.condInput, ADMIN_KW, "");
281  }
282 
283  if ( getValByKey( &rmCollInp->condInput, ADMIN_RMTRASH_KW ) != NULL ) {
284  if ( isTrashPath( rmCollInp->collName ) == False ) {
285  return SYS_INVALID_FILE_PATH;
286  }
289  }
290  addKeyVal( &tmpCollInp.condInput, ADMIN_RMTRASH_KW, "" );
291  addKeyVal( &dataObjInp.condInput, ADMIN_RMTRASH_KW, "" );
292  rmtrashFlag = 2;
293  }
294  else if ( getValByKey( &rmCollInp->condInput, RMTRASH_KW ) != NULL ) {
295  if ( isTrashPath( rmCollInp->collName ) == False ) {
296  return SYS_INVALID_FILE_PATH;
297  }
298  addKeyVal( &tmpCollInp.condInput, RMTRASH_KW, "" );
299  addKeyVal( &dataObjInp.condInput, RMTRASH_KW, "" );
300  rmtrashFlag = 1;
301  }
302  // =-=-=-=-=-=-=-
303  // JMC - backport 4552
304  if ( getValByKey( &rmCollInp->condInput, EMPTY_BUNDLE_ONLY_KW ) != NULL ) {
305  addKeyVal( &tmpCollInp.condInput, EMPTY_BUNDLE_ONLY_KW, "" );
306  addKeyVal( &dataObjInp.condInput, EMPTY_BUNDLE_ONLY_KW, "" );
307  }
308  // =-=-=-=-=-=-=-
309  collEnt_t *collEnt = NULL;
310  while ( ( status = rsReadCollection( rsComm, &handleInx, &collEnt ) ) >= 0 ) {
311  if ( entCnt == 0 ) {
312  entCnt ++;
313  /* cannot rm non-empty home collection */
314  if ( isHomeColl( rmCollInp->collName ) ) {
315  free( collEnt );
317  }
318  }
319  if ( collEnt->objType == DATA_OBJ_T ) {
320  snprintf( dataObjInp.objPath, MAX_NAME_LEN, "%s/%s",
321  collEnt->collName, collEnt->dataName );
322 
323  status = rsDataObjUnlink( rsComm, &dataObjInp );
324  if ( status < 0 ) {
326  "_rsPhyRmColl:rsDataObjUnlink failed for %s. stat = %d",
327  dataObjInp.objPath, status );
328  /* need to set global error here */
329  savedStatus = status;
330  }
331  else if ( collOprStat != NULL ) {
332  ( *collOprStat )->filesCnt ++;
333  if ( ( *collOprStat )->filesCnt >= fileCntPerStatOut ) {
334  rstrcpy( ( *collOprStat )->lastObjPath, dataObjInp.objPath,
335  MAX_NAME_LEN );
336  status = svrSendCollOprStat( rsComm, *collOprStat );
337  if ( status < 0 ) {
339  "_rsPhyRmColl: svrSendCollOprStat failed for %s. status = %d",
340  rmCollInp->collName, status );
341  *collOprStat = NULL;
342  savedStatus = status;
343  free( collEnt );
344  break;
345  }
346  *collOprStat = ( collOprStat_t* )malloc( sizeof( collOprStat_t ) );
347  memset( *collOprStat, 0, sizeof( collOprStat_t ) );
348  }
349  }
350  }
351  else if ( collEnt->objType == COLL_OBJ_T ) {
352  if ( strcmp( collEnt->collName, rmCollInp->collName ) == 0 ) {
353  free( collEnt );
354  collEnt = NULL;
355  continue; /* duplicate */
356  }
357  rstrcpy( tmpCollInp.collName, collEnt->collName, MAX_NAME_LEN );
358  if ( collEnt->specColl.collClass != NO_SPEC_COLL ) {
359  if ( strcmp( collEnt->collName, collEnt->specColl.collection )
360  == 0 ) {
361  free( collEnt );
362  collEnt = NULL;
363  continue; /* no mount point */
364  }
365  }
366  initReiWithCollInp( &rei, rsComm, &tmpCollInp, &collInfo );
367  status = applyRule( "acPreprocForRmColl", NULL, &rei, NO_SAVE_REI );
368  if ( status < 0 ) {
369  if ( rei.status < 0 ) {
370  status = rei.status;
371  }
373  "_rsPhyRmColl:acPreprocForRmColl error for %s,stat=%d",
374  tmpCollInp.collName, status );
375  free( collEnt );
376  return status;
377  }
378  status = _rsRmCollRecur( rsComm, &tmpCollInp, collOprStat );
379  if (status < 0) {
381  "[%s]:_rsRmCollRecur error for [%s],stat=[%d]",
382  __FUNCTION__, tmpCollInp.collName, status );
383  }
384  rei.status = applyRule( "acPostProcForRmColl", NULL, &rei,
385  NO_SAVE_REI );
386  if ( rei.status < 0 ) {
388  "_rsRmColl:acPostProcForRmColl error for %s,stat=%d",
389  tmpCollInp.collName, status );
390  }
391  }
392  if ( status < 0 ) {
393  savedStatus = status;
394  }
395  free( collEnt );
396  collEnt = NULL;
397  }
398  rsCloseCollection( rsComm, &handleInx );
399 
400  if ( ( rmtrashFlag > 0 && ( isTrashHome( rmCollInp->collName ) > 0 || // JMC - backport 4561
401  isOrphanPath( rmCollInp->collName ) == is_ORPHAN_HOME ) ) ||
402  ( isBundlePath( rmCollInp->collName ) == True &&
403  getValByKey( &rmCollInp->condInput, EMPTY_BUNDLE_ONLY_KW ) != NULL ) ) {
404  /* don't rm user's home trash coll or orphan collection */
405  status = 0;
406  }
407  else {
408  if ( dataObjInfo != NULL && dataObjInfo->specColl != NULL ) {
409  if ( dataObjInfo->specColl->collClass == LINKED_COLL ) {
410  rstrcpy( rmCollInp->collName, dataObjInfo->objPath,
411  MAX_NAME_LEN );
412  status = svrUnregColl( rsComm, rmCollInp );
413  }
414  else {
415  status = l3Rmdir( rsComm, dataObjInfo );
416  }
417  }
418  else {
419  status = svrUnregColl( rsComm, rmCollInp );
420  if ( status < 0 ) {
421  savedStatus = status;
422  }
423  }
424  }
425  clearKeyVal( &tmpCollInp.condInput );
426  clearKeyVal( &dataObjInp.condInput );
427 
428  return savedStatus;
429 }
430 
431 int
432 svrUnregColl( rsComm_t *rsComm, collInp_t *rmCollInp ) {
433  int status;
434 
436 
438  rsComm,
439  MASTER_RCAT,
440  ( const char* )rmCollInp->collName,
441  &rodsServerHost );
442  if ( status < 0 || NULL == rodsServerHost ) { // JMC cppcheck - nullptr
443  return status;
444  }
445 
446  if ( rodsServerHost->localFlag == LOCAL_HOST ) {
447  std::string svc_role;
448  irods::error ret = get_catalog_service_role(svc_role);
449  if(!ret.ok()) {
450  irods::log(PASS(ret));
451  return ret.code();
452  }
453 
454  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
455  collInfo_t collInfo{};
456  rstrcpy( collInfo.collName, rmCollInp->collName, MAX_NAME_LEN );
457  if (getValByKey(&rmCollInp->condInput, ADMIN_RMTRASH_KW) ||
458  getValByKey(&rmCollInp->condInput, ADMIN_KW)) {
459  status = chlDelCollByAdmin( rsComm, &collInfo );
460  if ( status >= 0 ) {
461  chlCommit( rsComm );
462  }
463  }
464  else {
465  status = chlDelColl( rsComm, &collInfo );
466  }
467  } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
469  } else {
470  rodsLog(
471  LOG_ERROR,
472  "role not supported [%s]",
473  svc_role.c_str() );
475  }
476  }
477  else {
478  collOprStat_t *collOprStat = NULL;;
479  addKeyVal( &rmCollInp->condInput, UNREG_COLL_KW, "" );
480  status = _rcRmColl( rodsServerHost->conn, rmCollInp, &collOprStat );
481  if ( collOprStat != NULL ) {
482  free( collOprStat );
483  }
484  }
485 
486  return status;
487 }
488 
489 int
490 rsMkTrashPath( rsComm_t *rsComm, char *objPath, char *trashPath ) {
491  int status;
492  char *tmpStr;
493  char startTrashPath[MAX_NAME_LEN];
494  char destTrashColl[MAX_NAME_LEN], myFile[MAX_NAME_LEN];
495  char *trashPathPtr;
496 
497  trashPathPtr = trashPath;
498  *trashPathPtr = '/';
499  trashPathPtr++;
500  tmpStr = objPath + 1;
501  /* copy the zone */
502  while ( *tmpStr != '\0' ) {
503  *trashPathPtr = *tmpStr;
504  trashPathPtr ++;
505  if ( *tmpStr == '/' ) {
506  tmpStr ++;
507  break;
508  }
509  tmpStr ++;
510  }
511 
512  if ( *tmpStr == '\0' ) {
514  "rsMkTrashPath: input path %s too short", objPath );
515  return USER_INPUT_PATH_ERR;
516  }
517 
518  /* skip "home/userName/" or "home/userName#" */
519 
520  if ( strncmp( tmpStr, "home/", 5 ) == 0 ) {
521  int nameLen;
522  tmpStr += 5;
523  nameLen = strlen( rsComm->clientUser.userName );
524  if ( strncmp( tmpStr, rsComm->clientUser.userName, nameLen ) == 0 &&
525  ( *( tmpStr + nameLen ) == '/' || *( tmpStr + nameLen ) == '#' ) ) {
526  /* tmpStr += (nameLen + 1); */
527  tmpStr = strchr( tmpStr, '/' ) + 1;
528  }
529  }
530 
531 
532  /* don't want to go back beyond /myZone/trash/home */
533  *trashPathPtr = '\0';
534  snprintf( startTrashPath, MAX_NAME_LEN, "%strash/home", trashPath );
535 
536  /* add home/userName/ */
537 
538  if ( rsComm->clientUser.authInfo.authFlag == REMOTE_USER_AUTH ||
540  /* remote user */
541  snprintf( trashPathPtr, MAX_NAME_LEN, "trash/home/%s#%s/%s",
542  rsComm->clientUser.userName, rsComm->clientUser.rodsZone, tmpStr );
543  }
544  else {
545  snprintf( trashPathPtr, MAX_NAME_LEN, "trash/home/%s/%s",
546  rsComm->clientUser.userName, tmpStr );
547  }
548 
549  if ( ( status = splitPathByKey( trashPath, destTrashColl, MAX_NAME_LEN, myFile, MAX_NAME_LEN, '/' ) ) < 0 ) {
551  "rsMkTrashPath: splitPathByKey error for %s ", trashPath );
552  return USER_INPUT_PATH_ERR;
553  }
554 
555  status = rsMkCollR( rsComm, startTrashPath, destTrashColl );
556 
557  if ( status < 0 ) {
559  "rsMkTrashPath: rsMkCollR error for startPath %s, destPath %s ",
560  startTrashPath, destTrashColl );
561  }
562 
563  return status;
564 }
565 
566 int
567 l3Rmdir( rsComm_t *rsComm, dataObjInfo_t *dataObjInfo ) {
568  fileRmdirInp_t fileRmdirInp;
569  int status;
570 
571  // =-=-=-=-=-=-=-
572  // get the resc location of the hier leaf
573  std::string location;
574  irods::error ret = irods::get_loc_for_hier_string( dataObjInfo->rescHier, location );
575  if ( !ret.ok() ) {
576  irods::log( PASSMSG( "l3Rmdir - failed in get_loc_for_hier_string", ret ) );
577  return -1;
578  }
579 
580  if ( getStructFileType( dataObjInfo->specColl ) >= 0 ) {
581  subFile_t subFile;
582  memset( &subFile, 0, sizeof( subFile ) );
583  rstrcpy( subFile.subFilePath, dataObjInfo->subPath, MAX_NAME_LEN );
584  rstrcpy( subFile.addr.hostAddr, location.c_str(), NAME_LEN );
585  subFile.specColl = dataObjInfo->specColl;
586  status = rsSubStructFileRmdir( rsComm, &subFile );
587  }
588  else {
589  memset( &fileRmdirInp, 0, sizeof( fileRmdirInp ) );
590  rstrcpy( fileRmdirInp.dirName, dataObjInfo->filePath, MAX_NAME_LEN );
591  rstrcpy( fileRmdirInp.addr.hostAddr, location.c_str(), NAME_LEN );
592  rstrcpy( fileRmdirInp.rescHier, dataObjInfo->rescHier, MAX_NAME_LEN );
593  status = rsFileRmdir( rsComm, &fileRmdirInp );
594  }
595  return status;
596 }
597 
598 int
599 rsMvCollToTrash( rsComm_t *rsComm, collInp_t *rmCollInp ) {
600  int status;
601  char trashPath[MAX_NAME_LEN];
602  dataObjCopyInp_t dataObjRenameInp;
603  genQueryInp_t genQueryInp;
604  genQueryOut_t *genQueryOut = NULL;
605  int continueInx;
606  dataObjInfo_t dataObjInfo;
607 
608  /* check permission of files */
609 
610  memset( &genQueryInp, 0, sizeof( genQueryInp ) );
611  status = rsQueryDataObjInCollReCur( rsComm, rmCollInp->collName,
612  &genQueryInp, &genQueryOut, ACCESS_DELETE_OBJECT, 0 );
613 
614  memset( &dataObjInfo, 0, sizeof( dataObjInfo ) );
615  while ( status >= 0 ) {
616  sqlResult_t *subColl, *dataObj, *rescName;
617  ruleExecInfo_t rei;
618 
619  /* check if allow to delete */
620 
621  if ( ( subColl = getSqlResultByInx( genQueryOut, COL_COLL_NAME ) )
622  == NULL ) {
624  "rsMvCollToTrash: getSqlResultByInx for COL_COLL_NAME failed" );
625  return UNMATCHED_KEY_OR_INDEX;
626  }
627 
628  if ( ( dataObj = getSqlResultByInx( genQueryOut, COL_DATA_NAME ) )
629  == NULL ) {
631  "rsMvCollToTrash: getSqlResultByInx for COL_DATA_NAME failed" );
632  return UNMATCHED_KEY_OR_INDEX;
633  }
634 
635  if ( ( rescName = getSqlResultByInx( genQueryOut, COL_D_RESC_NAME ) )
636  == NULL ) {
638  "rsMvCollToTrash: getSqlResultByInx for COL_D_RESC_NAME failed" );
639  return UNMATCHED_KEY_OR_INDEX;
640  }
641 
642  snprintf( dataObjInfo.objPath, MAX_NAME_LEN, "%s/%s",
643  subColl->value, dataObj->value );
644  rstrcpy( dataObjInfo.rescName, rescName->value, NAME_LEN );
645 
646  initReiWithDataObjInp( &rei, rsComm, NULL );
647  rei.doi = &dataObjInfo;
648 
649  // make resource properties available as rule session variables
651 
652  status = applyRule( "acDataDeletePolicy", NULL, &rei, NO_SAVE_REI );
653 
655  free(rei.condInputData);
656 
657  if ( status < 0 && status != NO_MORE_RULES_ERR &&
660  "rsMvCollToTrash: acDataDeletePolicy error for %s. status = %d",
661  dataObjInfo.objPath, status );
662  return status;
663  }
664 
665  if ( rei.status == SYS_DELETE_DISALLOWED ) {
667  "rsMvCollToTrash:disallowed for %s via DataDeletePolicy,status=%d",
668  dataObjInfo.objPath, rei.status );
669  return rei.status;
670  }
671 
672  continueInx = genQueryOut->continueInx;
673 
674  freeGenQueryOut( &genQueryOut );
675 
676  if ( continueInx > 0 ) {
677  /* More to come */
678  genQueryInp.continueInx = continueInx;
679  status = rsGenQuery( rsComm, &genQueryInp, &genQueryOut );
680  }
681  else {
682  break;
683  }
684  }
685 
686  if ( status < 0 && status != CAT_NO_ROWS_FOUND ) {
688  "rsMvCollToTrash: rsQueryDataObjInCollReCur error for %s, stat=%d",
689  rmCollInp->collName, status );
690  freeGenQueryOut( &genQueryOut );
691  return status;
692  }
693 
694  status = rsMkTrashPath( rsComm, rmCollInp->collName, trashPath );
695 
696  if ( status < 0 ) {
697  appendRandomToPath( trashPath );
698  status = rsMkTrashPath( rsComm, rmCollInp->collName, trashPath );
699  if ( status < 0 ) {
700  return status;
701  }
702  }
703 
704  memset( &dataObjRenameInp, 0, sizeof( dataObjRenameInp ) );
705 
706  dataObjRenameInp.srcDataObjInp.oprType =
707  dataObjRenameInp.destDataObjInp.oprType = RENAME_COLL;
708 
709  rstrcpy( dataObjRenameInp.destDataObjInp.objPath, trashPath, MAX_NAME_LEN );
710  rstrcpy( dataObjRenameInp.srcDataObjInp.objPath, rmCollInp->collName,
711  MAX_NAME_LEN );
712 
713  status = rsDataObjRename( rsComm, &dataObjRenameInp );
714 
716  appendRandomToPath( dataObjRenameInp.destDataObjInp.objPath );
717  status = rsDataObjRename( rsComm, &dataObjRenameInp );
718  }
719 
720  if ( status < 0 ) {
722  "mvCollToTrash: rcDataObjRename error for %s, status = %d",
723  dataObjRenameInp.destDataObjInp.objPath, status );
724  return status;
725  }
726 
727  return status;
728 }
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
getValByKey
char * getValByKey(const keyValPair_t *condInput, const char *keyWord)
Definition: rcMisc.cpp:675
DataObjInp::objPath
char objPath[(1024+64)]
Definition: dataObjInpOut.h:66
chlDelCollByAdmin
int chlDelCollByAdmin(rsComm_t *rsComm, collInfo_t *collInfo)
Definition: icatHighLevelRoutines.cpp:1774
NO_TRASH_CAN
#define NO_TRASH_CAN
Definition: objInfo.h:263
NULL
#define NULL
Definition: rodsDef.h:70
appendRandomToPath
int appendRandomToPath(char *trashPath)
Definition: rcMisc.cpp:2348
fileRmdir.h
rsComm_t
Definition: rcConnect.h:145
True
#define True
Definition: parseCommandLine.h:11
DataObjCopyInp::srcDataObjInp
dataObjInp_t srcDataObjInp
Definition: dataObjCopy.h:26
rsReadCollection
int rsReadCollection(rsComm_t *rsComm, int *handleInxInp, collEnt_t **collEnt)
Definition: rsReadCollection.cpp:15
addKeyVal
int addKeyVal(keyValPair_t *condInput, const char *keyWord, const char *value)
Definition: rcMisc.cpp:789
irods::CFG_SERVICE_ROLE_CONSUMER
const std::string CFG_SERVICE_ROLE_CONSUMER("consumer")
rsOpenCollection
int rsOpenCollection(rsComm_t *rsComm, collInp_t *openCollInp)
Definition: rsOpenCollection.cpp:16
irods_configuration_keywords.hpp
rsFileRmdir
int rsFileRmdir(rsComm_t *rsComm, fileRmdirInp_t *fileRmdirInp)
Definition: rsFileRmdir.cpp:21
rodsServerHost::localFlag
int localFlag
Definition: rodsConnect.h:68
GenQueryInp::continueInx
int continueInx
Definition: rodsGenQuery.h:28
SYS_SERVICE_ROLE_NOT_SUPPORTED
@ SYS_SERVICE_ROLE_NOT_SUPPORTED
Definition: rodsErrorTable.h:217
is_ORPHAN_HOME
@ is_ORPHAN_HOME
Definition: rodsDef.h:174
DataObjCopyInp
Definition: dataObjCopy.h:25
specColl.hpp
CollInp
Definition: dataObjInpOut.h:157
UNMATCHED_KEY_OR_INDEX
@ UNMATCHED_KEY_OR_INDEX
Definition: rodsErrorTable.h:244
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
fileRmdirInp_t::addr
rodsHostAddr_t addr
Definition: fileRmdir.h:12
userInfo_t::userName
char userName[64]
Definition: rodsUser.h:66
Subfile
Definition: objInfo.h:316
rodsServerHost::rcatEnabled
int rcatEnabled
Definition: rodsConnect.h:65
RuleExecInfo::status
int status
Definition: irods_re_structs.hpp:19
PASS
#define PASS(prev_error_)
Definition: irods_error.hpp:118
Subfile::subFilePath
char subFilePath[(1024+64)]
Definition: objInfo.h:318
NO_SAVE_REI
#define NO_SAVE_REI
Definition: rodsDef.h:103
CollEnt::collName
char * collName
Definition: miscUtil.h:119
CollHandle
std::vector< collHandle_t > CollHandle
Definition: irods_server_globals.cpp:31
GenQueryInp
Definition: rodsGenQuery.h:24
_rsRmColl
int _rsRmColl(rsComm_t *rsComm, collInp_t *rmCollInp, collOprStat_t **collOprStat)
Definition: rsRmColl.cpp:114
freeDataObjInfo
int freeDataObjInfo(dataObjInfo_t *dataObjInfo)
Definition: rcMisc.cpp:544
rsOpenCollection.hpp
RENAME_COLL
#define RENAME_COLL
Definition: dataObjInpOut.h:178
isOrphanPath
orphanPathType_t isOrphanPath(char *myPath)
Definition: rcMisc.cpp:2473
getStructFileType
int getStructFileType(specColl_t *specColl)
Definition: objMetaOpr.cpp:386
DataObjInfo::rescHier
char rescHier[(1024+64)]
Definition: objInfo.h:132
dataObjRename.h
LOCAL_HOST
#define LOCAL_HOST
Definition: rodsConnect.h:44
irods::experimental::filesystem::replica_number
replica_number
Definition: filesystem.hpp:51
RuleExecInfo::doi
dataObjInfo_t * doi
Definition: irods_re_structs.hpp:28
svrUnregColl
int svrUnregColl(rsComm_t *rsComm, collInp_t *rmCollInp)
Definition: rsRmColl.cpp:432
irods_resource_backport.hpp
Subfile::specColl
specColl_t * specColl
Definition: objInfo.h:322
WRITE_COLL_PERM
@ WRITE_COLL_PERM
Definition: objInfo.h:99
REPL_NUM_KW
#define REPL_NUM_KW
Definition: rodsKeyWdDef.h:30
PASSMSG
#define PASSMSG(message_, prev_error_)
Definition: irods_error.hpp:119
rmColl.h
fileRmdirInp_t::rescHier
char rescHier[(1024+64)]
Definition: fileRmdir.h:14
DataObjInfo::filePath
char filePath[(1024+64)]
Definition: objInfo.h:137
chlCommit
int chlCommit(rsComm_t *rsComm)
Definition: icatHighLevelRoutines.cpp:1090
REMOTE_USER_AUTH
#define REMOTE_USER_AUTH
Definition: rodsUser.h:33
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
CollInp::flags
int flags
Definition: dataObjInpOut.h:159
RECURSIVE_OPR__KW
#define RECURSIVE_OPR__KW
Definition: rodsKeyWdDef.h:66
REMOTE_ICAT
#define REMOTE_ICAT
Definition: rodsConnect.h:54
rsReadCollection.hpp
readCollection.h
CollInfo
Definition: objInfo.h:177
DataObjInfo::specColl
specColl_t * specColl
Definition: objInfo.h:158
resolveLinkedPath
int resolveLinkedPath(rsComm_t *rsComm, char *objPath, specCollCache_t **specCollCache, keyValPair_t *condInput)
Definition: specColl.cpp:711
irods::get_resc_properties_as_kvp
error get_resc_properties_as_kvp(const std::string &, keyValPair_t *)
Definition: irods_resource_backport.cpp:500
initReiWithDataObjInp
int initReiWithDataObjInp(ruleExecInfo_t *rei, rsComm_t *rsComm, dataObjInp_t *dataObjIn)
Definition: irods_re_structs.cpp:164
rsSubStructFileRmdir.hpp
rsCloseCollection
int rsCloseCollection(rsComm_t *rsComm, int *handleInxInp)
Definition: rsCloseCollection.cpp:14
isHomeColl
int isHomeColl(char *myPath)
Definition: rcMisc.cpp:2508
COLL_OBJ_T
@ COLL_OBJ_T
Definition: rodsType.h:39
closeCollection.h
COL_DATA_NAME
#define COL_DATA_NAME
Definition: rodsGenQuery.h:165
CANT_RM_NON_EMPTY_HOME_COLL
@ CANT_RM_NON_EMPTY_HOME_COLL
Definition: rodsErrorTable.h:275
RuleExecInfo::condInputData
keyValPair_t * condInputData
Definition: irods_re_structs.hpp:34
irods::error::code
long long code() const
Definition: irods_error.cpp:194
LINKED_COLL
@ LINKED_COLL
Definition: objInfo.h:49
COL_D_RESC_NAME
#define COL_D_RESC_NAME
Definition: rodsGenQuery.h:171
_rcRmColl
int _rcRmColl(rcComm_t *conn, collInp_t *rmCollInp, collOprStat_t **collOprStat)
Definition: rcRmColl.cpp:14
rodsObjStat::modifyTime
char modifyTime[32]
Definition: objStat.h:17
getSqlResultByInx
sqlResult_t * getSqlResultByInx(genQueryOut_t *genQueryOut, int attriInx)
Definition: rcMisc.cpp:1387
GenQueryOut::continueInx
int continueInx
Definition: rodsGenQuery.h:70
fileRmdirInp_t::dirName
char dirName[(1024+64)]
Definition: fileRmdir.h:13
CAT_INSUFFICIENT_PRIVILEGE_LEVEL
@ CAT_INSUFFICIENT_PRIVILEGE_LEVEL
Definition: rodsErrorTable.h:445
rsMkTrashPath
int rsMkTrashPath(rsComm_t *rsComm, char *objPath, char *trashPath)
Definition: rsRmColl.cpp:490
collOprStat_t
Definition: objInfo.h:298
_rsRmCollRecur
int _rsRmCollRecur(rsComm_t *rsComm, collInp_t *rmCollInp, collOprStat_t **collOprStat)
Definition: rsRmColl.cpp:156
subStructFileRmdir.h
rsDataObjRename.hpp
irods::CFG_SERVICE_ROLE_PROVIDER
const std::string CFG_SERVICE_ROLE_PROVIDER("provider")
CollEnt
Definition: miscUtil.h:113
NO_MORE_RULES_ERR
@ NO_MORE_RULES_ERR
Definition: rodsErrorTable.h:594
CollEnt::specColl
specColl_t specColl
Definition: miscUtil.h:130
isTrashHome
int isTrashHome(char *myPath)
Definition: rcMisc.cpp:2427
FILE_CNT_PER_STAT_OUT
#define FILE_CNT_PER_STAT_OUT
Definition: objInfo.h:297
DataObjInp
Definition: dataObjInpOut.h:65
genQuery.h
REMOTE_PRIV_USER_AUTH
#define REMOTE_PRIV_USER_AUTH
Definition: rodsUser.h:35
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
rsDataObjRename
int rsDataObjRename(rsComm_t *rsComm, dataObjCopyInp_t *dataObjRenameInp)
Definition: rsDataObjRename.cpp:42
chlDelColl
int chlDelColl(rsComm_t *rsComm, collInfo_t *collInfo)
Definition: icatHighLevelRoutines.cpp:1824
RMTRASH_KW
#define RMTRASH_KW
Definition: rodsKeyWdDef.h:65
rsMvCollToTrash
int rsMvCollToTrash(rsComm_t *rsComm, collInp_t *rmCollInp)
Definition: rsRmColl.cpp:599
Subfile::addr
rodsHostAddr_t addr
Definition: objInfo.h:317
SYS_NO_RCAT_SERVER_ERR
@ SYS_NO_RCAT_SERVER_ERR
Definition: rodsErrorTable.h:110
CollInp::condInput
keyValPair_t condInput
Definition: dataObjInpOut.h:161
ADMIN_KW
#define ADMIN_KW
Definition: rodsKeyWdDef.h:62
GenQueryOut
Definition: rodsGenQuery.h:67
EMPTY_BUNDLE_ONLY_KW
#define EMPTY_BUNDLE_ONLY_KW
Definition: rodsKeyWdDef.h:111
LOCAL_PRIV_USER_AUTH
#define LOCAL_PRIV_USER_AUTH
Definition: rodsUser.h:36
svrSendCollOprStat
int svrSendCollOprStat(rsComm_t *rsComm, collOprStat_t *collOprStat)
Definition: rsApiHandler.cpp:660
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
NO_SPEC_COLL
@ NO_SPEC_COLL
Definition: objInfo.h:46
userInfo_t::rodsZone
char rodsZone[64]
Definition: rodsUser.h:67
collection.hpp
splitPathByKey
int splitPathByKey(const char *srcPath, char *dir, size_t maxDirLen, char *file, size_t maxFileLen, char key)
Definition: stringOpr.cpp:222
irods::log
void log(const error &)
Definition: irods_log.cpp:13
fileRmdirInp_t
Definition: fileRmdir.h:10
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
rcRmColl
int rcRmColl(rcComm_t *conn, collInp_t *rmCollInp, int vFlag)
Definition: rcRmColl.cpp:79
rsComm_t::clientUser
userInfo_t clientUser
Definition: rcConnect.h:153
resolvePathInSpecColl
int resolvePathInSpecColl(rsComm_t *rsComm, char *objPath, specCollPerm_t specCollPerm, int inCachOnly, dataObjInfo_t **dataObjInfo)
Definition: specColl.cpp:644
irods::error
Definition: irods_error.hpp:23
AGE_KW
#define AGE_KW
Definition: rodsKeyWdDef.h:221
miscServerFunct.hpp
DATA_OBJ_T
@ DATA_OBJ_T
Definition: rodsType.h:38
CollEnt::dataName
char * dataName
Definition: miscUtil.h:120
SYS_INVALID_FILE_PATH
@ SYS_INVALID_FILE_PATH
Definition: rodsErrorTable.h:99
getAndConnRcatHost
int getAndConnRcatHost(rsComm_t *rsComm, int rcatType, const char *rcatZoneHint, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:26
rsRmColl
int rsRmColl(rsComm_t *rsComm, collInp_t *rmCollInp, collOprStat_t **collOprStat)
Definition: rsRmColl.cpp:35
SpecColl::collection
char collection[(1024+64)]
Definition: objInfo.h:79
SqlResult::value
char * value
Definition: rodsGenQuery.h:64
DataObjCopyInp::destDataObjInp
dataObjInp_t destDataObjInp
Definition: dataObjCopy.h:27
UNREG_COLL_KW
#define UNREG_COLL_KW
Definition: rodsKeyWdDef.h:74
FORCE_FLAG_KW
#define FORCE_FLAG_KW
Definition: rodsKeyWdDef.h:13
isTrashPath
int isTrashPath(char *myPath)
Definition: rcMisc.cpp:2395
_rsPhyRmColl
int _rsPhyRmColl(rsComm_t *rsComm, collInp_t *rmCollInp, dataObjInfo_t *dataObjInfo, collOprStat_t **collOprStat)
Definition: rsRmColl.cpp:213
MASTER_RCAT
#define MASTER_RCAT
Definition: rodsDef.h:85
CAT_NAME_EXISTS_AS_COLLECTION
@ CAT_NAME_EXISTS_AS_COLLECTION
Definition: rodsErrorTable.h:448
get_catalog_service_role
irods::error get_catalog_service_role(std::string &_role)
Definition: miscServerFunct.cpp:3153
rodsServerHost
Definition: rodsConnect.h:62
DataObjInfo::rescName
char rescName[64]
Definition: objInfo.h:131
DataObjInp::oprType
int oprType
Definition: dataObjInpOut.h:72
rodsHostAddr_t::hostAddr
char hostAddr[256]
Definition: rodsDef.h:297
CAT_NO_ROWS_FOUND
@ CAT_NO_ROWS_FOUND
Definition: rodsErrorTable.h:423
SqlResult
Definition: rodsGenQuery.h:61
UNREG_OPR
#define UNREG_OPR
Definition: dataObjInpOut.h:190
rsMkCollR
int rsMkCollR(rsComm_t *rsComm, const char *startColl, const char *destColl)
Definition: collection.cpp:428
openCollection.h
rsSubStructFileRmdir
int rsSubStructFileRmdir(rsComm_t *rsComm, subFile_t *subFile)
Definition: rsSubStructFileRmdir.cpp:12
RuleExecInfo
Definition: irods_re_structs.hpp:18
COL_COLL_NAME
#define COL_COLL_NAME
Definition: rodsGenQuery.h:189
rodsLogError
void rodsLogError(int level, int errCode, char *formatStr,...)
Definition: rodsLog.cpp:422
SYS_DELETE_DISALLOWED
@ SYS_DELETE_DISALLOWED
Definition: rodsErrorTable.h:108
rsQueryDataObjInCollReCur
int rsQueryDataObjInCollReCur(rsComm_t *rsComm, char *collection, genQueryInp_t *genQueryInp, genQueryOut_t **genQueryOut, char *accessPerm, int singleFlag)
Definition: collection.cpp:131
applyRule
int applyRule(char *inAction, msParamArray_t *inMsParamArray, ruleExecInfo_t *rei, int reiSaveFlag)
Definition: irods_re_structs.cpp:65
rsFileRmdir.hpp
USER_INCOMPATIBLE_PARAMS
@ USER_INCOMPATIBLE_PARAMS
Definition: rodsErrorTable.h:288
icatHighLevelRoutines.hpp
CollEnt::objType
objType_t objType
Definition: miscUtil.h:114
CollInp::collName
char collName[(1024+64)]
Definition: dataObjInpOut.h:158
rodsObjStat
Definition: objStat.h:8
rsRmColl.hpp
DataObjInfo::objPath
char objPath[(1024+64)]
Definition: objInfo.h:130
False
#define False
Definition: parseCommandLine.h:12
isBundlePath
int isBundlePath(char *myPath)
Definition: rcMisc.cpp:2368
rsGenQuery.hpp
userInfo_t::authInfo
authInfo_t authInfo
Definition: rodsUser.h:70
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
rsApiHandler.hpp
DataObjInp::condInput
keyValPair_t condInput
Definition: dataObjInpOut.h:74
irods::get_loc_for_hier_string
error get_loc_for_hier_string(const std::string &_hier, std::string &_loc)
Definition: irods_resource_backport.cpp:633
l3Rmdir
int l3Rmdir(rsComm_t *rsComm, dataObjInfo_t *dataObjInfo)
Definition: rsRmColl.cpp:567
ACCESS_DELETE_OBJECT
#define ACCESS_DELETE_OBJECT
Definition: icatDefines.h:60
freeGenQueryOut
int freeGenQueryOut(genQueryOut_t **genQueryOut)
Definition: rcMisc.cpp:1133
NAME_LEN
#define NAME_LEN
Definition: rodsDef.h:55
authInfo_t::authFlag
int authFlag
Definition: rodsUser.h:42
clearKeyVal
int clearKeyVal(keyValPair_t *condInput)
Definition: rcMisc.cpp:1047
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
DataObjInfo
Definition: objInfo.h:129
USER_INPUT_PATH_ERR
@ USER_INPUT_PATH_ERR
Definition: rodsErrorTable.h:248
rsGenQuery
int rsGenQuery(rsComm_t *rsComm, genQueryInp_t *genQueryInp, genQueryOut_t **genQueryOut)
Definition: rsGenQuery.cpp:604
rsCloseCollection.hpp
initReiWithCollInp
int initReiWithCollInp(ruleExecInfo_t *rei, rsComm_t *rsComm, collInp_t *collCreateInp, collInfo_t *collInfo)
Definition: irods_re_structs.cpp:182
SpecCollCache
Definition: objInfo.h:102
ADMIN_RMTRASH_KW
#define ADMIN_RMTRASH_KW
Definition: rodsKeyWdDef.h:63
objMetaOpr.hpp
SpecColl::collClass
specCollClass_t collClass
Definition: objInfo.h:77
CollInp::oprType
int oprType
Definition: dataObjInpOut.h:160
DataObjInfo::subPath
char subPath[(1024+64)]
Definition: objInfo.h:157