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