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 rodsLog( LOG_ERROR, "remoteFilePut - svrToSvrConnect failed %d", status );
00083 return status;
00084 }
00085
00086
00087 status = rcFilePut (rodsServerHost->conn, filePutInp, filePutInpBBuf);
00088
00089 if (status < 0 && status != EIRODS_DIRECT_ARCHIVE_ACCESS ) {
00090 rodsLog (LOG_NOTICE,
00091 "remoteFilePut: rcFilePut failed for %s",
00092 filePutInp->fileName);
00093 }
00094
00095 return status;
00096 }
00097
00098
00099
00100 int _rsFilePut(
00101 rsComm_t* _comm,
00102 fileOpenInp_t* _put_inp,
00103 bytesBuf_t* _put_bbuf,
00104 rodsServerHost_t* _server_host ) {
00105 int fd = 0;
00106
00107
00108
00109 if( ( _put_inp->otherFlags & FORCE_FLAG ) != 0 ) {
00110
00111
00112 _put_inp->flags |= O_CREAT;
00113 fd = _rsFileOpen( _comm, _put_inp );
00114
00115 } else {
00116 fd = _rsFileCreate( _comm, _put_inp, _server_host );
00117
00118 }
00119
00120
00121
00122 if( fd < 0 ) {
00123 if (getErrno (fd) == EEXIST) {
00124 rodsLog (LOG_DEBUG1,
00125 "_rsFilePut: filePut for %s, status = %d",
00126 _put_inp->fileName, fd);
00127 } else if( fd != EIRODS_DIRECT_ARCHIVE_ACCESS ) {
00128 rodsLog (LOG_NOTICE,
00129 "_rsFilePut: filePut for %s, status = %d",
00130 _put_inp->fileName, fd);
00131 }
00132 return (fd);
00133 }
00134
00135 if(_put_inp->objPath[0] == '\0') {
00136 std::stringstream msg;
00137 msg << __FUNCTION__;
00138 msg << " - Empty logical path.";
00139 eirods::log(LOG_ERROR, msg.str());
00140 return -1;
00141 }
00142
00143
00144
00145 eirods::file_object_ptr file_obj(
00146 new eirods::file_object(
00147 _comm,
00148 _put_inp->objPath,
00149 _put_inp->fileName,
00150 _put_inp->resc_hier_,
00151 fd, 0, 0 ) );
00152 file_obj->in_pdmo(_put_inp->in_pdmo);
00153
00154 eirods::error write_err = fileWrite( _comm,
00155 file_obj,
00156 _put_bbuf->buf,
00157 _put_bbuf->len );
00158 int write_code = write_err.code();
00159
00160
00161 if ( write_code != _put_bbuf->len ) {
00162 if( write_code >= 0 ) {
00163 std::stringstream msg;
00164 msg << "fileWrite failed for [";
00165 msg << _put_inp->fileName;
00166 msg << "] towrite [";
00167 msg << _put_bbuf->len;
00168 msg << "] written [";
00169 msg << write_code << "]";
00170 eirods::error err = PASSMSG( msg.str(), write_err );
00171 eirods::log ( err );
00172 write_code = SYS_COPY_LEN_ERR;
00173 } else {
00174 std::stringstream msg;
00175 msg << "fileWrite failed for [";
00176 msg << _put_inp->fileName;
00177 msg << "]";
00178 eirods::error err = PASSMSG( msg.str(), write_err );
00179 eirods::log ( err );
00180 }
00181 }
00182
00183
00184
00185 eirods::error close_err = fileClose( _comm,
00186 file_obj );
00187 if( !close_err.ok() ) {
00188 eirods::error err = PASSMSG( "error on close", close_err );
00189 eirods::log( err );
00190 }
00191
00192
00193
00194
00195 return write_code;
00196
00197 }
00198
00199
00200
00201