00001
00002
00003
00004
00005
00006 #include "fileGet.h"
00007 #include "miscServerFunct.h"
00008
00009
00010
00011
00012
00013
00014 int
00015 rsFileGet (rsComm_t *rsComm, fileOpenInp_t *fileGetInp,
00016 bytesBuf_t *fileGetOutBBuf)
00017 {
00018 rodsServerHost_t *rodsServerHost;
00019 int remoteFlag;
00020 int status;
00021
00022 remoteFlag = resolveHost (&fileGetInp->addr, &rodsServerHost);
00023 if (remoteFlag == LOCAL_HOST) {
00024 status = _rsFileGet (rsComm, fileGetInp, fileGetOutBBuf);
00025 } else if (remoteFlag == REMOTE_HOST) {
00026 status = remoteFileGet (rsComm, fileGetInp, fileGetOutBBuf,
00027 rodsServerHost);
00028 } else {
00029 if (remoteFlag < 0) {
00030 return (remoteFlag);
00031 } else {
00032 rodsLog (LOG_NOTICE,
00033 "rsFileGet: resolveHost returned unrecognized value %d",
00034 remoteFlag);
00035 return (SYS_UNRECOGNIZED_REMOTE_FLAG);
00036 }
00037 }
00038
00039 return (status);
00040 }
00041
00042 int
00043 remoteFileGet (rsComm_t *rsComm, fileOpenInp_t *fileGetInp,
00044 bytesBuf_t *fileGetOutBBuf, rodsServerHost_t *rodsServerHost)
00045 {
00046 int status;
00047
00048 if (rodsServerHost == NULL) {
00049 rodsLog (LOG_NOTICE,
00050 "remoteFileGet: Invalid rodsServerHost");
00051 return SYS_INVALID_SERVER_HOST;
00052 }
00053
00054 if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
00055 return status;
00056 }
00057
00058
00059
00060 status = rcFileGet (rodsServerHost->conn, fileGetInp, fileGetOutBBuf);
00061
00062 if (status < 0) {
00063 rodsLog (LOG_NOTICE,
00064 "remoteFileGet: rcFileGet failed for %s",
00065 fileGetInp->fileName);
00066 }
00067
00068 return status;
00069 }
00070
00071 int
00072 _rsFileGet (rsComm_t *rsComm, fileOpenInp_t *fileGetInp,
00073 bytesBuf_t *fileGetOutBBuf)
00074 {
00075 int status;
00076 int fd;
00077 int len;
00078
00079 len = fileGetInp->dataSize;
00080 if (len <= 0)
00081 return (0);
00082
00083 fd = _rsFileOpen (rsComm, fileGetInp);
00084
00085 if (fd < 0) {
00086 rodsLog (LOG_NOTICE,
00087 "_rsFileGet: fileGet for %s, status = %d",
00088 fileGetInp->fileName, fd);
00089 return (fd);
00090 }
00091
00092 if (fileGetOutBBuf->buf == NULL) {
00093 fileGetOutBBuf->buf = malloc (len);
00094 }
00095 status = fileRead (fileGetInp->fileType, rsComm,
00096 fd, fileGetOutBBuf->buf, len);
00097
00098 if (status != len) {
00099 if (status >= 0) {
00100 #if 0
00101 rodsLog (LOG_NOTICE,
00102 "_rsFileGet: fileRead for %s, toread %d, read %d",
00103 fileGetInp->fileName, len, status);
00104 status = SYS_COPY_LEN_ERR;
00105 #else
00106 fileGetOutBBuf->len = status;
00107 #endif
00108 } else {
00109 rodsLog (LOG_NOTICE,
00110 "_rsFileGet: fileRead for %s, status = %d",
00111 fileGetInp->fileName, status);
00112 }
00113 } else {
00114 fileGetOutBBuf->len = status;
00115 }
00116
00117 fileClose (fileGetInp->fileType, rsComm, fd);
00118
00119 return (status);
00120 }
00121