00001
00002
00003
00004
00005
00006
00007
00008 #include "fileOpendir.h"
00009 #include "miscServerFunct.h"
00010 #include "rsGlobalExtern.h"
00011
00012
00013
00014 #include "eirods_log.h"
00015 #include "eirods_collection_object.h"
00016 #include "eirods_resource_backport.h"
00017 #include "eirods_stacktrace.h"
00018
00019 int
00020 rsFileOpendir (rsComm_t *rsComm, fileOpendirInp_t *fileOpendirInp)
00021 {
00022 rodsServerHost_t *rodsServerHost;
00023 int remoteFlag;
00024 int fileInx;
00025 int status;
00026 void *dirPtr = NULL;
00027
00028
00029 eirods::error ret = eirods::get_host_for_hier_string( fileOpendirInp->resc_hier_, remoteFlag, rodsServerHost );
00030 if( !ret.ok() ) {
00031 eirods::log( PASSMSG( "failed in call to eirods::get_host_for_hier_string", ret ) );
00032 return -1;
00033 }
00034
00035 if (remoteFlag == LOCAL_HOST) {
00036 status = _rsFileOpendir (rsComm, fileOpendirInp, &dirPtr);
00037 } else if (remoteFlag == REMOTE_HOST) {
00038 status = remoteFileOpendir (rsComm, fileOpendirInp, rodsServerHost);
00039 } else {
00040 if (remoteFlag < 0) {
00041 return (remoteFlag);
00042 } else {
00043 rodsLog (LOG_NOTICE,
00044 "rsFileOpendir: resolveHost returned unrecognized value %d",
00045 remoteFlag);
00046 return (SYS_UNRECOGNIZED_REMOTE_FLAG);
00047 }
00048 }
00049
00050 if (status < 0) {
00051 return (status);
00052 }
00053
00054 fileInx = allocAndFillFileDesc( rodsServerHost, fileOpendirInp->objPath, fileOpendirInp->dirName, fileOpendirInp->resc_hier_,
00055 fileOpendirInp->fileType, status, 0);
00056 FileDesc[fileInx].driverDep = dirPtr;
00057
00058 return (fileInx);
00059 }
00060
00061 int
00062 remoteFileOpendir (rsComm_t *rsComm, fileOpendirInp_t *fileOpendirInp,
00063 rodsServerHost_t *rodsServerHost)
00064 {
00065 int fileInx;
00066 int status;
00067
00068 if (rodsServerHost == NULL) {
00069 rodsLog (LOG_NOTICE,
00070 "remoteFileOpendir: Invalid rodsServerHost");
00071 return SYS_INVALID_SERVER_HOST;
00072 }
00073
00074 if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
00075 return status;
00076 }
00077
00078 fileInx = rcFileOpendir (rodsServerHost->conn, fileOpendirInp);
00079
00080 if (fileInx < 0) {
00081 rodsLog (LOG_NOTICE,
00082 "remoteFileOpendir: rcFileOpendir failed for %s",
00083 fileOpendirInp->dirName);
00084 }
00085
00086 return fileInx;
00087 }
00088
00089
00090
00091 int _rsFileOpendir( rsComm_t *rsComm, fileOpendirInp_t *fileOpendirInp, void **dirPtr ) {
00092
00093
00094
00095
00096
00097
00098 eirods::collection_object coll_obj( fileOpendirInp->dirName, fileOpendirInp->resc_hier_, 0, 0 );
00099 eirods::error opendir_err = fileOpendir( rsComm, coll_obj );
00100
00101
00102
00103 if( !opendir_err.ok() ) {
00104 std::stringstream msg;
00105 msg << "fileOpendir failed for [";
00106 msg <<fileOpendirInp->dirName;
00107 msg << "]";
00108 eirods::error err = PASSMSG( msg.str(), opendir_err );
00109 eirods::log ( err );
00110 }
00111
00112 (*dirPtr) = coll_obj.directory_pointer();
00113
00114 return (opendir_err.code());
00115
00116 }
00117