00001
00002
00003
00004
00005
00006
00007
00008 #include "fileFstat.h"
00009 #include "miscServerFunct.h"
00010 #include "rsGlobalExtern.h"
00011
00012
00013
00014 #include "eirods_log.h"
00015 #include "eirods_file_object.h"
00016 #include "eirods_stacktrace.h"
00017
00018 int
00019 rsFileFstat (rsComm_t *rsComm, fileFstatInp_t *fileFstatInp,
00020 rodsStat_t **fileFstatOut)
00021 {
00022 rodsServerHost_t *rodsServerHost;
00023 int remoteFlag;
00024 int status;
00025
00026 *fileFstatOut = NULL;
00027
00028 remoteFlag = getServerHostByFileInx (fileFstatInp->fileInx,
00029 &rodsServerHost);
00030
00031 if (remoteFlag == LOCAL_HOST) {
00032 status = _rsFileFstat (rsComm, fileFstatInp, fileFstatOut);
00033 } else if (remoteFlag == REMOTE_HOST) {
00034 status = remoteFileFstat (rsComm, fileFstatInp, fileFstatOut,
00035 rodsServerHost);
00036 } else {
00037 if (remoteFlag < 0) {
00038 return (remoteFlag);
00039 } else {
00040 rodsLog (LOG_NOTICE,
00041 "rsFileFstat: resolveHost returned unrecognized value %d",
00042 remoteFlag);
00043 return (SYS_UNRECOGNIZED_REMOTE_FLAG);
00044 }
00045 }
00046
00047
00048
00049 return (status);
00050 }
00051
00052 int
00053 remoteFileFstat (rsComm_t *rsComm, fileFstatInp_t *fileFstatInp,
00054 rodsStat_t **fileFstatOut, rodsServerHost_t *rodsServerHost)
00055 {
00056 int status;
00057
00058 if (rodsServerHost == NULL) {
00059 rodsLog (LOG_NOTICE,
00060 "remoteFileFstat: Invalid rodsServerHost");
00061 return SYS_INVALID_SERVER_HOST;
00062 }
00063
00064 if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
00065 return status;
00066 }
00067
00068
00069 fileFstatInp->fileInx = convL3descInx (fileFstatInp->fileInx);
00070 status = rcFileFstat (rodsServerHost->conn, fileFstatInp, fileFstatOut);
00071
00072 if (status < 0) {
00073 rodsLog (LOG_NOTICE,
00074 "remoteFileFstat: rcFileFstat failed for %s",
00075 FileDesc[fileFstatInp->fileInx].fileName);
00076 }
00077
00078 return status;
00079 }
00080
00081
00082
00083 int _rsFileFstat (rsComm_t *rsComm, fileFstatInp_t *fileFstatInp, rodsStat_t **fileFstatOut ) {
00084
00085 if(FileDesc[fileFstatInp->fileInx].objPath == NULL ||
00086 FileDesc[fileFstatInp->fileInx].objPath[0] == '\0') {
00087 std::stringstream msg;
00088 msg << __FUNCTION__;
00089 msg << " - Empty logical path.";
00090 eirods::log(LOG_ERROR, msg.str());
00091 return -1;
00092 }
00093
00094
00095
00096 struct stat myFileStat;
00097 eirods::file_object file_obj( rsComm,
00098 FileDesc[fileFstatInp->fileInx].objPath,
00099 FileDesc[fileFstatInp->fileInx].fileName,
00100 FileDesc[fileFstatInp->fileInx].rescHier,
00101 FileDesc[fileFstatInp->fileInx].fd,
00102 0, 0 );
00103 eirods::error stat_err = fileFstat( rsComm, file_obj, &myFileStat );
00104
00105
00106
00107 if( !stat_err.ok() ) {
00108 std::stringstream msg;
00109 msg << "_rsFileFstat: fileFstat for ";
00110 msg << FileDesc[fileFstatInp->fileInx].fileName;
00111 msg << ", status = ";
00112 msg << stat_err.code();
00113 eirods::error ret_err = PASS( false, stat_err.code(), msg.str(), stat_err );
00114 eirods::log( ret_err );
00115
00116 return ret_err.code();
00117 }
00118
00119
00120
00121 *fileFstatOut = (rodsStat_t*)malloc (sizeof (rodsStat_t));
00122 int status = statToRodsStat(*fileFstatOut, &myFileStat);
00123
00124
00125
00126 if (status < 0) {
00127 free (*fileFstatOut);
00128 *fileFstatOut = NULL;
00129 }
00130
00131 return status;
00132
00133 }
00134
00135
00136
00137
00138