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 struct_obj( *_sub_file );
00079 struct_obj.comm( _comm );
00080
00081 struct_obj.resc_hier( eirods::EIRODS_LOCAL_USE_ONLY_RESOURCE );
00082
00083
00084
00085 if (_sub_file->flags & FORCE_FLAG) {
00086 eirods::error err = fileOpen( _comm, struct_obj );
00087 if( !err.ok() ) {
00088 std::stringstream msg;
00089 msg << "_rsSubStructFilePut - failed on call to fileCreate for [";
00090 msg << struct_obj.sub_file_path();
00091 eirods::log( ERROR( -1, msg.str() ) );
00092 fd = -1;
00093
00094 } else {
00095 fd = err.code();
00096 }
00097
00098 } else {
00099 eirods::error err = fileCreate( _comm, struct_obj );
00100 if( !err.ok() ) {
00101 std::stringstream msg;
00102 msg << "_rsSubStructFilePut - failed on call to fileCreate for [";
00103 msg << struct_obj.sub_file_path();
00104 eirods::log( ERROR( -1, msg.str() ) );
00105 fd = -1;
00106
00107 } else {
00108 fd = err.code();
00109 }
00110
00111 }
00112
00113
00114
00115 if (fd < 0) {
00116 if (getErrno (fd) == EEXIST) {
00117 rodsLog (LOG_DEBUG1,
00118 "_rsSubStructFilePut: filePut for %s, status = %d",
00119 _sub_file->subFilePath, fd);
00120 } else {
00121 rodsLog (LOG_NOTICE,
00122 "_rsSubStructFilePut: subStructFileOpen error for %s, stat=%d",
00123 _sub_file->subFilePath, fd);
00124 }
00125 return (fd);
00126 }
00127
00128
00129
00130
00131
00132 eirods::error write_err = fileWrite( _comm, struct_obj, _out_buf->buf, _out_buf->len );
00133 if( !write_err.ok() ) {
00134 std::stringstream msg;
00135 msg << "_rsSubStructFilePut - failed on call to fileWrite for [";
00136 msg << struct_obj.sub_file_path();
00137 eirods::log( ERROR( -1, msg.str() ) );
00138 status = write_err.code();
00139
00140 } else {
00141 status = write_err.code();
00142
00143 }
00144
00145
00146
00147 if (status != _out_buf->len) {
00148 if (status >= 0) {
00149 rodsLog (LOG_NOTICE,
00150 "_rsSubStructFilePut:Write error for %s,towrite %d,read %d",
00151 _sub_file->subFilePath, _out_buf->len, status);
00152 status = SYS_COPY_LEN_ERR;
00153 } else {
00154 rodsLog (LOG_NOTICE,
00155 "_rsSubStructFilePut: Write error for %s, status = %d",
00156 _sub_file->subFilePath, status);
00157 }
00158 }
00159
00160
00161
00162 eirods::error close_err = fileClose( _comm, struct_obj );
00163 if( !close_err.ok() ) {
00164 std::stringstream msg;
00165 msg << "_rsSubStructFilePut - failed on call to fileWrite for [";
00166 msg << struct_obj.sub_file_path();
00167 eirods::log( ERROR( -1, msg.str() ) );
00168 status = close_err.code();
00169
00170 }
00171
00172 return (status);
00173
00174 }
00175
00176