00001
00002
00003 #include "structFileDriver.h"
00004 #include "subStructFilePut.h"
00005 #include "miscServerFunct.h"
00006 #include "dataObjOpr.h"
00007
00008 int
00009 rsSubStructFilePut (rsComm_t *rsComm, subFile_t *subFile,
00010 bytesBuf_t *subFilePutOutBBuf)
00011 {
00012 rodsServerHost_t *rodsServerHost;
00013 int remoteFlag;
00014 int status;
00015
00016 remoteFlag = resolveHost (&subFile->addr, &rodsServerHost);
00017
00018 if (remoteFlag == LOCAL_HOST) {
00019 status = _rsSubStructFilePut (rsComm, subFile, subFilePutOutBBuf);
00020 } else if (remoteFlag == REMOTE_HOST) {
00021 status = remoteSubStructFilePut (rsComm, subFile, subFilePutOutBBuf,
00022 rodsServerHost);
00023 } else {
00024 if (remoteFlag < 0) {
00025 return (remoteFlag);
00026 } else {
00027 rodsLog (LOG_NOTICE,
00028 "rsSubStructFilePut: resolveHost returned unrecognized value %d",
00029 remoteFlag);
00030 return (SYS_UNRECOGNIZED_REMOTE_FLAG);
00031 }
00032 }
00033
00034 return (status);
00035 }
00036
00037 int
00038 remoteSubStructFilePut (rsComm_t *rsComm, subFile_t *subFile,
00039 bytesBuf_t *subFilePutOutBBuf, rodsServerHost_t *rodsServerHost)
00040 {
00041 int status;
00042
00043 if (rodsServerHost == NULL) {
00044 rodsLog (LOG_NOTICE,
00045 "remoteSubStructFilePut: Invalid rodsServerHost");
00046 return SYS_INVALID_SERVER_HOST;
00047 }
00048
00049 if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
00050 return status;
00051 }
00052
00053 status = rcSubStructFilePut (rodsServerHost->conn, subFile,
00054 subFilePutOutBBuf);
00055
00056 if (status < 0) {
00057 rodsLog (LOG_NOTICE,
00058 "remoteSubStructFilePut: rcSubStructFilePut failed for %s, status = %d",
00059 subFile->subFilePath, status);
00060 }
00061
00062 return status;
00063 }
00064
00065 int
00066 _rsSubStructFilePut (rsComm_t *rsComm, subFile_t *subFile,
00067 bytesBuf_t *subFilePutOutBBuf)
00068 {
00069 int status;
00070 int fd;
00071
00072 if (subFile->flags & FORCE_FLAG) {
00073 fd = subStructFileOpen (rsComm, subFile);
00074 } else {
00075 fd = subStructFileCreate (rsComm, subFile);
00076 }
00077
00078 if (fd < 0) {
00079 if (getErrno (fd) == EEXIST) {
00080 rodsLog (LOG_DEBUG1,
00081 "_rsSubStructFilePut: filePut for %s, status = %d",
00082 subFile->subFilePath, fd);
00083 } else {
00084 rodsLog (LOG_NOTICE,
00085 "_rsSubStructFilePut: subStructFileOpen error for %s, stat=%d",
00086 subFile->subFilePath, fd);
00087 }
00088 return (fd);
00089 }
00090
00091 status = subStructFileWrite (subFile->specColl->type, rsComm,
00092 fd, subFilePutOutBBuf->buf, subFilePutOutBBuf->len);
00093
00094 if (status != subFilePutOutBBuf->len) {
00095 if (status >= 0) {
00096 rodsLog (LOG_NOTICE,
00097 "_rsSubStructFilePut:Write error for %s,towrite %d,read %d",
00098 subFile->subFilePath, subFilePutOutBBuf->len, status);
00099 status = SYS_COPY_LEN_ERR;
00100 } else {
00101 rodsLog (LOG_NOTICE,
00102 "_rsSubStructFilePut: Write error for %s, status = %d",
00103 subFile->subFilePath, status);
00104 }
00105 }
00106
00107 subStructFileClose (subFile->specColl->type, rsComm, fd);
00108
00109 return (status);
00110 }
00111