#include "TString.h"
#include "TEnv.h"
#include "TSocket.h"
#include "TUrl.h"
#include "TVirtualMutex.h"
#include "TXNetFile.h"
#include "TXNetSystem.h"
#include "TROOT.h"
#include "XrdClient/XrdClientAdmin.hh"
#include "XrdClient/XrdClientConn.hh"
#include "XrdClient/XrdClientEnv.hh"
#include "XProtocol/XProtocol.hh"
ClassImp(TXNetSystem);
Bool_t TXNetSystem::fgInitDone = kFALSE;
Bool_t TXNetSystem::fgRootdBC = kTRUE;
TXNetSystem::TXNetSystem(Bool_t owner) : TNetSystem(owner)
{
SetTitle("(x)rootd system administration");
fIsXRootd = kFALSE;
fDir = "";
fDirp = 0;
fDirListValid = kFALSE;
fUrl = "";
}
TXNetSystem::TXNetSystem(const char *url, Bool_t owner) : TNetSystem(owner)
{
SetTitle("(x)rootd system administration");
fIsRootd = kFALSE;
fIsXRootd = kFALSE;
fDir = "";
fDirp = 0;
fDirListValid = kFALSE;
fUrl = url;
EnvPutInt(NAME_DEBUG, gEnv->GetValue("XNet.Debug", -1));
if (!fgInitDone)
InitXrdClient();
TNetSystem::InitRemoteEntity(url);
TXNetSystemConnectGuard cguard(this, url);
if (!cguard.IsValid()) {
Error("TXNetSystem","fatal error: connection creation failed.");
gSystem->Abort();
}
return;
}
XrdClientAdmin *TXNetSystem::Connect(const char *url)
{
TString dummy = url;
dummy += "/dummy";
XrdClientAdmin *cadm = new XrdClientAdmin(dummy);
if (!cadm) {
Error("Connect","fatal error: new object creation failed.");
return cadm;
}
if (cadm->Connect()) {
fIsXRootd = kTRUE;
} else {
if (fgRootdBC) {
Bool_t isRootd =
(cadm->GetClientConn()->GetServerType() == kSTRootd);
Int_t sd = cadm->GetClientConn()->GetOpenSockFD();
if (isRootd && sd > -1) {
TSocket *s = new TSocket(sd);
R__LOCKGUARD2(gROOTMutex);
gROOT->GetListOfSockets()->Remove(s);
s->SetOption(kNoBlock, 0);
Int_t rproto = TXNetFile::GetRootdProtocol(s);
if (rproto < 0) {
Error("TXNetSystem", "getting protocol of the rootd server");
delete cadm;
return 0;
}
s->SetRemoteProtocol(rproto);
TUrl uut((cadm->GetClientConn()
->GetCurrentUrl()).GetUrl().c_str());
TString uu;
TXNetFile::FormUrl(uut,uu);
if (gDebug > 2)
Info("Connect"," url: %s",uu.Data());
s->SetUrl(uu.Data());
s->SetService("rootd");
s->SetServType(TSocket::kROOTD);
if (rproto > 13) {
TNetSystem::Create(uu, s);
} else {
TNetSystem::Create(uu);
}
fIsRootd = kTRUE;
delete cadm;
} else {
Error("Connect", "some severe error occurred while opening"
" the connection at %s - exit", url);
delete cadm;
return cadm;
}
} else {
Error("Connect",
"while opening the connection at %s - exit", url);
delete cadm;
return cadm;
}
}
return cadm;
}
TXNetSystem::~TXNetSystem()
{
}
void TXNetSystem::InitXrdClient()
{
TXNetFile::SetEnv();
fgInitDone = kTRUE;
if (gEnv->GetValue("XNet.PrintTAG",0) == 1)
Info("TXNetFile","(C) 2005 SLAC TXNetSystem (eXtended TNetSystem) %s",
gROOT->GetVersion());
}
void* TXNetSystem::OpenDirectory(const char* dir)
{
if (fIsXRootd) {
TXNetSystemConnectGuard cg(this, dir);
if (cg.IsValid()) {
fUrl = dir;
fDir = TUrl(dir).GetFile();
fDirp = (void*)&fDir;
vecString dirs;
vecBool existDirs;
XrdOucString s(fDir.Data());
dirs.Push_back(s);
cg.ClientAdmin()->ExistDirs(dirs, existDirs);
if (existDirs.GetSize()>0 && existDirs[0])
return fDirp;
}
return 0;
}
if (gDebug > 1)
Info("OpenDirectory", "calling TNetSystem::OpenDirectory");
return TNetSystem::OpenDirectory(dir);
}
void TXNetSystem::FreeDirectory(void *dirp)
{
if (fIsXRootd) {
if (dirp != fDirp) {
Error("FreeDirectory","invalid directory pointer (%p, %p)", dirp, fDirp);
return;
}
fDir = "";
fDirp = 0;
fDirListValid = kFALSE;
return;
}
if (gDebug > 1)
Info("FreeDirectory","calling TNetSystem::FreeDirectory");
return TNetSystem::FreeDirectory(dirp);
}
Int_t TXNetSystem::MakeDirectory(const char* dir)
{
if (fIsXRootd) {
TXNetSystemConnectGuard cg(this, dir);
if (cg.IsValid()) {
Bool_t ok = cg.ClientAdmin()->Mkdir(TUrl(dir).GetFile(),7,5,5);
return (ok ? 0 : -1);
}
}
if (gDebug > 1)
Info("MakeDirectory","Calling TNetSystem::MakeDirectory");
return TNetSystem::MakeDirectory(dir);
}
const char* TXNetSystem::GetDirEntry(void *dirp)
{
if (fIsXRootd) {
if (dirp != fDirp) {
Error("GetDirEntry","invalid directory pointer");
return 0;
}
if (!fDirListValid) {
TXNetSystemConnectGuard cg(this, fUrl);
if (cg.IsValid()) {
Bool_t ok = cg.ClientAdmin()->DirList(fDir, fDirList);
if (ok)
fDirListValid = kTRUE;
else
return 0;
}
}
if (fDirList.GetSize() > 0)
return fDirList.Pop_back().c_str();
return 0;
}
if (gDebug > 1) Info("GetDirEntry","Calling TNetSystem::GetDirEntry");
return TNetSystem::GetDirEntry(dirp);
}
Int_t TXNetSystem::GetPathInfo(const char* path, FileStat_t &buf)
{
if (fIsXRootd) {
TXNetSystemConnectGuard cg(this, path);
if (cg.IsValid()) {
Long_t id;
Long64_t size;
Long_t flags;
Long_t modtime;
TString edir = TUrl(path).GetFile();
Bool_t ok = cg.ClientAdmin()->Stat(edir.Data(),id,size,flags,modtime);
if (flags & kXR_offline) {
buf.fMode = kS_IFOFF;
} else if (ok) {
buf.fDev = (id >> 24);
buf.fIno = (id && 0x00FFFFFF);
buf.fUid = -1;
buf.fGid = -1;
buf.fSize = size;
buf.fMtime = modtime;
if (flags == 0) buf.fMode = kS_IFREG;
if (flags & kXR_xset) buf.fMode = (kS_IFREG|kS_IXUSR|kS_IXGRP|kS_IXOTH);
if (flags & kXR_isDir) buf.fMode = kS_IFDIR;
if (flags & kXR_other) buf.fMode = kS_IFSOCK;
if (flags & kXR_readable) buf.fMode |= kS_IRUSR;
if (flags & kXR_writable) buf.fMode |= kS_IWUSR;
buf.fIsLink = 0;
return 0;
}
}
return 1;
}
if (gDebug > 1)
Info("GetPathInfo","Calling TNetSystem::GetPathInfo");
return TNetSystem::GetPathInfo(path,buf);
}
Bool_t TXNetSystem::ConsistentWith(const char *path, void *dirptr)
{
if (gDebug > 1)
Info("ConsistenWith",
"Calling TNetSystem::ConsistenWith for path: %s, dir: %p", path, dirptr);
return TNetSystem::ConsistentWith(path,dirptr);
}
Bool_t TXNetSystem::AccessPathName(const char *path, EAccessMode mode)
{
if (fIsXRootd) {
FileStat_t buf;
if (GetPathInfo(path, buf) == 0)
if (buf.fMode != kS_IFSOCK)
return kFALSE;
return kTRUE;
}
if (gDebug > 1)
Info("AccessPathName", "calling TNetSystem::AccessPathName");
return TNetSystem::AccessPathName(path,mode);
}
int TXNetSystem::Unlink(const char *path)
{
if (fIsXRootd) {
TXNetSystemConnectGuard cg(this, path);
if (cg.IsValid()) {
Long_t id;
Long64_t size;
Long_t flags;
Long_t modtime;
TString edir = TUrl(path).GetFile();
Bool_t ok = cg.ClientAdmin()->Stat(edir.Data(), id, size, flags, modtime);
if (ok && !(flags & kXR_offline)) {
if (flags & kXR_isDir)
ok = cg.ClientAdmin()->Rmdir(edir.Data());
else
ok = cg.ClientAdmin()->Rm(edir.Data());
return ((ok) ? 0 : -1);
}
}
}
if (gDebug > 1)
Info("AccessPathName", "calling TNetSystem::AccessPathName");
return -1;
}
TXNetSystemConnectGuard::TXNetSystemConnectGuard(TXNetSystem *xn, const char *url)
: fClientAdmin(0)
{
if (xn)
fClientAdmin = xn->Connect(url);
}
TXNetSystemConnectGuard::~TXNetSystemConnectGuard()
{
if (fClientAdmin)
delete fClientAdmin;
}
ROOT page - Class index - Class Hierarchy - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.