00001
00002
00003
00004
00005
00006
00007
00008 #include "fileChmod.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 rsFileChmod (rsComm_t *rsComm, fileChmodInp_t *fileChmodInp)
00020 {
00021 rodsServerHost_t *rodsServerHost;
00022 int remoteFlag;
00023 int status;
00024
00025
00026 eirods::error ret = eirods::get_host_for_hier_string( fileChmodInp->rescHier, 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 = _rsFileChmod (rsComm, fileChmodInp);
00033 } else if (remoteFlag == REMOTE_HOST) {
00034 status = remoteFileChmod (rsComm, fileChmodInp, rodsServerHost);
00035 } else {
00036 if (remoteFlag < 0) {
00037 return (remoteFlag);
00038 } else {
00039 rodsLog (LOG_NOTICE,
00040 "rsFileChmod: 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 remoteFileChmod (rsComm_t *rsComm, fileChmodInp_t *fileChmodInp,
00053 rodsServerHost_t *rodsServerHost)
00054 {
00055 int status;
00056
00057 if (rodsServerHost == NULL) {
00058 rodsLog (LOG_NOTICE,
00059 "remoteFileChmod: 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 = rcFileChmod (rodsServerHost->conn, fileChmodInp);
00069
00070 if (status < 0) {
00071 rodsLog (LOG_NOTICE,
00072 "remoteFileOpen: rcFileChmod failed for %s",
00073 fileChmodInp->fileName);
00074 }
00075
00076 return status;
00077 }
00078
00079
00080
00081 int _rsFileChmod( rsComm_t *rsComm, fileChmodInp_t *fileChmodInp ) {
00082
00083 if(fileChmodInp->objPath[0] == '\0') {
00084 std::stringstream msg;
00085 msg << __FUNCTION__;
00086 msg << " - Empty logical path.";
00087 eirods::log(LOG_ERROR, msg.str());
00088 return -1;
00089 }
00090
00091
00092
00093
00094
00095 eirods::file_object file_obj( rsComm, fileChmodInp->objPath, fileChmodInp->fileName, fileChmodInp->rescHier, 0, fileChmodInp->mode, 0 );
00096 eirods::error chmod_err = fileChmod( rsComm, file_obj );
00097
00098
00099
00100 if( chmod_err.code() < 0 ) {
00101 std::stringstream msg;
00102 msg << "fileChmod failed for [";
00103 msg << fileChmodInp->fileName;
00104 msg << "]";
00105 eirods::error err = PASSMSG( msg.str(), chmod_err );
00106 eirods::log ( err );
00107 }
00108
00109 return chmod_err.code();
00110
00111 }