00001
00002
00003
00004
00005
00006
00007
00008 #include "fileTruncate.h"
00009 #include "miscServerFunct.h"
00010
00011
00012
00013 #include "eirods_log.h"
00014 #include "eirods_file_object.h"
00015 #include "eirods_stacktrace.h"
00016 #include "eirods_resource_backport.h"
00017
00018 int
00019 rsFileTruncate (rsComm_t *rsComm, fileOpenInp_t *fileTruncateInp)
00020 {
00021 rodsServerHost_t *rodsServerHost;
00022 int remoteFlag;
00023 int status;
00024
00025
00026 eirods::error ret = eirods::get_host_for_hier_string( fileTruncateInp->resc_hier_, remoteFlag, rodsServerHost );
00027 if( !ret.ok() ) {
00028 eirods::log( PASSMSG( " failed in call to eirods::get_host_for_hier_string", ret ) );
00029 return -1;
00030 }
00031 if (remoteFlag == LOCAL_HOST) {
00032 status = _rsFileTruncate (rsComm, fileTruncateInp);
00033 } else if (remoteFlag == REMOTE_HOST) {
00034 status = remoteFileTruncate (rsComm, fileTruncateInp, rodsServerHost);
00035 } else {
00036 if (remoteFlag < 0) {
00037 return (remoteFlag);
00038 } else {
00039 rodsLog (LOG_NOTICE,
00040 "rsFileTruncate: resolveHost returned unrecognized value %d",
00041 remoteFlag);
00042 return (SYS_UNRECOGNIZED_REMOTE_FLAG);
00043 }
00044 }
00045
00046
00047
00048 return (status);
00049 }
00050
00051 int
00052 remoteFileTruncate (rsComm_t *rsComm, fileOpenInp_t *fileTruncateInp,
00053 rodsServerHost_t *rodsServerHost)
00054 {
00055 int status;
00056
00057 if (rodsServerHost == NULL) {
00058 rodsLog (LOG_NOTICE,
00059 "remoteFileTruncate: Invalid rodsServerHost");
00060 return SYS_INVALID_SERVER_HOST;
00061 }
00062
00063 if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
00064 return status;
00065 }
00066
00067
00068 status = rcFileTruncate (rodsServerHost->conn, fileTruncateInp);
00069
00070 if (status < 0) {
00071 rodsLog (LOG_NOTICE,
00072 "remoteFileTruncate: rcFileTruncate failed for %s, status = %d",
00073 fileTruncateInp->fileName, status);
00074 }
00075
00076 return status;
00077 }
00078
00079
00080
00081 int _rsFileTruncate(
00082 rsComm_t* _comm,
00083 fileOpenInp_t* _trunc_inp ) {
00084
00085
00086 if(_trunc_inp->objPath[0] == '\0') {
00087 std::stringstream msg;
00088 msg << __FUNCTION__;
00089 msg << " - Empty logical path.";
00090 eirods::log(LOG_ERROR, msg.str());
00091 return -1;
00092 }
00093
00094
00095
00096 eirods::file_object_ptr file_obj(
00097 new eirods::file_object(
00098 _comm,
00099 _trunc_inp->objPath,
00100 _trunc_inp->fileName,
00101 _trunc_inp->resc_hier_,
00102 0, 0, 0 ) );
00103 file_obj->size( _trunc_inp->dataSize );
00104 eirods::error trunc_err = fileTruncate( _comm, file_obj );
00105
00106
00107
00108 if ( !trunc_err.ok() ) {
00109 std::stringstream msg;
00110 msg << "fileTruncate for [";
00111 msg << _trunc_inp->fileName;
00112 msg << "]";
00113 msg << trunc_err.code();
00114 eirods::error err = PASSMSG( msg.str(), trunc_err );
00115 eirods::log ( err );
00116 }
00117
00118 return trunc_err.code();
00119
00120 }
00121
00122
00123
00124
00125
00126