00001
00002
00003
00004
00005
00006
00007
00008 #include "fileGet.h"
00009 #include "miscServerFunct.h"
00010
00011
00012
00013 #include "eirods_log.h"
00014 #include "eirods_file_object.h"
00015 #include "eirods_resource_backport.h"
00016
00017
00018
00019
00020
00021
00022
00023 int
00024 rsFileGet (rsComm_t *rsComm, fileOpenInp_t *fileGetInp,
00025 bytesBuf_t *fileGetOutBBuf)
00026 {
00027 rodsServerHost_t *rodsServerHost;
00028 int remoteFlag;
00029 int status;
00030
00031
00032 eirods::error ret = eirods::get_host_for_hier_string( fileGetInp->resc_hier_, remoteFlag, rodsServerHost );
00033 if( !ret.ok() ) {
00034 eirods::log( PASSMSG( "failed in call to eirods::get_host_for_hier_string", ret ) );
00035 return -1;
00036 }
00037 if (remoteFlag == LOCAL_HOST) {
00038 status = _rsFileGet (rsComm, fileGetInp, fileGetOutBBuf);
00039 } else if (remoteFlag == REMOTE_HOST) {
00040 status = remoteFileGet (rsComm, fileGetInp, fileGetOutBBuf,
00041 rodsServerHost);
00042 } else {
00043 if (remoteFlag < 0) {
00044 return (remoteFlag);
00045 } else {
00046 rodsLog (LOG_NOTICE,
00047 "rsFileGet: resolveHost returned unrecognized value %d",
00048 remoteFlag);
00049 return (SYS_UNRECOGNIZED_REMOTE_FLAG);
00050 }
00051 }
00052
00053 return (status);
00054 }
00055
00056 int
00057 remoteFileGet (rsComm_t *rsComm, fileOpenInp_t *fileGetInp,
00058 bytesBuf_t *fileGetOutBBuf, rodsServerHost_t *rodsServerHost)
00059 {
00060 int status;
00061
00062 if (rodsServerHost == NULL) {
00063 rodsLog (LOG_NOTICE,
00064 "remoteFileGet: Invalid rodsServerHost");
00065 return SYS_INVALID_SERVER_HOST;
00066 }
00067
00068 if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
00069 return status;
00070 }
00071
00072
00073
00074 status = rcFileGet (rodsServerHost->conn, fileGetInp, fileGetOutBBuf);
00075
00076 if (status < 0) {
00077 rodsLog (LOG_NOTICE,
00078 "remoteFileGet: rcFileGet failed for %s",
00079 fileGetInp->fileName);
00080 }
00081
00082 return status;
00083 }
00084
00085 int _rsFileGet(
00086 rsComm_t* _comm,
00087 fileOpenInp_t* _get_inp,
00088 bytesBuf_t* _get_buf ) {
00089
00090 int fd;
00091 int len;
00092
00093 len = _get_inp->dataSize;
00094 if (len <= 0)
00095 return (0);
00096 fd = _rsFileOpen (_comm, _get_inp);
00097
00098 if (fd < 0) {
00099 rodsLog (LOG_NOTICE,
00100 "_rsFileGet: fileGet for %s, status = %d",
00101 _get_inp->fileName, fd);
00102 return (fd);
00103 }
00104
00105 if (_get_buf->buf == NULL) {
00106 _get_buf->buf = malloc (len);
00107 }
00108
00109 if(_get_inp->objPath[0] == '\0') {
00110 std::stringstream msg;
00111 msg << __FUNCTION__;
00112 msg << " - Empty logical path.";
00113 eirods::log(LOG_ERROR, msg.str());
00114 return -1;
00115 }
00116
00117 eirods::file_object_ptr file_obj(
00118 new eirods::file_object(
00119 _comm,
00120 _get_inp->objPath,
00121 _get_inp->fileName,
00122 _get_inp->resc_hier_,
00123 fd,
00124 _get_inp->mode,
00125 _get_inp->flags ) );
00126 eirods::error read_err = fileRead( _comm,
00127 file_obj,
00128 _get_buf->buf,
00129 len );
00130 int bytes_read = read_err.code();
00131 if ( bytes_read != len ) {
00132 if ( bytes_read >= 0) {
00133
00134 _get_buf->len = bytes_read;
00135
00136 } else {
00137 std::stringstream msg;
00138 msg << "fileRead failed for [";
00139 msg << _get_inp->fileName;
00140 msg << "]";
00141 eirods::error ret_err = PASSMSG( msg.str(), read_err );
00142 eirods::log( ret_err );
00143 }
00144 } else {
00145 _get_buf->len = bytes_read;
00146 }
00147
00148
00149
00150 eirods::error close_err = fileClose( _comm,
00151 file_obj );
00152 if( !close_err.ok() ) {
00153 eirods::error err = PASSMSG( "error on close", close_err );
00154 eirods::log( err );
00155 }
00156
00157 return (bytes_read);
00158
00159 }
00160
00161
00162
00163
00164
00165
00166