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)  

rsFileCreate.cpp
Go to the documentation of this file.
1 
3 /* rsFileCreate.c - server routine that handles the fileCreate
4  * API
5  */
6 
7 #include "fileCreate.h"
8 #include "fileOpr.hpp"
9 #include "miscServerFunct.hpp"
10 #include "dataObjOpr.hpp"
11 #include "physPath.hpp"
12 #include "rsGlobalExtern.hpp"
14 #include "rsFileCreate.hpp"
15 
16 // =-=-=-=-=-=-=-
17 #include "irods_log.hpp"
18 #include "irods_file_object.hpp"
21 #include "irods_stacktrace.hpp"
23 
24 
25 #include <string>
26 
27 int
28 rsFileCreate( rsComm_t *rsComm, fileCreateInp_t *fileCreateInp, fileCreateOut_t** _out ) {
30  int remoteFlag;
31  int fileInx;
32  int fd;
33 
34  //remoteFlag = resolveHost (&fileCreateInp->addr, &rodsServerHost);
35  irods::error ret = irods::get_host_for_hier_string( fileCreateInp->resc_hier_, remoteFlag, rodsServerHost );
36  if ( !ret.ok() ) {
37  irods::log( PASSMSG( "failed in call to irods::get_host_for_hier_string", ret ) );
38  return -1;
39  }
40 
41  if ( remoteFlag == LOCAL_HOST ) {
42  fd = _rsFileCreate( rsComm, fileCreateInp, rodsServerHost, _out );
43  }
44  else if ( remoteFlag == REMOTE_HOST ) {
45  fd = remoteFileCreate( rsComm, fileCreateInp, rodsServerHost, _out );
46  }
47  else {
48  if ( remoteFlag < 0 ) {
49  return remoteFlag;
50  }
51  else {
53  "rsFileCreate: resolveHost returned unrecognized value %d",
54  remoteFlag );
56  }
57  }
58 
59  if ( fd < 0 ) {
60  return fd;
61  }
62 
63  fileInx = allocAndFillFileDesc( rodsServerHost, fileCreateInp->objPath, fileCreateInp->fileName, fileCreateInp->resc_hier_,
64  fd, fileCreateInp->mode );
65 
66  return fileInx;
67 }
68 
69 int
70 remoteFileCreate( rsComm_t *rsComm, fileCreateInp_t *fileCreateInp,
72  int fileInx;
73  int status;
74 
75  if ( rodsServerHost == NULL ) {
77  "remoteFileCreate: Invalid rodsServerHost" );
79  }
80 
81  if ( ( status = svrToSvrConnect( rsComm, rodsServerHost ) ) < 0 ) {
82  return status;
83  }
84 
85  fileInx = rcFileCreate( rodsServerHost->conn, fileCreateInp, _out );
86 
87  if ( fileInx < 0 ) {
89  "remoteFileCreate: rcFileCreate failed for %s",
90  fileCreateInp->fileName );
91  }
92 
93  return fileInx;
94 }
95 
96 // =-=-=-=-=-=-=-
97 // _rsFileCreate - this the local version of rsFileCreate.
99  rsComm_t* _comm,
100  fileCreateInp_t* _create_inp,
101  rodsServerHost_t* _server_host,
102  fileCreateOut_t** _out ) {
103  // =-=-=-=-=-=-=-
104  // NOTE:: need to check resource permission and vault permission when RCAT
105  // is available
106 
107  // =-=-=-=-=-=-=-
108  // check path permissions before creating the file
109  if ( ( _create_inp->otherFlags & NO_CHK_PERM_FLAG ) == 0 ) { // JMC - backport 4758
110  int status = chkFilePathPerm(
111  _comm,
112  _create_inp,
113  _server_host,
114  DO_CHK_PATH_PERM ); // JMC - backport 4774
115  if ( status < 0 ) {
116  rodsLog( LOG_ERROR, "_rsFileCreate - chkFilePathPerm returned %d", status );
117  return status;
118  }
119  }
120 
121  // =-=-=-=-=-=-=-
122  // don't capture the irods results in the log here as there may be an issue with
123  // needing to create a directory, etc.
125  _comm,
126  _create_inp->objPath,
127  _create_inp->fileName,
128  _create_inp->resc_hier_,
129  0,
130  _create_inp->mode,
131  _create_inp->flags ) );
132  file_obj->in_pdmo( _create_inp->in_pdmo );
133 
134  // =-=-=-=-=-=-=-
135  // pass condInput
136  file_obj->cond_input( _create_inp->condInput );
137 
138  irods::error create_err = fileCreate( _comm, file_obj );
139 
140  // =-=-=-=-=-=-=-
141  // if we get a bad file descriptor
142  if ( !create_err.ok() ) {
143  // =-=-=-=-=-=-=-
144  // check error on fd, did the directory exist?
145  if ( getErrno( create_err.code() ) == ENOENT ) {
146 
147  // =-=-=-=-=-=-=-
148  // the directory didn't exist, make it and then try the create once again.
149  int status = mkDirForFilePath(
150  _comm,
151  0,
152  file_obj->physical_path().c_str(),
153  file_obj->resc_hier().c_str(),
154  getDefDirMode() );
155  if ( status != 0 ) {
156  std::stringstream msg;
157  msg << "Unable to make directory: \""
158  << file_obj->physical_path()
159  << "\"";
160  irods::log( LOG_ERROR, msg.str() );
161  return status;
162  }
163 
164  create_err = fileCreate( _comm, file_obj );
165 
166  // =-=-=-=-=-=-=-
167  // capture the irods results in the log as our error mechanism
168  // doesn't extend outside this function for now.
169  if ( !create_err.ok() ) {
170  std::stringstream msg;
171  msg << "ENOENT fileCreate for [";
172  msg << _create_inp->fileName;
173  msg << "]";
174  irods::error ret_err = PASSMSG( msg.str(), create_err );
175  irods::log( ret_err );
176 
177  }
178 
179  }
180  else if ( getErrno( create_err.code() ) == EEXIST ) {
181  // =-=-=-=-=-=-=-
182  // remove a potentially empty directory which is already in place
185  _create_inp->fileName,
186  _create_inp->resc_hier_,
187  0, 0 ) );
188  coll_obj->cond_input( _create_inp->condInput );
189 
190  irods::error rmdir_err = fileRmdir( _comm, coll_obj );
191  if ( !rmdir_err.ok() ) {
192  std::stringstream msg;
193  msg << "EEXIST 1 fileRmdir for [";
194  msg << _create_inp->fileName;
195  msg << "]";
196  irods::error err = PASSMSG( msg.str(), rmdir_err );
197  irods::log( err );
198  }
199 
200  create_err = fileCreate( _comm, file_obj );
201 
202  // =-=-=-=-=-=-=-
203  // capture the irods results in the log as our error mechanism
204  // doesn't extend outside this function for now.
205  if ( !create_err.ok() ) {
206  std::stringstream msg;
207  msg << "EEXIST 2 fileCreate for [";
208  msg << _create_inp->fileName;
209  msg << "]";
210  irods::error ret_err = PASSMSG( msg.str(), create_err );
211  irods::log( ret_err );
212  }
213 
214  }
215  else {
216  std::stringstream msg;
217  msg << "UNHANDLED fileCreate for [";
218  msg << _create_inp->fileName;
219  msg << "]";
220  irods::error ret_err = PASSMSG( msg.str(), create_err );
221  irods::log( ret_err );
222 
223  } // else
224 
225  } // if !create_err.ok()
226 
227  if ( !create_err.ok() ) {
228  return create_err.code();
229  }
230 
231  // =-=-=-=-=-=-=-
232  // percolate possible change in phy path up
233  ( *_out ) = ( fileCreateOut_t* ) malloc( sizeof( fileCreateOut_t ) );
234  rstrcpy(
235  ( *_out )->file_name,
236  file_obj->physical_path().c_str(),
237  MAX_NAME_LEN );
238 
239  rstrcpy(
240  _create_inp->resc_hier_,
241  file_obj->resc_hier().c_str(),
242  MAX_NAME_LEN );
243  rstrcpy(
244  _create_inp->fileName,
245  file_obj->physical_path().c_str(),
246  MAX_NAME_LEN );
247 
248  return file_obj->file_descriptor();
249 
250 } // _rsFileCreate
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
NULL
#define NULL
Definition: rodsDef.h:70
rsComm_t
Definition: rcConnect.h:145
getDefDirMode
int getDefDirMode()
Definition: physPath.cpp:1070
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
SYS_UNRECOGNIZED_REMOTE_FLAG
@ SYS_UNRECOGNIZED_REMOTE_FLAG
Definition: rodsErrorTable.h:88
irods_file_object.hpp
irods_stacktrace.hpp
irods_collection_object.hpp
REMOTE_HOST
#define REMOTE_HOST
Definition: rodsConnect.h:45
irods::collection_object_ptr
boost::shared_ptr< collection_object > collection_object_ptr
Definition: irods_collection_object.hpp:85
NO_CHK_PERM_FLAG
#define NO_CHK_PERM_FLAG
Definition: fileOpen.h:10
remoteFileCreate
int remoteFileCreate(rsComm_t *rsComm, fileCreateInp_t *fileCreateInp, rodsServerHost_t *rodsServerHost, fileCreateOut_t **_out)
Definition: rsFileCreate.cpp:70
LOCAL_HOST
#define LOCAL_HOST
Definition: rodsConnect.h:44
irods_resource_backport.hpp
fileOpenInp_t::resc_hier_
char resc_hier_[(1024+64)]
Definition: fileOpen.h:16
PASSMSG
#define PASSMSG(message_, prev_error_)
Definition: irods_error.hpp:119
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
fileOpenInp_t::fileName
char fileName[(1024+64)]
Definition: fileOpen.h:20
_rsFileCreate
int _rsFileCreate(rsComm_t *_comm, fileCreateInp_t *_create_inp, rodsServerHost_t *_server_host, fileCreateOut_t **_out)
Definition: rsFileCreate.cpp:98
DO_CHK_PATH_PERM
#define DO_CHK_PATH_PERM
Definition: objInfo.h:247
fileCreate.h
rsGlobalExtern.hpp
fileCreateOut_t
Definition: fileCreate.h:9
irods::error::code
long long code() const
Definition: irods_error.cpp:194
fileOpenInp_t::flags
int flags
Definition: fileOpen.h:21
rcFileCreate
int rcFileCreate(rcComm_t *conn, fileCreateInp_t *fileCreateInp, fileCreateOut_t **)
Definition: rcFileCreate.cpp:24
fileOpenInp_t::objPath
char objPath[(1024+64)]
Definition: fileOpen.h:17
irods::get_host_for_hier_string
error get_host_for_hier_string(const std::string &, int &, rodsServerHost_t *&)
Definition: irods_resource_backport.cpp:581
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
getErrno
int getErrno(int errCode)
Definition: rcMisc.cpp:3261
fileRmdir
irods::error fileRmdir(rsComm_t *, irods::first_class_object_ptr)
Definition: fileDriver.cpp:332
SYS_INVALID_SERVER_HOST
@ SYS_INVALID_SERVER_HOST
Definition: rodsErrorTable.h:89
fileOpenInp_t::mode
int mode
Definition: fileOpen.h:22
svrToSvrConnect
int svrToSvrConnect(rsComm_t *rsComm, rodsServerHost_t *rodsServerHost)
Definition: miscServerFunct.cpp:106
irods::collection_object
Definition: irods_collection_object.hpp:14
rsFileCreate
int rsFileCreate(rsComm_t *rsComm, fileCreateInp_t *fileCreateInp, fileCreateOut_t **_out)
Definition: rsFileCreate.cpp:28
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
allocAndFillFileDesc
int allocAndFillFileDesc(rodsServerHost_t *rodsServerHost, const std::string &objPath, const std::string &fileName, const std::string &rescHier, int fd, int mode)
Definition: fileOpr.cpp:48
physPath.hpp
irods::log
void log(const error &)
Definition: irods_log.cpp:13
fileCreate
irods::error fileCreate(rsComm_t *, irods::first_class_object_ptr)
Definition: fileDriver.cpp:17
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
rsFileCreate.hpp
irods::error
Definition: irods_error.hpp:23
miscServerFunct.hpp
fileOpenInp_t::condInput
keyValPair_t condInput
Definition: fileOpen.h:24
irods_hierarchy_parser.hpp
fileOpenInp_t
Definition: fileOpen.h:14
irods::file_object
Definition: irods_file_object.hpp:19
chkFilePathPerm
int chkFilePathPerm(rsComm_t *rsComm, fileOpenInp_t *fileOpenInp, rodsServerHost_t *rodsServerHost, int chkType)
Definition: fileOpr.cpp:381
fileOpr.hpp
rodsServerHost
Definition: rodsConnect.h:62
irods::file_object_ptr
boost::shared_ptr< file_object > file_object_ptr
Definition: irods_file_object.hpp:145
icatHighLevelRoutines.hpp
fileOpenInp_t::in_pdmo
char in_pdmo[(1024+64)]
Definition: fileOpen.h:25
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
dataObjOpr.hpp
fileOpenInp_t::otherFlags
int otherFlags
Definition: fileOpen.h:18
mkDirForFilePath
int mkDirForFilePath(rsComm_t *rsComm, size_t startDirLen, const std::string &filePath, const std::string &hier, int mode)
Definition: fileOpr.cpp:120
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
irods_log.hpp