diff --git a/core/base/inc/TSystem.h b/core/base/inc/TSystem.h index 4f70b69891e560f449625235c5814dbb58aa796d..ac1288cc19e9cc396e70550f55100213257a142c 100644 --- a/core/base/inc/TSystem.h +++ b/core/base/inc/TSystem.h @@ -403,6 +403,7 @@ public: virtual Bool_t ExpandPathName(TString &path); virtual char *ExpandPathName(const char *path); virtual Bool_t AccessPathName(const char *path, EAccessMode mode = kFileExists); + virtual Bool_t IsPathLocal(const char *path); virtual int CopyFile(const char *from, const char *to, Bool_t overwrite = kFALSE); virtual int Rename(const char *from, const char *to); virtual int Link(const char *from, const char *to); diff --git a/core/base/src/TSystem.cxx b/core/base/src/TSystem.cxx index 51691bc2a8ecc7c77ac51995a67fc8c00dc40a69..f7678fc0a92c166d1b005a8eccaadd9882c5b008 100644 --- a/core/base/src/TSystem.cxx +++ b/core/base/src/TSystem.cxx @@ -1116,6 +1116,40 @@ Bool_t TSystem::AccessPathName(const char *, EAccessMode) return kFALSE; } +//______________________________________________________________________________ +Bool_t TSystem::IsPathLocal(const char *path) +{ + // Returns TRUE if the url in 'path' points to the local file system. + // This is used to avoid going through the NIC card for local operations. + + Bool_t localPath = kTRUE; + + TUrl url(path); + if (strlen(url.GetHost()) > 0) { + // Check locality + localPath = kFALSE; + TInetAddress a(gSystem->GetHostByName(url.GetHost())); + TInetAddress b(gSystem->GetHostByName(gSystem->HostName())); + if (!strcmp(a.GetHostName(), b.GetHostName()) || + !strcmp(a.GetHostAddress(), b.GetHostAddress())) { + // Host OK + localPath = kTRUE; + // Check the user if specified + if (strlen(url.GetUser()) > 0) { + UserGroup_t *u = gSystem->GetUserInfo(); + if (u) { + if (strcmp(u->fUser, url.GetUser())) + // Requested a different user + localPath = kFALSE; + delete u; + } + } + } + } + // Done + return localPath; +} + //______________________________________________________________________________ int TSystem::CopyFile(const char *, const char *, Bool_t) {