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)  

rsCollCreate.cpp
Go to the documentation of this file.
1 
3 /* This is script-generated code (for the most part). */
4 /* See collCreate.h for a description of this API call.*/
5 
6 #include "rcMisc.h"
7 #include "collCreate.h"
8 #include "rodsConnect.h"
9 #include "rodsLog.h"
10 #include "regColl.h"
11 #include "icatDefines.h"
12 #include "fileMkdir.h"
13 #include "subStructFileMkdir.h"
14 #include "rsGlobalExtern.hpp"
15 #include "rcGlobalExtern.h"
16 #include "objMetaOpr.hpp"
17 #include "collection.hpp"
18 #include "specColl.hpp"
19 #include "physPath.hpp"
20 #include "dataObjOpr.hpp"
21 #include "miscServerFunct.hpp"
22 #include "rsCollCreate.hpp"
23 #include "rsRegColl.hpp"
24 #include "rsSubStructFileMkdir.hpp"
25 #include "rsFileMkdir.hpp"
26 
27 // =-=-=-=-=-=-=-
31 
32 #define IRODS_FILESYSTEM_ENABLE_SERVER_SIDE_API
34 
35 #include <algorithm>
36 #include <string_view>
37 
38 namespace fs = irods::experimental::filesystem;
39 
40 namespace
41 {
42  auto is_special_path(fs::path p) -> bool
43  {
44  static const auto special_paths = {".", ".."};
45 
46  return std::any_of(std::begin(special_paths),
47  std::end(special_paths),
48  [p = p.object_name()](const auto& sp) { return sp == p; });
49  }
50 } // anonymous namespace
51 
52 int rsCollCreate(rsComm_t* rsComm, collInp_t* collCreateInp)
53 {
54  if (is_special_path(collCreateInp->collName)) {
55  return USER_INPUT_PATH_ERR;
56  }
57 
59 
60  int status;
62  ruleExecInfo_t rei;
63  collInfo_t collInfo;
64  specCollCache_t *specCollCache = NULL;
65  dataObjInfo_t *dataObjInfo = NULL;
66 
67  irods::error ret = validate_logical_path( collCreateInp->collName );
68  if ( !ret.ok() ) {
69  if ( rsComm->rError.len < MAX_ERROR_MESSAGES ) {
70  char error_msg[ERR_MSG_LEN];
71  snprintf(error_msg, ERR_MSG_LEN, "%s", ret.user_result().c_str());
72  addRErrorMsg( &rsComm->rError, ret.code(), error_msg );
73  }
74  irods::log( ret );
76  }
77 
78  // Issue 3913: retain status in case string too long
79  status = resolveLinkedPath( rsComm, collCreateInp->collName, &specCollCache,
80  &collCreateInp->condInput );
81 
82  // Issue 3913: retain status in case string too long
83  if (status == USER_STRLEN_TOOLONG) {
84  return USER_STRLEN_TOOLONG;
85  }
87  rsComm,
89  ( const char* )collCreateInp->collName,
90  &rodsServerHost );
91 
92  if ( status < 0 || rodsServerHost == NULL ) { // JMC cppcheck
93  return status;
94  }
95 
97  initReiWithCollInp( &rei, rsComm, collCreateInp, &collInfo );
98 
99  status = applyRule( "acPreprocForCollCreate", NULL, &rei, NO_SAVE_REI );
100 
101  if ( status < 0 ) {
102  if ( rei.status < 0 ) {
103  status = rei.status;
104  }
106  "rsCollCreate:acPreprocForCollCreate error for %s,stat=%d",
107  collCreateInp->collName, status );
108  return status;
109  }
110 
111  if ( getValByKey( &collCreateInp->condInput, RECURSIVE_OPR__KW ) !=
112  NULL ) {
113  status = rsMkCollR( rsComm, "/", collCreateInp->collName );
114  return status;
115  }
116  std::string svc_role;
117  irods::error ret = get_catalog_service_role(svc_role);
118  if(!ret.ok()) {
119  irods::log(PASS(ret));
120  return ret.code();
121  }
122 
123  if( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
124  /* for STRUCT_FILE_COLL to make a directory in the structFile, the
125  * COLLECTION_TYPE_KW must be set */
126 
127  status = resolvePathInSpecColl( rsComm, collCreateInp->collName,
128  WRITE_COLL_PERM, 0, &dataObjInfo );
129  if ( status >= 0 ) {
130  freeDataObjInfo( dataObjInfo );
131  if ( status == COLL_OBJ_T ) {
132  return 0;
133  }
134  else if ( status == DATA_OBJ_T ) {
135  return USER_INPUT_PATH_ERR;
136  }
137  }
138  else if ( status == SYS_SPEC_COLL_OBJ_NOT_EXIST ) {
139  /* for STRUCT_FILE_COLL to make a directory in the structFile, the
140  * COLLECTION_TYPE_KW must be set */
141  if ( dataObjInfo != NULL && dataObjInfo->specColl != NULL &&
142  dataObjInfo->specColl->collClass == LINKED_COLL ) {
143  /* should not be here because if has been translated */
144  return SYS_COLL_LINK_PATH_ERR;
145  }
146  else {
147  status = l3Mkdir( rsComm, dataObjInfo );
148  }
149  freeDataObjInfo( dataObjInfo );
150  return status;
151  }
152  else {
153  if ( isColl( rsComm, collCreateInp->collName, NULL ) >= 0 ) {
155  }
156  status = _rsRegColl( rsComm, collCreateInp );
157  }
158  rei.status = status;
159  if ( status >= 0 ) {
160  rei.status = applyRule( "acPostProcForCollCreate", NULL, &rei,
161  NO_SAVE_REI );
162 
163  if ( rei.status < 0 ) {
165  "rsCollCreate:acPostProcForCollCreate error for %s,stat=%d",
166  collCreateInp->collName, status );
167  }
168  }
169  } else if( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
171  } else {
172  rodsLog(
173  LOG_ERROR,
174  "role not supported [%s]",
175  svc_role.c_str() );
177  }
178  }
179  else {
180  status = rcCollCreate( rodsServerHost->conn, collCreateInp );
181  }
182  return status;
183 }
184 
185 int
186 l3Mkdir( rsComm_t *rsComm, dataObjInfo_t *dataObjInfo ) {
187  if ( NULL == dataObjInfo ) {
188  return SYS_NULL_INPUT;
189  }
190 
191  //int rescTypeInx;
192  fileMkdirInp_t fileMkdirInp;
193  int status;
194 
195  // =-=-=-=-=-=-=-
196  // extract the host location from the resource hierarchy
197  std::string location;
198  irods::error ret = irods::get_loc_for_hier_string( dataObjInfo->rescHier, location );
199  if ( !ret.ok() ) {
200  irods::log( PASSMSG( "l3Mkdir - failed in get_loc_for_hier_string", ret ) );
201  return -1;
202  }
203 
204  if ( getStructFileType( dataObjInfo->specColl ) >= 0 ) {
205  subFile_t subFile;
206  memset( &subFile, 0, sizeof( subFile ) );
207  rstrcpy( subFile.subFilePath, dataObjInfo->subPath, MAX_NAME_LEN );
208  subFile.mode = getDefDirMode();
209  //rstrcpy (subFile.addr.hostAddr, dataObjInfo->rescInfo->rescLoc, NAME_LEN );
210  rstrcpy( subFile.addr.hostAddr, location.c_str(), NAME_LEN );
211  subFile.specColl = dataObjInfo->specColl;
212  status = rsSubStructFileMkdir( rsComm, &subFile );
213  }
214  else {
215  memset( &fileMkdirInp, 0, sizeof( fileMkdirInp ) );
216  rstrcpy( fileMkdirInp.dirName, dataObjInfo->filePath, MAX_NAME_LEN );
217  rstrcpy( fileMkdirInp.rescHier, dataObjInfo->rescHier, MAX_NAME_LEN );
218  rstrcpy( fileMkdirInp.addr.hostAddr, location.c_str(), NAME_LEN );
219  fileMkdirInp.mode = getDefDirMode();
220  status = rsFileMkdir( rsComm, &fileMkdirInp );
221  }
222  return status;
223 }
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
NULL
#define NULL
Definition: rodsDef.h:70
rsComm_t
Definition: rcConnect.h:145
getDefDirMode
int getDefDirMode()
Definition: physPath.cpp:1070
irods::CFG_SERVICE_ROLE_CONSUMER
const std::string CFG_SERVICE_ROLE_CONSUMER("consumer")
irods_configuration_keywords.hpp
rError_t::len
int len
Definition: rodsError.h:25
rsFileMkdir.hpp
rodsServerHost::localFlag
int localFlag
Definition: rodsConnect.h:68
SYS_SERVICE_ROLE_NOT_SUPPORTED
@ SYS_SERVICE_ROLE_NOT_SUPPORTED
Definition: rodsErrorTable.h:217
irods::error::user_result
std::string user_result() const
Definition: irods_error.cpp:229
specColl.hpp
CollInp
Definition: dataObjInpOut.h:157
rsCollCreate
int rsCollCreate(rsComm_t *rsComm, collInp_t *collCreateInp)
Definition: rsCollCreate.cpp:52
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
Subfile
Definition: objInfo.h:316
isColl
int isColl(rsComm_t *rsComm, char *objName, rodsLong_t *collId)
Definition: objMetaOpr.cpp:204
RuleExecInfo::status
int status
Definition: irods_re_structs.hpp:19
PASS
#define PASS(prev_error_)
Definition: irods_error.hpp:118
validate_logical_path
irods::error validate_logical_path(const std::string &)
Definition: dataObjOpr.cpp:47
Subfile::subFilePath
char subFilePath[(1024+64)]
Definition: objInfo.h:318
CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME
@ CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME
Definition: rodsErrorTable.h:424
NO_SAVE_REI
#define NO_SAVE_REI
Definition: rodsDef.h:103
SYS_SPEC_COLL_OBJ_NOT_EXIST
@ SYS_SPEC_COLL_OBJ_NOT_EXIST
Definition: rodsErrorTable.h:123
_rsRegColl
int _rsRegColl(rsComm_t *rsComm, collInp_t *regCollInp)
Definition: rsRegColl.cpp:75
rcMisc.h
pid_age.p
p
Definition: pid_age.py:13
freeDataObjInfo
int freeDataObjInfo(dataObjInfo_t *dataObjInfo)
Definition: rcMisc.cpp:544
rsRegColl.hpp
fileMkdirInp_t::mode
int mode
Definition: fileMkdir.h:11
getStructFileType
int getStructFileType(specColl_t *specColl)
Definition: objMetaOpr.cpp:386
DataObjInfo::rescHier
char rescHier[(1024+64)]
Definition: objInfo.h:132
LOCAL_HOST
#define LOCAL_HOST
Definition: rodsConnect.h:44
regColl.h
irods_resource_backport.hpp
Subfile::specColl
specColl_t * specColl
Definition: objInfo.h:322
WRITE_COLL_PERM
@ WRITE_COLL_PERM
Definition: objInfo.h:99
rcCollCreate
int rcCollCreate(rcComm_t *conn, collInp_t *collCreateInp)
Definition: rcCollCreate.cpp:58
PASSMSG
#define PASSMSG(message_, prev_error_)
Definition: irods_error.hpp:119
rcGlobalExtern.h
DataObjInfo::filePath
char filePath[(1024+64)]
Definition: objInfo.h:137
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
RECURSIVE_OPR__KW
#define RECURSIVE_OPR__KW
Definition: rodsKeyWdDef.h:66
SYS_INVALID_INPUT_PARAM
@ SYS_INVALID_INPUT_PARAM
Definition: rodsErrorTable.h:195
collCreate.h
rodsConnect.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
rsSubStructFileMkdir.hpp
irods::experimental::filesystem::client::end
auto end(const collection_iterator &) noexcept -> const collection_iterator
Definition: collection_iterator.hpp:88
COLL_OBJ_T
@ COLL_OBJ_T
Definition: rodsType.h:39
rsSubStructFileMkdir
int rsSubStructFileMkdir(rsComm_t *rsComm, subFile_t *subFile)
Definition: rsSubStructFileMkdir.cpp:12
rsGlobalExtern.hpp
irods::experimental::filesystem::client::begin
auto begin(collection_iterator _iter) noexcept -> collection_iterator
Definition: collection_iterator.hpp:83
MAX_ERROR_MESSAGES
#define MAX_ERROR_MESSAGES
Definition: rodsError.h:17
rsComm_t::rError
rError_t rError
Definition: rcConnect.h:158
irods::error::code
long long code() const
Definition: irods_error.cpp:194
LINKED_COLL
@ LINKED_COLL
Definition: objInfo.h:49
fileMkdir.h
irods::experimental::filesystem
Definition: collection_entry.hpp:12
remove_trailing_path_separators
void remove_trailing_path_separators(char *path)
Definition: rodsPath.cpp:536
fileMkdirInp_t::addr
rodsHostAddr_t addr
Definition: fileMkdir.h:8
fileMkdirInp_t::dirName
char dirName[(1024+64)]
Definition: fileMkdir.h:9
irods::CFG_SERVICE_ROLE_PROVIDER
const std::string CFG_SERVICE_ROLE_PROVIDER("provider")
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
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
addRErrorMsg
int addRErrorMsg(rError_t *myError, int status, const char *msg)
Definition: rcMisc.cpp:121
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
SYS_NULL_INPUT
@ SYS_NULL_INPUT
Definition: rodsErrorTable.h:876
collection.hpp
rodsLog.h
physPath.hpp
irods::log
void log(const error &)
Definition: irods_log.cpp:13
fileMkdirInp_t::rescHier
char rescHier[(1024+64)]
Definition: fileMkdir.h:10
l3Mkdir
int l3Mkdir(rsComm_t *rsComm, dataObjInfo_t *dataObjInfo)
Definition: rsCollCreate.cpp:186
icatDefines.h
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
miscServerFunct.hpp
DATA_OBJ_T
@ DATA_OBJ_T
Definition: rodsType.h:38
getAndConnRcatHost
int getAndConnRcatHost(rsComm_t *rsComm, int rcatType, const char *rcatZoneHint, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:26
irods_hierarchy_parser.hpp
SYS_COLL_LINK_PATH_ERR
@ SYS_COLL_LINK_PATH_ERR
Definition: rodsErrorTable.h:172
MASTER_RCAT
#define MASTER_RCAT
Definition: rodsDef.h:85
get_catalog_service_role
irods::error get_catalog_service_role(std::string &_role)
Definition: miscServerFunct.cpp:3153
rodsServerHost
Definition: rodsConnect.h:62
rodsHostAddr_t::hostAddr
char hostAddr[256]
Definition: rodsDef.h:297
USER_STRLEN_TOOLONG
@ USER_STRLEN_TOOLONG
Definition: rodsErrorTable.h:237
rsMkCollR
int rsMkCollR(rsComm_t *rsComm, const char *startColl, const char *destColl)
Definition: collection.cpp:428
RuleExecInfo
Definition: irods_re_structs.hpp:18
applyRule
int applyRule(char *inAction, msParamArray_t *inMsParamArray, ruleExecInfo_t *rei, int reiSaveFlag)
Definition: irods_re_structs.cpp:65
CollInp::collName
char collName[(1024+64)]
Definition: dataObjInpOut.h:158
Subfile::mode
int mode
Definition: objInfo.h:319
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
dataObjOpr.hpp
path.hpp
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
NAME_LEN
#define NAME_LEN
Definition: rodsDef.h:55
rsCollCreate.hpp
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
initReiWithCollInp
int initReiWithCollInp(ruleExecInfo_t *rei, rsComm_t *rsComm, collInp_t *collCreateInp, collInfo_t *collInfo)
Definition: irods_re_structs.cpp:182
rsFileMkdir
int rsFileMkdir(rsComm_t *rsComm, fileMkdirInp_t *fileMkdirInp)
Definition: rsFileMkdir.cpp:17
SpecCollCache
Definition: objInfo.h:102
fileMkdirInp_t
Definition: fileMkdir.h:7
objMetaOpr.hpp
SpecColl::collClass
specCollClass_t collClass
Definition: objInfo.h:77
ERR_MSG_LEN
#define ERR_MSG_LEN
Definition: rodsError.h:16
DataObjInfo::subPath
char subPath[(1024+64)]
Definition: objInfo.h:157
subStructFileMkdir.h