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(
00112 rsComm_t* _comm,
00113 fileStatInp_t* _stat_inp,
00114 rodsStat_t** _stat_out ) {
00115 struct stat myFileStat;
00116
00117 if(_stat_inp->objPath[0] == '\0') {
00118 std::stringstream msg;
00119 msg << "Empty logical path.";
00120 eirods::log(LOG_ERROR, msg.str());
00121 return -1;
00122 }
00123
00124
00125
00126 eirods::file_object_ptr file_obj(
00127 new eirods::file_object(
00128 _comm,
00129 _stat_inp->objPath,
00130 _stat_inp->fileName,
00131 _stat_inp->rescHier,
00132 0, 0, 0 ) );
00133 eirods::error stat_err = fileStat( _comm, file_obj, &myFileStat );
00134
00135
00136
00137 if( !stat_err.ok() ) {
00138
00139 return stat_err.code();
00140 }
00141
00142
00143
00144 *_stat_out = (rodsStat_t*)malloc (sizeof (rodsStat_t));
00145 int status = statToRodsStat (*_stat_out, &myFileStat);
00146
00147
00148
00149 if (status < 0) {
00150 free (*_stat_out);
00151 *_stat_out = NULL;
00152 }
00153
00154 return status;
00155
00156 }
00157
00158
00159
00160