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_ptr struct_obj(
00132 new eirods::structured_object(
00133 ) );
00134 struct_obj->spec_coll( _struct_inp->specColl );
00135 struct_obj->addr( _struct_inp->addr );
00136 struct_obj->flags( _struct_inp->flags );
00137 struct_obj->comm( _comm );
00138 struct_obj->opr_type( _struct_inp->oprType );
00139
00140
00141
00142 char* data_type = getValByKey( &_struct_inp->condInput, DATA_TYPE_KW );
00143 if( data_type ) {
00144 struct_obj->data_type( data_type );
00145 }
00146
00147
00148
00149 eirods::plugin_ptr ptr;
00150 eirods::error ret_err = struct_obj->resolve( eirods::RESOURCE_INTERFACE, ptr );
00151 if( !ret_err.ok() ) {
00152 eirods::error err = PASSMSG( "failed to resolve resource", ret_err );
00153 eirods::log( err );
00154 return ret_err.code();
00155 }
00156
00157 eirods::resource_ptr resc = boost::dynamic_pointer_cast< eirods::resource >( ptr );
00158
00159
00160
00161 ret_err = resc->call( _comm, "extract", struct_obj );
00162
00163
00164
00165 if( !ret_err.ok() ) {
00166 eirods::error err = PASSMSG( "failed to call 'extract'", ret_err );
00167 eirods::log( err );
00168 return ret_err.code();
00169 } else {
00170 return ret_err.code();
00171 }
00172
00173 }
00174
00175 int
00176 procCacheDir (rsComm_t *rsComm, char *cacheDir, char *resource, int oprType) {
00177 if( ( oprType & PRESERVE_DIR_CONT) == 0 ) {
00178 int status = chkEmptyDir( -1, rsComm, cacheDir );
00179 if( status == SYS_DIR_IN_VAULT_NOT_EMPTY ) {
00180 rodsLog( LOG_ERROR,"procCacheDir: chkEmptyDir error for %s in resc %s, status = %d",
00181 cacheDir, resource, status );
00182 return (status);
00183 }
00184
00185 }
00186
00187 mkFileDirR( rsComm, "/", cacheDir, getDefDirMode() );
00188
00189 return 0;
00190 }
00191