00001
00002
00003 #include "subStructFileTruncate.h"
00004 #include "miscServerFunct.h"
00005 #include "dataObjOpr.h"
00006
00007
00008
00009 #include "eirods_structured_object.h"
00010
00011
00012 int
00013 rsSubStructFileTruncate (rsComm_t *rsComm, subFile_t *subFile)
00014 {
00015 rodsServerHost_t *rodsServerHost;
00016 int remoteFlag;
00017 int status;
00018
00019 remoteFlag = resolveHost (&subFile->addr, &rodsServerHost);
00020
00021 if (remoteFlag == LOCAL_HOST) {
00022 status = _rsSubStructFileTruncate (rsComm, subFile);
00023 } else if (remoteFlag == REMOTE_HOST) {
00024 status = remoteSubStructFileTruncate (rsComm, subFile, rodsServerHost);
00025 } else {
00026 if (remoteFlag < 0) {
00027 return (remoteFlag);
00028 } else {
00029 rodsLog (LOG_NOTICE,
00030 "rsSubStructFileTruncate: resolveHost returned unrecognized value %d",
00031 remoteFlag);
00032 return (SYS_UNRECOGNIZED_REMOTE_FLAG);
00033 }
00034 }
00035
00036 return (status);
00037 }
00038
00039 int
00040 remoteSubStructFileTruncate (rsComm_t *rsComm, subFile_t *subFile,
00041 rodsServerHost_t *rodsServerHost)
00042 {
00043 int status;
00044
00045 if (rodsServerHost == NULL) {
00046 rodsLog (LOG_NOTICE,
00047 "remoteSubStructFileTruncate: Invalid rodsServerHost");
00048 return SYS_INVALID_SERVER_HOST;
00049 }
00050
00051 if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
00052 return status;
00053 }
00054
00055 status = rcSubStructFileTruncate (rodsServerHost->conn, subFile);
00056
00057 if (status < 0) {
00058 rodsLog (LOG_NOTICE,
00059 "remoteSubStructFileTruncate: rcSubStructFileTruncate failed for %s, status = %d",
00060 subFile->subFilePath, status);
00061 }
00062
00063 return status;
00064 }
00065
00066 int _rsSubStructFileTruncate( rsComm_t* _comm,
00067 subFile_t * _sub_file ) {
00068
00069
00070 eirods::structured_object struct_obj( *_sub_file );
00071 struct_obj.comm( _comm );
00072
00073 struct_obj.resc_hier( eirods::EIRODS_LOCAL_USE_ONLY_RESOURCE );
00074
00075
00076
00077 eirods::error trunc_err = fileTruncate( _comm, struct_obj );
00078 if( !trunc_err.ok() ) {
00079 std::stringstream msg;
00080 msg << "_rsSubStructFileTruncate - failed on call to fileTruncate for [";
00081 msg << struct_obj.physical_path();
00082 msg << "]";
00083 eirods::log( PASS( false, -1, msg.str(), trunc_err ) );
00084 return trunc_err.code();
00085
00086 } else {
00087 return trunc_err.code();
00088
00089 }
00090
00091 }
00092