00001
00002
00003 #include "structFileExtract.h"
00004 #include "miscServerFunct.h"
00005 #include "syncMountedColl.h"
00006
00007 #include "dataObjOpr.h"
00008 #include "rsGlobalExtern.h"
00009 #include "objMetaOpr.h"
00010 #include "resource.h"
00011 #include "physPath.h"
00012
00013
00014
00015 #include "eirods_structured_object.h"
00016 #include "eirods_resource_backport.h"
00017 #include "eirods_resource_redirect.h"
00018
00019
00020 int
00021 rsStructFileExtract (rsComm_t *rsComm, structFileOprInp_t *structFileOprInp)
00022 {
00023
00024
00025 int status;
00026
00027
00028 dataObjInp_t dataObjInp;
00029 bzero( &dataObjInp, sizeof( dataObjInp ) );
00030 rstrcpy( dataObjInp.objPath, structFileOprInp->specColl->objPath, MAX_NAME_LEN );
00031
00032
00033
00034
00035
00036 std::string hier;
00037 int local = LOCAL_HOST;
00038 rodsServerHost_t* host = 0;
00039 if( getValByKey( &structFileOprInp->condInput, RESC_HIER_STR_KW ) == NULL ) {
00040 eirods::error ret = eirods::resource_redirect( eirods::EIRODS_OPEN_OPERATION, rsComm,
00041 &dataObjInp, hier, host, local );
00042 if( !ret.ok() ) {
00043 std::stringstream msg;
00044 msg << "failed in eirods::resource_redirect for [";
00045 msg << dataObjInp.objPath << "]";
00046 eirods::log( PASSMSG( msg.str(), ret ) );
00047 return ret.code();
00048 }
00049
00050
00051
00052
00053 addKeyVal( &structFileOprInp->condInput, RESC_HIER_STR_KW, hier.c_str() );
00054
00055 }
00056
00057
00058 if ( local == LOCAL_HOST) {
00059 status = _rsStructFileExtract (rsComm, structFileOprInp);
00060 } else if (local == REMOTE_HOST) {
00061
00062 status = rcStructFileExtract( host->conn, structFileOprInp );
00063 } else {
00064 if (local < 0) {
00065 return (local);
00066 } else {
00067 rodsLog (LOG_NOTICE,
00068 "rsStructFileExtract: resolveHost returned unrecognized value %d",
00069 local);
00070 return (SYS_UNRECOGNIZED_REMOTE_FLAG);
00071 }
00072 }
00073
00074 return (status);
00075 }
00076
00077 int
00078 remoteStructFileExtract (rsComm_t *rsComm,
00079 structFileOprInp_t *structFileOprInp, rodsServerHost_t *rodsServerHost)
00080 {
00081 int status;
00082
00083 if (rodsServerHost == NULL) {
00084 rodsLog (LOG_NOTICE,
00085 "remoteStructFileExtract: Invalid rodsServerHost");
00086 return SYS_INVALID_SERVER_HOST;
00087 }
00088
00089 if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
00090 return status;
00091 }
00092
00093 status = rcStructFileExtract (rodsServerHost->conn, structFileOprInp);
00094
00095 if (status < 0) {
00096 rodsLog (LOG_NOTICE,
00097 "remoteStructFileExtract: rcStructFileExtract failed for %s, status = %d",
00098 structFileOprInp->specColl->collection, status);
00099 }
00100
00101 return status;
00102 }
00103
00104
00105
00106 int _rsStructFileExtract( rsComm_t* _comm,
00107 structFileOprInp_t* _struct_inp ) {
00108
00109
00110 if( _comm == NULL ||
00111 _struct_inp == NULL ||
00112 _struct_inp->specColl == NULL) {
00113 rodsLog( LOG_ERROR, "_rsStructFileExtract: NULL input" );
00114 return SYS_INTERNAL_NULL_INPUT_ERR;
00115 }
00116
00117
00118
00119 int status = procCacheDir( _comm,
00120 _struct_inp->specColl->cacheDir,
00121 _struct_inp->specColl->resource,
00122 _struct_inp->oprType );
00123 if( status < 0 ) {
00124 rodsLog( LOG_ERROR, "_rsStructFileExtract - failed in call to procCacheDir status = %d", status );
00125 return status;
00126 }
00127
00128
00129
00130
00131 eirods::structured_object struct_obj;
00132 struct_obj.spec_coll( _struct_inp->specColl );
00133 struct_obj.addr( _struct_inp->addr );
00134 struct_obj.flags( _struct_inp->flags );
00135 struct_obj.comm( _comm );
00136 struct_obj.opr_type( _struct_inp->oprType );
00137
00138
00139
00140 char* data_type = getValByKey( &_struct_inp->condInput, DATA_TYPE_KW );
00141 if( data_type ) {
00142 struct_obj.data_type( data_type );
00143 }
00144
00145
00146
00147 eirods::resource_ptr resc;
00148 eirods::error ret_err = struct_obj.resolve( resc_mgr, resc );
00149 if( !ret_err.ok() ) {
00150 eirods::error err = PASSMSG( "failed to resolve resource", ret_err );
00151 eirods::log( err );
00152 return ret_err.code();
00153 }
00154
00155
00156
00157 ret_err = resc->call( _comm, "extract", struct_obj );
00158
00159
00160
00161 if( !ret_err.ok() ) {
00162 eirods::error err = PASSMSG( "failed to call 'extract'", ret_err );
00163 eirods::log( err );
00164 return ret_err.code();
00165 } else {
00166 return ret_err.code();
00167 }
00168
00169 }
00170
00171 int
00172 procCacheDir (rsComm_t *rsComm, char *cacheDir, char *resource, int oprType) {
00173 if( ( oprType & PRESERVE_DIR_CONT) == 0 ) {
00174 int status = chkEmptyDir( -1, rsComm, cacheDir );
00175 if( status == SYS_DIR_IN_VAULT_NOT_EMPTY ) {
00176 rodsLog( LOG_ERROR,"procCacheDir: chkEmptyDir error for %s in resc %s, status = %d",
00177 cacheDir, resource, status );
00178 return (status);
00179 }
00180
00181 }
00182
00183 mkFileDirR( rsComm, "/", cacheDir, getDefDirMode() );
00184
00185 return 0;
00186 }
00187