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)  

bunUtil.cpp
Go to the documentation of this file.
1 
3 #include "rodsPath.h"
4 #include "rodsErrorTable.h"
5 #include "rodsLog.h"
6 #include "bunUtil.h"
7 #include "miscUtil.h"
8 #include "rcGlobalExtern.h"
9 
10 int
11 bunUtil( rcComm_t *conn, rodsEnv *myRodsEnv, rodsArguments_t *myRodsArgs,
12  rodsPathInp_t *rodsPathInp ) {
13  rodsPath_t *collPath, *structFilePath;
14  structFileExtAndRegInp_t structFileExtAndRegInp;
15 
16  if ( rodsPathInp == NULL ) {
17  return USER__NULL_INPUT_ERR;
18  }
19 
20  int savedStatus = initCondForBunOpr( myRodsEnv, myRodsArgs, &structFileExtAndRegInp );
21  if ( savedStatus < 0 ) {
22  return savedStatus;
23  }
24 
25  for ( int i = 0; i < rodsPathInp->numSrc; i++ ) {
26  collPath = &rodsPathInp->destPath[i]; /* iRODS Collection */
27  structFilePath = &rodsPathInp->srcPath[i]; /* iRODS StructFile */
28 
29  getRodsObjType( conn, collPath );
30 
31  rstrcpy( structFileExtAndRegInp.collection, collPath->outPath,
32  MAX_NAME_LEN );
33  rstrcpy( structFileExtAndRegInp.objPath, structFilePath->outPath,
34  MAX_NAME_LEN );
35 
36  int status = 0;
37  if ( myRodsArgs->extract == True ) { /* -x */
38  if ( myRodsArgs->condition == True ) {
39  rodsLog( LOG_ERROR, "bunUtil: cannot use -x and -c at the same time" );
40  return -1;
41  }
42  status = rcStructFileExtAndReg( conn, &structFileExtAndRegInp );
43  }
44  else if ( myRodsArgs->condition == True ) { /* -c - create */
45  status = rcStructFileBundle( conn, &structFileExtAndRegInp );
46  }
47  else if ( myRodsArgs->add == True ) { /* add to tar */ // JMC - backport 4643
48  status = rcStructFileBundle( conn, &structFileExtAndRegInp );
49  }
50  else {
52  "bunUtil: -x or -c must be specified" );
53  return -1;
54  }
55 
56  /* XXXX may need to return a global status */
57  if ( status < 0 &&
60  myRodsArgs->condition == True ) {
62  "bunUtil: A resc must be entered for non-existing structFile" );
63  }
64  else {
66  "bunUtil: opr error for %s, status = %d",
67  collPath->outPath, status );
68  savedStatus = status;
69  }
70  }
71  }
72  return savedStatus;
73 }
74 
75 int
76 initCondForBunOpr( rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs,
77  structFileExtAndRegInp_t *structFileExtAndRegInp ) {
78  if ( structFileExtAndRegInp == NULL ) {
80  "initCondForBunOpr: NULL structFileExtAndRegInp input" );
81  return USER__NULL_INPUT_ERR;
82  }
83 
84  memset( structFileExtAndRegInp, 0, sizeof( structFileExtAndRegInp_t ) );
85 
86  if ( rodsArgs == NULL ) {
87  return 0;
88  }
89 
90  if ( rodsArgs->dataType == True ) {
91  if ( rodsArgs->dataTypeString != NULL ) {
92  if ( strcmp( rodsArgs->dataTypeString, "t" ) == 0 ||
93  strcmp( rodsArgs->dataTypeString, TAR_DT_STR ) == 0 || // JMC - backport 4640
94  strcmp( rodsArgs->dataTypeString, "tar" ) == 0 ) {
95  addKeyVal( &structFileExtAndRegInp->condInput, DATA_TYPE_KW,
96  // =-=-=-=-=-=-=-
97  // JMC - backport 4633
98  TAR_DT_STR );
99  }
100  else if ( strcmp( rodsArgs->dataTypeString, "g" ) == 0 ||
101  strcmp( rodsArgs->dataTypeString, GZIP_TAR_DT_STR ) == 0 || // JMC - backport 4640
102  strcmp( rodsArgs->dataTypeString, "gzip" ) == 0 ) {
103  addKeyVal( &structFileExtAndRegInp->condInput, DATA_TYPE_KW, GZIP_TAR_DT_STR );
104  }
105  else if ( strcmp( rodsArgs->dataTypeString, "b" ) == 0 ||
106  strcmp( rodsArgs->dataTypeString, BZIP2_TAR_DT_STR ) == 0 || // JMC - backport 4640
107  strcmp( rodsArgs->dataTypeString, "bzip2" ) == 0 ) { // JMC - backport 4648
108  addKeyVal( &structFileExtAndRegInp->condInput, DATA_TYPE_KW, BZIP2_TAR_DT_STR );
109  }
110  else if ( strcmp( rodsArgs->dataTypeString, "z" ) == 0 ||
111  strcmp( rodsArgs->dataTypeString, ZIP_DT_STR ) == 0 || // JMC - backport 4640
112  strcmp( rodsArgs->dataTypeString, "zip" ) == 0 ) {
113  addKeyVal( &structFileExtAndRegInp->condInput, DATA_TYPE_KW, ZIP_DT_STR );
114  // =-=-=-=-=-=-=-
115  }
116  else {
117  rodsLog( LOG_ERROR, "bunUtil: Unknown dataType %s for ibun", // JMC - backport 4648
118  rodsArgs->dataTypeString );
120  }
121 
122  }
123  }
124  else if ( rodsArgs->condition == True ) { /* -c */
125  addKeyVal( &structFileExtAndRegInp->condInput, DATA_TYPE_KW,
126  "tar file" );
127 
128  }
129 
130  if ( rodsArgs->resource == True ) {
131  if ( rodsArgs->resourceString == NULL ) {
133  "initCondForBunOpr: NULL resourceString error" );
134  return USER__NULL_INPUT_ERR;
135  }
136  else {
137  addKeyVal( &structFileExtAndRegInp->condInput,
138  DEST_RESC_NAME_KW, rodsArgs->resourceString );
139  /* RESC_NAME_KW is need for unbundle. DEST_RESC_NAME_KW or
140  * DEF_RESC_NAME_KW are neede for bundle */
141  addKeyVal( &structFileExtAndRegInp->condInput, RESC_NAME_KW,
142  rodsArgs->resourceString );
143  }
144  }
145  else if ( myRodsEnv != NULL && strlen( myRodsEnv->rodsDefResource ) > 0 ) {
146  /* use rodsDefResource but set the DEF_RESC_NAME_KW instead.
147  * Used by dataObjCreate. Will only make a new replica only if
148  * DEST_RESC_NAME_KW is set */
149  addKeyVal( &structFileExtAndRegInp->condInput, DEF_RESC_NAME_KW,
150  myRodsEnv->rodsDefResource );
151  }
152 
153  if ( rodsArgs->force == True ) {
154  addKeyVal( &structFileExtAndRegInp->condInput, FORCE_FLAG_KW, "" );
155  }
156 
157  if ( rodsArgs->condition == True ) { /* -c - create */ // JMC - backport 4644
158  structFileExtAndRegInp->oprType = PRESERVE_COLL_PATH;
159  }
160 
161  if ( rodsArgs->add == True ) { /* add to tar */ // JMC - backport 4643
162  structFileExtAndRegInp->oprType = ADD_TO_TAR_OPR | PRESERVE_COLL_PATH; // JMC - backport 4644
163  addKeyVal( &structFileExtAndRegInp->condInput, FORCE_FLAG_KW, "" );
164  }
165 
166  if ( rodsArgs->bulk == True ) {
167  addKeyVal( &structFileExtAndRegInp->condInput, BULK_OPR_KW, "" );
168  }
169 
170  return 0;
171 }
172 
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
rodsArguments_t::add
int add
Definition: parseCommandLine.h:15
initCondForBunOpr
int initCondForBunOpr(rodsEnv *myRodsEnv, rodsArguments_t *rodsArgs, structFileExtAndRegInp_t *structFileExtAndRegInp)
Definition: bunUtil.cpp:76
RESC_NAME_KW
#define RESC_NAME_KW
Definition: rodsKeyWdDef.h:19
rcComm_t
Definition: rcConnect.h:95
NULL
#define NULL
Definition: rodsDef.h:70
BULK_OPR_KW
#define BULK_OPR_KW
Definition: rodsKeyWdDef.h:99
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
RodsPathInp
Definition: rodsPath.h:33
TAR_DT_STR
#define TAR_DT_STR
Definition: objInfo.h:28
StructFileExtAndRegInp
Definition: structFileExtAndReg.h:7
BZIP2_TAR_DT_STR
#define BZIP2_TAR_DT_STR
Definition: objInfo.h:30
rodsArguments_t::dataTypeString
char * dataTypeString
Definition: parseCommandLine.h:55
rcStructFileBundle
int rcStructFileBundle(rcComm_t *conn, structFileExtAndRegInp_t *structFileBundleInp)
Definition: rcStructFileBundle.cpp:23
bunUtil.h
bunUtil
int bunUtil(rcComm_t *conn, rodsEnv *myRodsEnv, rodsArguments_t *myRodsArgs, rodsPathInp_t *rodsPathInp)
Definition: bunUtil.cpp:11
StructFileExtAndRegInp::objPath
char objPath[(1024+64)]
Definition: structFileExtAndReg.h:8
rodsArguments_t::bulk
int bulk
Definition: parseCommandLine.h:27
rodsArguments_t::resource
int resource
Definition: parseCommandLine.h:86
rcGlobalExtern.h
RodsPathInp::srcPath
rodsPath_t * srcPath
Definition: rodsPath.h:35
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
DATA_TYPE_KW
#define DATA_TYPE_KW
Definition: rodsKeyWdDef.h:23
StructFileExtAndRegInp::collection
char collection[(1024+64)]
Definition: structFileExtAndReg.h:9
DEST_RESC_NAME_KW
#define DEST_RESC_NAME_KW
Definition: rodsKeyWdDef.h:20
RodsPathInp::destPath
rodsPath_t * destPath
Definition: rodsPath.h:36
rodsArguments_t::condition
int condition
Definition: parseCommandLine.h:29
ADD_TO_TAR_OPR
#define ADD_TO_TAR_OPR
Definition: syncMountedColl.h:13
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
ZIP_DT_STR
#define ZIP_DT_STR
Definition: objInfo.h:31
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
StructFileExtAndRegInp::condInput
keyValPair_t condInput
Definition: structFileExtAndReg.h:12
rodsLog.h
DEF_RESC_NAME_KW
#define DEF_RESC_NAME_KW
Definition: rodsKeyWdDef.h:21
rodsArguments_t::resourceString
char * resourceString
Definition: parseCommandLine.h:87
StructFileExtAndRegInp::oprType
int oprType
Definition: structFileExtAndReg.h:10
rodsArguments_t::force
int force
Definition: parseCommandLine.h:38
rodsEnv::rodsDefResource
char rodsDefResource[64]
Definition: getRodsEnv.h:17
RodsPath::outPath
char outPath[(1024+64)]
Definition: rodsPath.h:24
FORCE_FLAG_KW
#define FORCE_FLAG_KW
Definition: rodsKeyWdDef.h:13
CAT_NO_ROWS_FOUND
@ CAT_NO_ROWS_FOUND
Definition: rodsErrorTable.h:423
rodsLogError
void rodsLogError(int level, int errCode, char *formatStr,...)
Definition: rodsLog.cpp:422
RodsPathInp::numSrc
int numSrc
Definition: rodsPath.h:34
rcStructFileExtAndReg
int rcStructFileExtAndReg(rcComm_t *conn, structFileExtAndRegInp_t *structFileExtAndRegInp)
Definition: rcStructFileExtAndReg.cpp:23
rodsArguments_t::extract
int extract
Definition: parseCommandLine.h:115
GZIP_TAR_DT_STR
#define GZIP_TAR_DT_STR
Definition: objInfo.h:29
rodsErrorTable.h
RodsPath
Definition: rodsPath.h:18
miscUtil.h
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
rodsEnv
Definition: getRodsEnv.h:8
getRodsObjType
int getRodsObjType(rcComm_t *conn, rodsPath_t *rodsPath)
Definition: miscUtil.cpp:200
rodsArguments_t::dataType
int dataType
Definition: parseCommandLine.h:54
PRESERVE_COLL_PATH
#define PRESERVE_COLL_PATH
Definition: syncMountedColl.h:14
USER__NULL_INPUT_ERR
@ USER__NULL_INPUT_ERR
Definition: rodsErrorTable.h:247
SYS_CACHE_STRUCT_FILE_RESC_ERR
@ SYS_CACHE_STRUCT_FILE_RESC_ERR
Definition: rodsErrorTable.h:132
SYS_ZIP_FORMAT_NOT_SUPPORTED
@ SYS_ZIP_FORMAT_NOT_SUPPORTED
Definition: rodsErrorTable.h:191