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