00001
00002
00003
00004
00005
00006
00007
00008 #include "filePut.h"
00009 #include "miscServerFunct.h"
00010 #include "fileCreate.h"
00011 #include "dataObjOpr.h"
00012
00013
00014
00015 #include <iostream>
00016 #include <sstream>
00017
00018
00019
00020 #include "eirods_log.h"
00021 #include "eirods_file_object.h"
00022 #include "eirods_stacktrace.h"
00023 #include "eirods_resource_backport.h"
00024
00025
00026
00027
00028
00029
00030
00031 int
00032 rsFilePut (rsComm_t *rsComm, fileOpenInp_t *filePutInp,
00033 bytesBuf_t *filePutInpBBuf)
00034 {
00035 rodsServerHost_t *rodsServerHost;
00036 int remoteFlag;
00037 int status;
00038
00039 eirods::error ret = eirods::get_host_for_hier_string( filePutInp->resc_hier_, remoteFlag, rodsServerHost );
00040 if( !ret.ok() ) {
00041 eirods::log( PASSMSG( "failed in call to eirods::get_host_for_hier_string", ret ) );
00042 return -1;
00043 }
00044 if (remoteFlag == LOCAL_HOST) {
00045 status = _rsFilePut (rsComm, filePutInp, filePutInpBBuf,
00046 rodsServerHost);
00047 } else if (remoteFlag == REMOTE_HOST) {
00048 status = remoteFilePut (rsComm, filePutInp, filePutInpBBuf,
00049 rodsServerHost);
00050 } else {
00051 if (remoteFlag < 0) {
00052 return (remoteFlag);
00053 } else {
00054 rodsLog (LOG_NOTICE,
00055 "rsFilePut: resolveHost returned unrecognized value %d",
00056 remoteFlag);
00057 return (SYS_UNRECOGNIZED_REMOTE_FLAG);
00058 }
00059 }
00060
00061 if (status < 0) {
00062 return (status);
00063 }
00064
00065
00066 return (status);
00067 }
00068
00069 int
00070 remoteFilePut (rsComm_t *rsComm, fileOpenInp_t *filePutInp,
00071 bytesBuf_t *filePutInpBBuf, rodsServerHost_t *rodsServerHost)
00072 {
00073 int status;
00074
00075 if (rodsServerHost == NULL) {
00076 rodsLog (LOG_NOTICE,
00077 "remoteFilePut: Invalid rodsServerHost");
00078 return SYS_INVALID_SERVER_HOST;
00079 }
00080
00081 if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
00082 return status;
00083 }
00084
00085
00086 status = rcFilePut (rodsServerHost->conn, filePutInp, filePutInpBBuf);
00087
00088 if (status < 0) {
00089 rodsLog (LOG_NOTICE,
00090 "remoteFilePut: rcFilePut failed for %s",
00091 filePutInp->fileName);
00092 }
00093
00094 return status;
00095 }
00096
00097
00098
00099 int _rsFilePut(
00100 rsComm_t* _comm,
00101 fileOpenInp_t* _put_inp,
00102 bytesBuf_t* _put_bbuf,
00103 rodsServerHost_t* _server_host ) {
00104 int fd = 0;
00105
00106
00107
00108 if( ( _put_inp->otherFlags & FORCE_FLAG ) != 0 ) {
00109
00110
00111 _put_inp->flags |= O_CREAT;
00112 fd = _rsFileOpen( _comm, _put_inp );
00113
00114 } else {
00115 fd = _rsFileCreate( _comm, _put_inp, _server_host );
00116
00117 }
00118
00119
00120
00121 if( fd < 0 ) {
00122 if (getErrno (fd) == EEXIST) {
00123 rodsLog (LOG_DEBUG1,
00124 "_rsFilePut: filePut for %s, status = %d",
00125 _put_inp->fileName, fd);
00126 } else if( fd != EIRODS_DIRECT_ARCHIVE_ACCESS ) {
00127 rodsLog (LOG_NOTICE,
00128 "_rsFilePut: filePut for %s, status = %d",
00129 _put_inp->fileName, fd);
00130 }
00131 return (fd);
00132 }
00133
00134 if(_put_inp->objPath[0] == '\0') {
00135 std::stringstream msg;
00136 msg << __FUNCTION__;
00137 msg << " - Empty logical path.";
00138 eirods::log(LOG_ERROR, msg.str());
00139 return -1;
00140 }
00141
00142
00143
00144 eirods::file_object_ptr file_obj(
00145 new eirods::file_object(
00146 _comm,
00147 _put_inp->objPath,
00148 _put_inp->fileName,
00149 _put_inp->resc_hier_,
00150 fd, 0, 0 ) );
00151 file_obj->in_pdmo(_put_inp->in_pdmo);
00152
00153 eirods::error write_err = fileWrite( _comm,
00154 file_obj,
00155 _put_bbuf->buf,
00156 _put_bbuf->len );
00157 int write_code = write_err.code();
00158
00159
00160 if ( write_code != _put_bbuf->len ) {
00161 if( write_code >= 0 ) {
00162 std::stringstream msg;
00163 msg << "fileWrite failed for [";
00164 msg << _put_inp->fileName;
00165 msg << "] towrite [";
00166 msg << _put_bbuf->len;
00167 msg << "]";
00168 eirods::error err = PASSMSG( msg.str(), write_err );
00169 eirods::log ( err );
00170 write_code = SYS_COPY_LEN_ERR;
00171 } else {
00172 std::stringstream msg;
00173 msg << "fileWrite failed for [";
00174 msg << _put_inp->fileName;
00175 msg << "]";
00176 eirods::error err = PASSMSG( msg.str(), write_err );
00177 eirods::log ( err );
00178 }
00179 }
00180
00181
00182
00183 eirods::error close_err = fileClose( _comm,
00184 file_obj );
00185 if( !close_err.ok() ) {
00186 eirods::error err = PASSMSG( "error on close", close_err );
00187 eirods::log( err );
00188 }
00189
00190
00191
00192
00193 return write_code;
00194
00195 }
00196
00197
00198
00199