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