00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "fileSyncToArch.h"
00011 #include "fileOpr.h"
00012 #include "miscServerFunct.h"
00013 #include "dataObjOpr.h"
00014 #include "physPath.h"
00015
00016
00017
00018 #include "eirods_log.h"
00019 #include "eirods_file_object.h"
00020 #include "eirods_collection_object.h"
00021 #include "eirods_stacktrace.h"
00022 #include "eirods_resource_backport.h"
00023
00024 int
00025 rsFileSyncToArch (rsComm_t *rsComm, fileStageSyncInp_t *fileSyncToArchInp)
00026 {
00027 rodsServerHost_t *rodsServerHost;
00028 int remoteFlag;
00029 int status;
00030
00031
00032 eirods::error ret = eirods::get_host_for_hier_string( fileSyncToArchInp->rescHier, remoteFlag, rodsServerHost );
00033 if( !ret.ok() ) {
00034 eirods::log( PASSMSG( "failed in call to eirods::get_host_for_hier_string", ret ) );
00035 return -1;
00036 }
00037
00038 if (remoteFlag < 0) {
00039 return (remoteFlag);
00040 } else {
00041 status = rsFileSyncToArchByHost (rsComm, fileSyncToArchInp, rodsServerHost);
00042 return (status);
00043 }
00044 }
00045
00046 int
00047 rsFileSyncToArchByHost (rsComm_t *rsComm, fileStageSyncInp_t *fileSyncToArchInp, rodsServerHost_t *rodsServerHost)
00048 {
00049 int status;
00050 int remoteFlag;
00051
00052 if (rodsServerHost == NULL) {
00053 rodsLog (LOG_NOTICE,
00054 "rsFileSyncToArchByHost: Input NULL rodsServerHost");
00055 return (SYS_INTERNAL_NULL_INPUT_ERR);
00056 }
00057
00058 remoteFlag = rodsServerHost->localFlag;
00059
00060 if (remoteFlag == LOCAL_HOST) {
00061 status = _rsFileSyncToArch (rsComm, fileSyncToArchInp);
00062 } else if (remoteFlag == REMOTE_HOST) {
00063 status = remoteFileSyncToArch (rsComm, fileSyncToArchInp, rodsServerHost);
00064 } else {
00065 if (remoteFlag < 0) {
00066 return (remoteFlag);
00067 } else {
00068 rodsLog (LOG_NOTICE,
00069 "rsFileSyncToArchByHost: resolveHost returned value %d",
00070 remoteFlag);
00071 return (SYS_UNRECOGNIZED_REMOTE_FLAG);
00072 }
00073 }
00074
00075 return (status);
00076 }
00077
00078 int
00079 remoteFileSyncToArch (rsComm_t *rsComm, fileStageSyncInp_t *fileSyncToArchInp, rodsServerHost_t *rodsServerHost)
00080 {
00081 int status;
00082
00083 if (rodsServerHost == NULL) {
00084 rodsLog (LOG_NOTICE,
00085 "remoteFileSyncToArch: Invalid rodsServerHost");
00086 return SYS_INVALID_SERVER_HOST;
00087 }
00088
00089 if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
00090 return status;
00091 }
00092
00093 status = rcFileSyncToArch (rodsServerHost->conn, fileSyncToArchInp);
00094
00095 if (status < 0) {
00096 rodsLog (LOG_NOTICE,
00097 "remoteFileSyncToArch: rcFileSyncToArch failed for %s",
00098 fileSyncToArchInp->filename);
00099 }
00100
00101 return status;
00102 }
00103
00104
00105
00106 int _rsFileSyncToArch(
00107 rsComm_t* _comm,
00108 fileStageSyncInp_t* _sync_inp ) {
00109
00110
00111
00112
00113
00114
00115 if(_sync_inp->objPath[0] == '\0') {
00116 std::stringstream msg;
00117 msg << "Empty logical path.";
00118 eirods::log(LOG_ERROR, msg.str());
00119 return -1;
00120 }
00121
00122
00123
00124 eirods::file_object_ptr file_obj(
00125 new eirods::file_object(
00126 _comm,
00127 _sync_inp->objPath,
00128 _sync_inp->filename, "", 0,
00129 _sync_inp->mode,
00130 _sync_inp->flags ) );
00131 file_obj->resc_hier( _sync_inp->rescHier );
00132 eirods::error sync_err = fileSyncToArch( _comm, file_obj, _sync_inp->cacheFilename );
00133
00134 if( !sync_err.ok() ) {
00135
00136 if (getErrno (sync_err.code()) == ENOENT) {
00137
00138
00139 mkDirForFilePath( _comm,"/", _sync_inp->filename, getDefDirMode() );
00140 } else if (getErrno (sync_err.code()) == EEXIST) {
00141
00142
00143 eirods::collection_object_ptr coll_obj(
00144 new eirods::collection_object(
00145 _sync_inp->filename,
00146 _sync_inp->rescHier,
00147 0, 0 ) );
00148 eirods::error rmdir_err = fileRmdir( _comm, coll_obj );
00149 if( !rmdir_err.ok() ) {
00150 std::stringstream msg;
00151 msg << "fileRmdir failed for [";
00152 msg << _sync_inp->filename;
00153 msg << "]";
00154 eirods::error err = PASSMSG( msg.str(), sync_err );
00155 eirods::log ( err );
00156 }
00157 } else {
00158 std::stringstream msg;
00159 msg << "fileSyncToArch failed for [";
00160 msg << _sync_inp->filename;
00161 msg << "]";
00162 eirods::error err = PASSMSG( msg.str(), sync_err );
00163 eirods::log ( err );
00164 return sync_err.code();
00165 }
00166
00167
00168
00169 sync_err = fileSyncToArch( _comm, file_obj, _sync_inp->cacheFilename );
00170 if( !sync_err.ok() ) {
00171 std::stringstream msg;
00172 msg << "fileSyncToArch failed for [";
00173 msg << _sync_inp->filename;
00174 msg << "]";
00175 msg << sync_err.code();
00176 eirods::error err = PASSMSG( msg.str(), sync_err );
00177 eirods::log ( err );
00178 }
00179
00180 }
00181
00182
00183
00184 rstrcpy(_sync_inp->filename, file_obj->physical_path().c_str(), MAX_NAME_LEN);
00185
00186 return (sync_err.code());
00187
00188 }
00189