00001
00002
00003 #include "subStructFilePut.h"
00004 #include "miscServerFunct.h"
00005 #include "dataObjOpr.h"
00006
00007
00008
00009 #include "eirods_structured_object.h"
00010 #include "eirods_stacktrace.h"
00011 #include "eirods_log.h"
00012
00013 int
00014 rsSubStructFilePut (rsComm_t *rsComm, subFile_t *subFile,
00015 bytesBuf_t *subFilePutOutBBuf)
00016 {
00017 rodsServerHost_t *rodsServerHost;
00018 int remoteFlag;
00019 int status;
00020 remoteFlag = resolveHost (&subFile->addr, &rodsServerHost);
00021
00022 if (remoteFlag == LOCAL_HOST) {
00023 status = _rsSubStructFilePut (rsComm, subFile, subFilePutOutBBuf);
00024 } else if (remoteFlag == REMOTE_HOST) {
00025 status = remoteSubStructFilePut (rsComm, subFile, subFilePutOutBBuf,
00026 rodsServerHost);
00027 } else {
00028 if (remoteFlag < 0) {
00029 return (remoteFlag);
00030 } else {
00031 rodsLog (LOG_NOTICE,
00032 "rsSubStructFilePut: resolveHost returned unrecognized value %d",
00033 remoteFlag);
00034 return (SYS_UNRECOGNIZED_REMOTE_FLAG);
00035 }
00036 }
00037
00038 return (status);
00039 }
00040
00041 int
00042 remoteSubStructFilePut (rsComm_t *rsComm, subFile_t *subFile,
00043 bytesBuf_t *subFilePutOutBBuf, rodsServerHost_t *rodsServerHost)
00044 {
00045 int status;
00046
00047 if (rodsServerHost == NULL) {
00048 rodsLog (LOG_NOTICE,
00049 "remoteSubStructFilePut: Invalid rodsServerHost");
00050 return SYS_INVALID_SERVER_HOST;
00051 }
00052
00053 if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
00054 return status;
00055 }
00056
00057 status = rcSubStructFilePut (rodsServerHost->conn, subFile,
00058 subFilePutOutBBuf);
00059
00060 if (status < 0) {
00061 rodsLog (LOG_NOTICE,
00062 "remoteSubStructFilePut: rcSubStructFilePut failed for %s, status = %d",
00063 subFile->subFilePath, status);
00064 }
00065
00066 return status;
00067 }
00068
00069 int
00070 _rsSubStructFilePut( rsComm_t* _comm,
00071 subFile_t* _sub_file,
00072 bytesBuf_t* _out_buf ) {
00073 int status = -1;
00074 int fd = -1;
00075
00076
00077
00078 eirods::structured_object_ptr struct_obj(
00079 new eirods::structured_object(
00080 *_sub_file ) );
00081 struct_obj->comm( _comm );
00082 struct_obj->resc_hier( eirods::EIRODS_LOCAL_USE_ONLY_RESOURCE );
00083
00084
00085
00086 if (_sub_file->flags & FORCE_FLAG) {
00087 eirods::error err = fileOpen( _comm, struct_obj );
00088 if( !err.ok() ) {
00089 std::stringstream msg;
00090 msg << "failed on call to fileCreate for [";
00091 msg << struct_obj->sub_file_path();
00092 eirods::log( PASSMSG( msg.str(), err ) );
00093 fd = -1;
00094
00095 } else {
00096 fd = err.code();
00097 }
00098
00099 } else {
00100 eirods::error err = fileCreate( _comm, struct_obj );
00101 if( !err.ok() ) {
00102 std::stringstream msg;
00103 msg << "failed on call to fileCreate for [";
00104 msg << struct_obj->sub_file_path();
00105 eirods::log( PASSMSG( msg.str(), err ) );
00106 fd = -1;
00107
00108 } else {
00109 fd = err.code();
00110 }
00111
00112 }
00113
00114
00115
00116 if (fd < 0) {
00117 if (getErrno (fd) == EEXIST) {
00118 rodsLog (LOG_DEBUG1,
00119 "_rsSubStructFilePut: filePut for %s, status = %d",
00120 _sub_file->subFilePath, fd);
00121 } else {
00122 rodsLog (LOG_NOTICE,
00123 "_rsSubStructFilePut: subStructFileOpen error for %s, stat=%d",
00124 _sub_file->subFilePath, fd);
00125 }
00126 return (fd);
00127 }
00128
00129
00130
00131
00132
00133 eirods::error write_err = fileWrite( _comm, struct_obj, _out_buf->buf, _out_buf->len );
00134 if( !write_err.ok() ) {
00135 std::stringstream msg;
00136 msg << "failed on call to fileWrite for [";
00137 msg << struct_obj->sub_file_path();
00138 eirods::log( PASSMSG( msg.str(), write_err ) );
00139 status = write_err.code();
00140
00141 } else {
00142 status = write_err.code();
00143
00144 }
00145
00146
00147
00148 if (status != _out_buf->len) {
00149 if (status >= 0) {
00150 rodsLog (LOG_NOTICE,
00151 "_rsSubStructFilePut:Write error for %s,towrite %d,read %d",
00152 _sub_file->subFilePath, _out_buf->len, status);
00153 status = SYS_COPY_LEN_ERR;
00154 } else {
00155 rodsLog (LOG_NOTICE,
00156 "_rsSubStructFilePut: Write error for %s, status = %d",
00157 _sub_file->subFilePath, status);
00158 }
00159 }
00160
00161
00162
00163 eirods::error close_err = fileClose( _comm, struct_obj );
00164 if( !close_err.ok() ) {
00165 std::stringstream msg;
00166 msg << "failed on call to fileWrite for [";
00167 msg << struct_obj->sub_file_path();
00168 eirods::log( PASSMSG( msg.str(), close_err ) );
00169 status = close_err.code();
00170
00171 }
00172
00173 return (status);
00174
00175 }
00176
00177