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( "rsFilePut - 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 eirods::error write_err = fileWrite( rsComm,
00143 file_obj,
00144 filePutInpBBuf->buf,
00145 filePutInpBBuf->len );
00146 int write_code = write_err.code();
00147
00148
00149
00150 if ( write_code != filePutInpBBuf->len ) {
00151 if( write_code >= 0 ) {
00152 std::stringstream msg;
00153 msg << "_rsFilePut: fileWrite for ";
00154 msg << filePutInp->fileName;
00155 msg << ", towrite ";
00156 msg << filePutInpBBuf->len;
00157 msg << ", status = ";
00158 msg << write_code;
00159 eirods::error err = PASS( false, write_code, msg.str(), write_err );
00160 eirods::log ( err );
00161 write_code = SYS_COPY_LEN_ERR;
00162 } else {
00163 std::stringstream msg;
00164 msg << "_rsFilePut: fileWrite for ";
00165 msg << filePutInp->fileName;
00166 msg << ", status = ";
00167 msg << write_code;
00168 eirods::error err = PASS( false, write_code, msg.str(), write_err );
00169 eirods::log ( err );
00170 }
00171 }
00172
00173
00174
00175 eirods::error close_err = fileClose( rsComm,
00176 file_obj );
00177 if( !close_err.ok() ) {
00178 eirods::error err = PASS( false, close_err.code(), "_rsFilePut - error on close", close_err );
00179 eirods::log( err );
00180 }
00181
00182
00183
00184
00185 return write_code;
00186
00187 }
00188
00189
00190
00191