Skip to content

Commit

Permalink
Redirect TFile::Open() calls to XRootD protocol if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
amadio committed Nov 2, 2022
1 parent 04a77df commit 9d76be6
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion io/io/src/TFile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ The structure of a directory is shown in TDirectoryFile::TDirectoryFile
#include <errno.h>
#include <sys/stat.h>
#ifndef WIN32
# include <unistd.h>
#include <unistd.h>
#include <sys/xattr.h>
#else
# define ssize_t int
# include <io.h>
Expand Down Expand Up @@ -150,6 +151,11 @@ Bool_t TFile::fgOnlyStaged = kFALSE;
ROOT::Internal::RConcurrentHashColl TFile::fgTsSIHashes;
#endif

#ifdef R__MACOSX
/* On macOS getxattr takes two extra arguments that should be set to 0 */
#define getxattr(path, name, value, size) getxattr(path, name, value, size, 0u, 0)
#endif

const Int_t kBEGIN = 100;

ClassImp(TFile);
Expand Down Expand Up @@ -4030,6 +4036,18 @@ TFile *TFile::Open(const char *url, Option_t *options, const char *ftitle,
return f;
}

#ifdef R__UNIX
{ // If the file has an extended attribute with the XRootD URL, try it first
ssize_t len = getxattr(url, "eos.url.xroot", nullptr, 0);
if (len > 0) {
std::string xurl(len, 0);
if (getxattr(url, "eos.url.xroot", xurl.data(), len) == len)
if ((f = TFile::Open(xurl.c_str(), options, ftitle, compress, netopt)))
return f;
}
}
#endif

TString expandedUrl(url);
gSystem->ExpandPathName(expandedUrl);

Expand Down

0 comments on commit 9d76be6

Please sign in to comment.