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