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)  

rsFilePut.cpp
Go to the documentation of this file.
1 
3 /* This is script-generated code (for the most part). */
4 /* See filePut.h for a description of this API call.*/
5 
6 #include "filePut.h"
7 #include "miscServerFunct.hpp"
8 #include "fileCreate.h"
9 #include "dataObjOpr.hpp"
10 #include "rsFilePut.hpp"
11 #include "rsFileOpen.hpp"
12 #include "rsFileCreate.hpp"
13 
14 // =-=-=-=-=-=-=-
15 // stl includes
16 #include <iostream>
17 #include <sstream>
18 
19 // =-=-=-=-=-=-=-
20 #include "irods_log.hpp"
21 #include "irods_file_object.hpp"
22 #include "irods_stacktrace.hpp"
24 
25 
26 /* rsFilePut - Put the content of a small file from a single buffer
27  * in filePutInpBBuf->buf.
28  * Return value - int - number of bytes read.
29  */
30 
31 int
33  rsComm_t *rsComm,
34  fileOpenInp_t* filePutInp,
35  bytesBuf_t* filePutInpBBuf,
36  filePutOut_t** _put_out ) {
38  int remoteFlag;
39  int status;
40  //remoteFlag = resolveHost (&filePutInp->addr, &rodsServerHost);
42  if ( !ret.ok() ) {
43  std::cerr << irods::stacktrace().dump();
44  irods::log( PASSMSG( "failed in call to irods::get_host_for_hier_string", ret ) );
45  return -1;
46  }
47  if ( remoteFlag == LOCAL_HOST ) {
49  rsComm,
50  filePutInp,
51  filePutInpBBuf,
53  _put_out );
54  }
55  else if ( remoteFlag == REMOTE_HOST ) {
57  rsComm,
58  filePutInp,
59  filePutInpBBuf,
61  _put_out );
62  }
63  else {
64  if ( remoteFlag < 0 ) {
65  return remoteFlag;
66  }
67  else {
69  "rsFilePut: resolveHost returned unrecognized value %d",
70  remoteFlag );
72  }
73  }
74 
75  if ( status < 0 ) {
76  return status;
77  }
78 
79 
80  return status;
81 }
82 
83 int
85  rsComm_t *rsComm,
86  fileOpenInp_t *filePutInp,
87  bytesBuf_t *filePutInpBBuf,
89  filePutOut_t** _put_out ) {
90  int status;
91 
92  if ( rodsServerHost == NULL ) {
94  "remoteFilePut: Invalid rodsServerHost" );
96  }
97 
98  if ( ( status = svrToSvrConnect( rsComm, rodsServerHost ) ) < 0 ) {
99  rodsLog( LOG_ERROR, "remoteFilePut - svrToSvrConnect failed %d", status );
100  return status;
101  }
102 
103 
104  status = rcFilePut(
106  filePutInp,
107  filePutInpBBuf,
108  _put_out );
109 
110  if ( status < 0 && status != DIRECT_ARCHIVE_ACCESS ) {
112  "remoteFilePut: rcFilePut failed for %s",
113  filePutInp->fileName );
114  }
115 
116  return status;
117 }
118 
119 // =-=-=-=-=-=-=-
120 // local implementation of put
122  rsComm_t* _comm,
123  fileOpenInp_t* _put_inp,
124  bytesBuf_t* _put_bbuf,
125  rodsServerHost_t* _server_host,
126  filePutOut_t** _put_out ) {
127  int fd = 0;
128 
129  // =-=-=-=-=-=-=-
130  // NOTE:: this test does not seem to work for i86 solaris
131  if ( ( _put_inp->otherFlags & FORCE_FLAG ) != 0 ) {
132  // =-=-=-=-=-=-=-
133  // create one if it does not exist */
134  _put_inp->flags |= O_CREAT;
135  fd = _rsFileOpen( _comm, _put_inp );
136 
137  }
138  else {
139  fileCreateOut_t* _out = 0;
140  fd = _rsFileCreate( _comm, _put_inp, _server_host, &_out );
141  free( _out );
142 
143  } // else
144 
145  // =-=-=-=-=-=-=-
146  // log, error if any
147  if ( fd < 0 ) {
148  if ( getErrno( fd ) == EEXIST ) {
150  "_rsFilePut: filePut for %s, status = %d",
151  _put_inp->fileName, fd );
152  }
153  else if ( fd != DIRECT_ARCHIVE_ACCESS ) {
155  "_rsFilePut: filePut for %s, status = %d",
156  _put_inp->fileName, fd );
157  }
158  return fd;
159  }
160 
161  // =-=-=-=-=-=-=-
162  // call write for resource plugin
163  irods::file_object_ptr file_obj(
164  new irods::file_object(
165  _comm,
166  _put_inp->objPath,
167  _put_inp->fileName,
168  _put_inp->resc_hier_,
169  fd, 0, 0 ) );
170  file_obj->in_pdmo( _put_inp->in_pdmo );
171  file_obj->cond_input( _put_inp->condInput );
172 
173  irods::error write_err = fileWrite( _comm,
174  file_obj,
175  _put_bbuf->buf,
176  _put_bbuf->len );
177  int write_code = write_err.code();
178  // =-=-=-=-=-=-=-
179  // log errors, if any
180  if ( write_code != _put_bbuf->len ) {
181  if ( write_code >= 0 ) {
182  std::stringstream msg;
183  msg << "fileWrite failed for [";
184  msg << _put_inp->fileName;
185  msg << "] towrite [";
186  msg << _put_bbuf->len;
187  msg << "] written [";
188  msg << write_code << "]";
189  irods::error err = PASSMSG( msg.str(), write_err );
190  irods::log( err );
191  write_code = SYS_COPY_LEN_ERR;
192  }
193  else {
194  std::stringstream msg;
195  msg << "fileWrite failed for [";
196  msg << _put_inp->fileName;
197  msg << "]";
198  irods::error err = PASSMSG( msg.str(), write_err );
199  irods::log( err );
200  }
201  }
202 
203  // =-=-=-=-=-=-=-
204  // close up after ourselves
205  irods::error close_err = fileClose( _comm,
206  file_obj );
207  if ( !close_err.ok() ) {
208  irods::error err = PASSMSG( "error on close", close_err );
209  irods::log( err );
210  }
211 
212  // =-=-=-=-=-=-=-
213  // percolate possible change in phy path up
214  ( *_put_out ) = ( filePutOut_t* ) malloc( sizeof( filePutOut_t ) );
215  snprintf( ( *_put_out )->file_name, sizeof( ( *_put_out )->file_name ),
216  "%s", file_obj->physical_path().c_str() );
217 
218  // =-=-=-=-=-=-=-
219  // return 'write_err code' as this includes this implementation
220  // assumes we are returning the size of the file 'put' via fileWrite
221  return write_code;
222 
223 } // _rsFilePut
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
NULL
#define NULL
Definition: rodsDef.h:70
irods::stacktrace::dump
const std::string & dump() const
Definition: irods_stacktrace.cpp:55
rsComm_t
Definition: rcConnect.h:145
rsFileOpen.hpp
rsFilePut.hpp
BytesBuf::buf
void * buf
Definition: rodsDef.h:199
filePut.h
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
SYS_UNRECOGNIZED_REMOTE_FLAG
@ SYS_UNRECOGNIZED_REMOTE_FLAG
Definition: rodsErrorTable.h:88
_rsFilePut
int _rsFilePut(rsComm_t *_comm, fileOpenInp_t *_put_inp, bytesBuf_t *_put_bbuf, rodsServerHost_t *_server_host, filePutOut_t **_put_out)
Definition: rsFilePut.cpp:121
irods_file_object.hpp
irods_stacktrace.hpp
rcFilePut
int rcFilePut(rcComm_t *conn, fileOpenInp_t *filePutInp, bytesBuf_t *filePutInpBBuf, filePutOut_t **)
Definition: rcFilePut.cpp:33
REMOTE_HOST
#define REMOTE_HOST
Definition: rodsConnect.h:45
irods::stacktrace
Definition: irods_stacktrace.hpp:11
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 *rsComm, fileCreateInp_t *fileCreateInp, rodsServerHost_t *rodsServerHost, fileCreateOut_t **)
Definition: rsFileCreate.cpp:98
remoteFilePut
int remoteFilePut(rsComm_t *rsComm, fileOpenInp_t *filePutInp, bytesBuf_t *filePutInpBBuf, rodsServerHost_t *rodsServerHost, filePutOut_t **_put_out)
Definition: rsFilePut.cpp:84
BytesBuf::len
int len
Definition: rodsDef.h:198
fileCreate.h
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
SYS_COPY_LEN_ERR
@ SYS_COPY_LEN_ERR
Definition: rodsErrorTable.h:95
fileOpenInp_t::objPath
char objPath[(1024+64)]
Definition: fileOpen.h:17
LOG_DEBUG
#define LOG_DEBUG
Definition: rodsLog.h:23
irods::get_host_for_hier_string
error get_host_for_hier_string(const std::string &, int &, rodsServerHost_t *&)
Definition: irods_resource_backport.cpp:581
filePutOut_t
Definition: filePut.h:8
fileWrite
irods::error fileWrite(rsComm_t *, irods::first_class_object_ptr, void *, int)
Definition: fileDriver.cpp:113
_rsFileOpen
int _rsFileOpen(rsComm_t *rsComm, fileOpenInp_t *fileOpenInp)
Definition: rsFileOpen.cpp:114
getErrno
int getErrno(int errCode)
Definition: rcMisc.cpp:3261
SYS_INVALID_SERVER_HOST
@ SYS_INVALID_SERVER_HOST
Definition: rodsErrorTable.h:89
svrToSvrConnect
int svrToSvrConnect(rsComm_t *rsComm, rodsServerHost_t *rodsServerHost)
Definition: miscServerFunct.cpp:106
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
irods::log
void log(const error &)
Definition: irods_log.cpp:13
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
rsFileCreate.hpp
BytesBuf
Definition: rodsDef.h:197
irods::error
Definition: irods_error.hpp:23
miscServerFunct.hpp
fileClose
irods::error fileClose(rsComm_t *, irods::first_class_object_ptr)
Definition: fileDriver.cpp:147
fileOpenInp_t::condInput
keyValPair_t condInput
Definition: fileOpen.h:24
fileOpenInp_t
Definition: fileOpen.h:14
irods::file_object
Definition: irods_file_object.hpp:19
rodsServerHost
Definition: rodsConnect.h:62
rsFilePut
int rsFilePut(rsComm_t *rsComm, fileOpenInp_t *filePutInp, bytesBuf_t *filePutInpBBuf, filePutOut_t **_put_out)
Definition: rsFilePut.cpp:32
irods::file_object_ptr
boost::shared_ptr< file_object > file_object_ptr
Definition: irods_file_object.hpp:145
LOG_DEBUG10
#define LOG_DEBUG10
Definition: rodsLog.h:19
fileOpenInp_t::in_pdmo
char in_pdmo[(1024+64)]
Definition: fileOpen.h:25
dataObjOpr.hpp
FORCE_FLAG
#define FORCE_FLAG
Definition: fileOpen.h:12
fileOpenInp_t::otherFlags
int otherFlags
Definition: fileOpen.h:18
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
DIRECT_ARCHIVE_ACCESS
@ DIRECT_ARCHIVE_ACCESS
Definition: rodsErrorTable.h:763
irods_log.hpp