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( rsComm_t *rsComm, fileStageSyncInp_t *fileSyncToArchInp) {
00107
00108
00109
00110
00111
00112
00113 if(fileSyncToArchInp->objPath[0] == '\0') {
00114 std::stringstream msg;
00115 msg << __FUNCTION__;
00116 msg << " - Empty logical path.";
00117 eirods::log(LOG_ERROR, msg.str());
00118 return -1;
00119 }
00120
00121
00122
00123 eirods::file_object file_obj( rsComm,
00124 fileSyncToArchInp->objPath,
00125 fileSyncToArchInp->filename, "", 0,
00126 fileSyncToArchInp->mode,
00127 fileSyncToArchInp->flags );
00128 file_obj.resc_hier( fileSyncToArchInp->rescHier );
00129 eirods::error sync_err = fileSyncToArch( rsComm, file_obj, fileSyncToArchInp->cacheFilename );
00130
00131 if( !sync_err.ok() ) {
00132
00133 if (getErrno (sync_err.code()) == ENOENT) {
00134
00135
00136 mkDirForFilePath( rsComm,"/", fileSyncToArchInp->filename, getDefDirMode() );
00137 } else if (getErrno (sync_err.code()) == EEXIST) {
00138
00139
00140 eirods::collection_object coll_obj( fileSyncToArchInp->filename, fileSyncToArchInp->rescHier, 0, 0 );
00141 eirods::error rmdir_err = fileRmdir( rsComm, coll_obj );
00142 if( !rmdir_err.ok() ) {
00143 std::stringstream msg;
00144 msg << "fileRmdir failed for [";
00145 msg << fileSyncToArchInp->filename;
00146 msg << "]";
00147 eirods::error err = PASSMSG( msg.str(), sync_err );
00148 eirods::log ( err );
00149 }
00150 } else {
00151 std::stringstream msg;
00152 msg << "fileSyncToArch failed for [";
00153 msg << fileSyncToArchInp->filename;
00154 msg << "]";
00155 eirods::error err = PASSMSG( msg.str(), sync_err );
00156 eirods::log ( err );
00157 return sync_err.code();
00158 }
00159
00160
00161
00162 sync_err = fileSyncToArch( rsComm, file_obj, fileSyncToArchInp->cacheFilename );
00163 if( !sync_err.ok() ) {
00164 std::stringstream msg;
00165 msg << "fileSyncToArch failed for [";
00166 msg << fileSyncToArchInp->filename;
00167 msg << "]";
00168 msg << sync_err.code();
00169 eirods::error err = PASSMSG( msg.str(), sync_err );
00170 eirods::log ( err );
00171 }
00172
00173 }
00174
00175
00176
00177 rstrcpy(fileSyncToArchInp->filename, file_obj.physical_path().c_str(), MAX_NAME_LEN);
00178
00179 return (sync_err.code());
00180
00181 }
00182